chore: rename folders

This commit is contained in:
Steven
2023-06-23 11:57:15 +08:00
parent 591edfc62d
commit 4d0bdc9b97
15 changed files with 13 additions and 13 deletions

19
web/src/stores/index.ts Normal file
View File

@@ -0,0 +1,19 @@
import { configureStore } from "@reduxjs/toolkit";
import { TypedUseSelectorHook, useSelector } from "react-redux";
import globalReducer from "./modules/global";
import userReducer from "./modules/user";
import shortcutReducer from "./modules/shortcut";
const store = configureStore({
reducer: {
global: globalReducer,
user: userReducer,
shortcut: shortcutReducer,
},
});
type AppState = ReturnType<typeof store.getState>;
export const useAppSelector: TypedUseSelectorHook<AppState> = useSelector;
export default store;

View File

@@ -0,0 +1,19 @@
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
type State = {
// do nth
};
const globalSlice = createSlice({
name: "global",
initialState: {} as State,
reducers: {
setGlobalState: (_, action: PayloadAction<State>) => {
return action.payload;
},
},
});
export const { setGlobalState } = globalSlice.actions;
export default globalSlice.reducer;

View File

@@ -0,0 +1,51 @@
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
interface State {
shortcutList: Shortcut[];
}
const shortcutSlice = createSlice({
name: "shortcut",
initialState: {
shortcutList: [],
} as State,
reducers: {
setShortcuts: (state, action: PayloadAction<Shortcut[]>) => {
return {
...state,
shortcutList: action.payload,
};
},
createShortcut: (state, action: PayloadAction<Shortcut>) => {
return {
...state,
shortcutList: state.shortcutList.concat(action.payload).sort((a, b) => b.createdTs - a.createdTs),
};
},
patchShortcut: (state, action: PayloadAction<Partial<Shortcut>>) => {
return {
...state,
shortcutList: state.shortcutList.map((s) => {
if (s.id === action.payload.id) {
return {
...s,
...action.payload,
};
} else {
return s;
}
}),
};
},
deleteShortcut: (state, action: PayloadAction<ShortcutId>) => {
return {
...state,
shortcutList: [...state.shortcutList].filter((shortcut) => shortcut.id !== action.payload),
};
},
},
});
export const { setShortcuts, createShortcut, patchShortcut, deleteShortcut } = shortcutSlice.actions;
export default shortcutSlice.reducer;

View File

@@ -0,0 +1,32 @@
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
interface State {
// user is the user who is currently logged in
user?: User;
}
const userSlice = createSlice({
name: "user",
initialState: {} as State,
reducers: {
setUser: (state, action: PayloadAction<User | undefined>) => {
return {
...state,
user: action.payload,
};
},
patchUser: (state, action: PayloadAction<Partial<User>>) => {
return {
...state,
user: {
...state.user,
...action.payload,
} as User,
};
},
},
});
export const { setUser, patchUser } = userSlice.actions;
export default userSlice.reducer;