blob: d5c01ee3c27771fa13f53621a5d8ec047ac4ea86 [file] [log] [blame]
simon26e79f72022-10-05 22:16:08 -04001/*
2 * Copyright (C) 2022 Savoir-faire Linux Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation; either version 3 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
13 *
14 * You should have received a copy of the GNU Affero General Public
15 * License along with this program. If not, see
16 * <https://www.gnu.org/licenses/>.
17 */
simond47ef9e2022-09-28 22:24:28 -040018import { createSlice, PayloadAction } from '@reduxjs/toolkit';
simon20076982022-10-11 15:04:13 -040019import { Account } from 'jami-web-common';
idillond858c182022-09-16 13:18:26 -040020
21// Define a type for the slice state
simond8ca2f22022-10-11 23:30:55 -040022export interface appState {
idillon531b6f22022-09-16 14:02:00 -040023 accountId: string;
simonc7d52452022-09-23 02:09:42 -040024 accountObject: Account | null;
ervinanoh34eb9472022-09-13 04:20:28 -040025 refresh: boolean;
idillond858c182022-09-16 13:18:26 -040026}
27
28// Define the initial state using that type
29const initialState: appState = {
simond47ef9e2022-09-28 22:24:28 -040030 accountId: '',
ervinanoh99655642022-09-01 15:11:31 -040031 accountObject: null,
ervinanoh34eb9472022-09-13 04:20:28 -040032 refresh: true,
idillond858c182022-09-16 13:18:26 -040033};
34
35export const appSlice = createSlice({
simond47ef9e2022-09-28 22:24:28 -040036 name: 'app',
idillond858c182022-09-16 13:18:26 -040037 // `createSlice` will infer the state type from the `initialState` argument
38 initialState,
39 reducers: {
idillon531b6f22022-09-16 14:02:00 -040040 setAccountId: (state, action: PayloadAction<string>) => {
41 state.accountId = action.payload;
idillond858c182022-09-16 13:18:26 -040042 },
ervinanoh99655642022-09-01 15:11:31 -040043 setAccountObject: (state, action: PayloadAction<Account>) => {
ervinanoh34eb9472022-09-13 04:20:28 -040044 state.accountObject = action.payload;
45 },
46 setRefreshFromSlice: (state) => {
47 state.refresh = !state.refresh;
ervinanoh99655642022-09-01 15:11:31 -040048 },
idillond858c182022-09-16 13:18:26 -040049 },
50});
51
ervinanoh34eb9472022-09-13 04:20:28 -040052export const { setAccountId, setAccountObject, setRefreshFromSlice } = appSlice.actions;
idillond858c182022-09-16 13:18:26 -040053
54// Other code such as selectors can use the imported `RootState` type
idillon531b6f22022-09-16 14:02:00 -040055// export const selectCount = (state: RootState) => state.app.value;
idillond858c182022-09-16 13:18:26 -040056
57export default appSlice.reducer;