| 
									
										
										
										
											2022-09-29 12:02:41 +02:00
										 |  |  | /* | 
					
						
							| 
									
										
										
										
											2023-01-18 14:45:14 +01:00
										 |  |  | 	GoToSocial | 
					
						
							| 
									
										
										
										
											2023-03-12 18:49:06 +01:00
										 |  |  | 	Copyright (C) GoToSocial Authors admin@gotosocial.org | 
					
						
							|  |  |  | 	SPDX-License-Identifier: AGPL-3.0-or-later | 
					
						
							| 
									
										
										
										
											2022-09-29 12:02:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-18 14:45:14 +01:00
										 |  |  | 	This program is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  | 	it under the terms of the GNU Affero General Public License as published by | 
					
						
							|  |  |  | 	the Free Software Foundation, either version 3 of the License, or | 
					
						
							|  |  |  | 	(at your option) any later version. | 
					
						
							| 
									
										
										
										
											2022-09-29 12:02:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-18 14:45:14 +01:00
										 |  |  | 	This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  | 	but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  | 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  | 	GNU Affero General Public License for more details. | 
					
						
							| 
									
										
										
										
											2022-09-29 12:02:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-18 14:45:14 +01:00
										 |  |  | 	You should have received a copy of the GNU Affero General Public License | 
					
						
							|  |  |  | 	along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
					
						
							| 
									
										
										
										
											2022-09-29 12:02:41 +02:00
										 |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-05 16:06:19 +02:00
										 |  |  | import { combineReducers } from "redux"; | 
					
						
							|  |  |  | import { configureStore } from "@reduxjs/toolkit"; | 
					
						
							|  |  |  | import { | 
					
						
							| 
									
										
										
										
											2022-11-08 17:51:44 +01:00
										 |  |  | 	persistStore, | 
					
						
							|  |  |  | 	persistReducer, | 
					
						
							|  |  |  | 	FLUSH, | 
					
						
							|  |  |  | 	REHYDRATE, | 
					
						
							|  |  |  | 	PAUSE, | 
					
						
							|  |  |  | 	PERSIST, | 
					
						
							|  |  |  | 	PURGE, | 
					
						
							|  |  |  | 	REGISTER, | 
					
						
							| 
									
										
										
										
											2023-10-05 16:06:19 +02:00
										 |  |  | } from "redux-persist"; | 
					
						
							| 
									
										
										
										
											2022-09-29 12:02:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-17 15:06:17 +01:00
										 |  |  | import { loginSlice } from "./login"; | 
					
						
							| 
									
										
										
										
											2023-10-05 16:06:19 +02:00
										 |  |  | import { gtsApi } from "../lib/query/gts-api"; | 
					
						
							| 
									
										
										
										
											2022-09-29 12:02:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | const combinedReducers = combineReducers({ | 
					
						
							| 
									
										
										
										
											2023-10-05 16:06:19 +02:00
										 |  |  | 	[gtsApi.reducerPath]: gtsApi.reducer, | 
					
						
							| 
									
										
										
										
											2025-03-17 15:06:17 +01:00
										 |  |  | 	login: loginSlice.reducer, | 
					
						
							| 
									
										
										
										
											2022-09-29 12:02:41 +02:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-08 17:51:44 +01:00
										 |  |  | const persistedReducer = persistReducer({ | 
					
						
							|  |  |  | 	key: "gotosocial-settings", | 
					
						
							|  |  |  | 	storage: require("redux-persist/lib/storage").default, | 
					
						
							| 
									
										
										
										
											2023-01-18 14:45:14 +01:00
										 |  |  | 	stateReconciler: require("redux-persist/lib/stateReconciler/autoMergeLevel1").default, | 
					
						
							| 
									
										
										
										
											2025-03-17 15:06:17 +01:00
										 |  |  | 	whitelist: ["login"], | 
					
						
							| 
									
										
										
										
											2023-10-05 16:06:19 +02:00
										 |  |  | 	migrate: async (state) => { | 
					
						
							|  |  |  | 		if (state == undefined) { | 
					
						
							| 
									
										
										
										
											2023-01-18 16:41:00 +01:00
										 |  |  | 			return state; | 
					
						
							| 
									
										
										
										
											2023-10-05 16:06:19 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		// This is a cheeky workaround for
 | 
					
						
							|  |  |  | 		// redux-persist being a stickler.
 | 
					
						
							|  |  |  | 		let anyState = state as any;  | 
					
						
							| 
									
										
										
										
											2025-03-17 15:06:17 +01:00
										 |  |  | 		if (anyState?.login != undefined) { | 
					
						
							|  |  |  | 			anyState.login.expectingRedirect = false; | 
					
						
							| 
									
										
										
										
											2023-10-05 16:06:19 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return anyState; | 
					
						
							| 
									
										
										
										
											2023-01-18 16:41:00 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2022-11-08 17:51:44 +01:00
										 |  |  | }, combinedReducers); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-05 16:06:19 +02:00
										 |  |  | export const store = configureStore({ | 
					
						
							| 
									
										
										
										
											2022-11-08 17:51:44 +01:00
										 |  |  | 	reducer: persistedReducer, | 
					
						
							|  |  |  | 	middleware: (getDefaultMiddleware) => { | 
					
						
							|  |  |  | 		return getDefaultMiddleware({ | 
					
						
							|  |  |  | 			serializableCheck: { | 
					
						
							| 
									
										
										
										
											2023-10-05 16:06:19 +02:00
										 |  |  | 				ignoredActions: [ | 
					
						
							|  |  |  | 					FLUSH, | 
					
						
							|  |  |  | 					REHYDRATE, | 
					
						
							|  |  |  | 					PAUSE, | 
					
						
							|  |  |  | 					PERSIST, | 
					
						
							|  |  |  | 					PURGE, | 
					
						
							|  |  |  | 					REGISTER, | 
					
						
							| 
									
										
										
										
											2025-04-07 16:14:41 +02:00
										 |  |  | 				], | 
					
						
							|  |  |  | 				ignoredPaths: ['api.queries.twoFactorQRCodePng(undefined).data.data'], | 
					
						
							| 
									
										
										
										
											2022-11-08 17:51:44 +01:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2023-10-05 16:06:19 +02:00
										 |  |  | 		}).concat(gtsApi.middleware); | 
					
						
							| 
									
										
										
										
											2022-11-08 17:51:44 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | }); | 
					
						
							| 
									
										
										
										
											2022-09-29 12:02:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-05 16:06:19 +02:00
										 |  |  | export const persistor = persistStore(store); | 
					
						
							| 
									
										
										
										
											2022-09-29 12:02:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-05 16:06:19 +02:00
										 |  |  | export type AppDispatch = typeof store.dispatch; | 
					
						
							|  |  |  | export type RootState = ReturnType<typeof store.getState>; |