blob: 20c2a065770a3fd9058afb7cb7f4573337e18735 [file] [log] [blame]
idillond858c182022-09-16 13:18:26 -04001import { createSlice, PayloadAction } from "@reduxjs/toolkit";
ervinanoh99655642022-09-01 15:11:31 -04002import Account from "../../model/Account";
idillond858c182022-09-16 13:18:26 -04003import type { RootState } from "./store";
4
5// Define a type for the slice state
6interface appState {
idillon531b6f22022-09-16 14:02:00 -04007 accountId: string;
ervinanoh99655642022-09-01 15:11:31 -04008 accountObject: Account;
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 = {
idillon531b6f22022-09-16 14:02:00 -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({
20 name: "app",
21 // `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;