blob: 61e73ea873492e156bd19f7fa9eec9011d336175 [file] [log] [blame]
simond47ef9e2022-09-28 22:24:28 -04001import { createSlice, PayloadAction } from '@reduxjs/toolkit';
simon07b4eb02022-09-29 17:50:26 -04002
simond47ef9e2022-09-28 22:24:28 -04003import Account from '../../model/Account';
idillond858c182022-09-16 13:18:26 -04004
5// Define a type for the slice state
6interface appState {
idillon531b6f22022-09-16 14:02:00 -04007 accountId: string;
simonc7d52452022-09-23 02:09:42 -04008 accountObject: Account | null;
ervinanoh34eb9472022-09-13 04:20:28 -04009 refresh: boolean;
idillond858c182022-09-16 13:18:26 -040010}
11
12// Define the initial state using that type
13const initialState: appState = {
simond47ef9e2022-09-28 22:24:28 -040014 accountId: '',
ervinanoh99655642022-09-01 15:11:31 -040015 accountObject: null,
ervinanoh34eb9472022-09-13 04:20:28 -040016 refresh: true,
idillond858c182022-09-16 13:18:26 -040017};
18
19export const appSlice = createSlice({
simond47ef9e2022-09-28 22:24:28 -040020 name: 'app',
idillond858c182022-09-16 13:18:26 -040021 // `createSlice` will infer the state type from the `initialState` argument
22 initialState,
23 reducers: {
idillon531b6f22022-09-16 14:02:00 -040024 setAccountId: (state, action: PayloadAction<string>) => {
25 state.accountId = action.payload;
idillond858c182022-09-16 13:18:26 -040026 },
ervinanoh99655642022-09-01 15:11:31 -040027 setAccountObject: (state, action: PayloadAction<Account>) => {
ervinanoh34eb9472022-09-13 04:20:28 -040028 state.accountObject = action.payload;
29 },
30 setRefreshFromSlice: (state) => {
31 state.refresh = !state.refresh;
ervinanoh99655642022-09-01 15:11:31 -040032 },
idillond858c182022-09-16 13:18:26 -040033 },
34});
35
ervinanoh34eb9472022-09-13 04:20:28 -040036export const { setAccountId, setAccountObject, setRefreshFromSlice } = appSlice.actions;
idillond858c182022-09-16 13:18:26 -040037
38// Other code such as selectors can use the imported `RootState` type
idillon531b6f22022-09-16 14:02:00 -040039// export const selectCount = (state: RootState) => state.app.value;
idillond858c182022-09-16 13:18:26 -040040
41export default appSlice.reducer;