add redux and user slice

This commit is contained in:
2024-03-23 13:48:43 +01:00
parent 2c91f4355a
commit dbec452dbe
8 changed files with 149 additions and 43 deletions
@@ -0,0 +1,31 @@
import { createSlice } from '@reduxjs/toolkit'
type LoadingState = "not-started" | "loading" | "finished"
export const userSlice = createSlice({
name: 'user',
initialState: {
state: "not-started" as LoadingState,
email: null,
},
reducers: {
load: (state) => {
state.state = "loading"
},
setUser: (state, action) => {
state.state = "finished"
state.email = action.payload
},
unsetUser: (state) => {
state.state = "finished"
state.email = null
}
},
})
// Action creators are generated for each case reducer function
export const { load, setUser, unsetUser } = userSlice.actions
export const userSelector = userSlice.selectSlice
export default userSlice.reducer