From dea651444460e8f185f44b2a59aeed8efd936235 Mon Sep 17 00:00:00 2001 From: choidabom Date: Mon, 9 Dec 2024 11:10:44 +0900 Subject: [PATCH] Add the clarity of comments in the Redux store configuration --- frontend/src/store/authSlice.ts | 11 ++++++++++- frontend/src/store/configSlice.ts | 13 ++++++++++++- frontend/src/store/documentSlice.ts | 12 +++++++++--- frontend/src/store/editorSlice.ts | 14 +++++++++++++- frontend/src/store/featureSettingSlice.ts | 11 ++++++++++- frontend/src/store/store.ts | 10 ++++++++-- frontend/src/store/userSlice.ts | 15 ++++++++++++++- frontend/src/store/workspaceSlice.ts | 7 ++++++- 8 files changed, 82 insertions(+), 11 deletions(-) diff --git a/frontend/src/store/authSlice.ts b/frontend/src/store/authSlice.ts index aefa66f2..3ca961fd 100644 --- a/frontend/src/store/authSlice.ts +++ b/frontend/src/store/authSlice.ts @@ -35,4 +35,13 @@ export const { setAccessToken, setRefreshToken, logout } = authSlice.actions; export const selectAuth = (state: RootState) => state.auth; -export default authSlice.reducer; +/** + * Manages user authentication state, including login information and tokens. + * + * * This slice handles: + * - `accessToken`: The user's access token for authenticated API requests. + * - `refreshToken`: The user's refresh token for obtaining new access tokens. + */ +const reducer = authSlice.reducer; + +export default reducer; diff --git a/frontend/src/store/configSlice.ts b/frontend/src/store/configSlice.ts index 8f8c67a1..56299bf6 100644 --- a/frontend/src/store/configSlice.ts +++ b/frontend/src/store/configSlice.ts @@ -51,4 +51,15 @@ export const { setTheme, setDrawerOpen, setCodeKeyType, setDisableScrollSync } = export const selectConfig = (state: RootState) => state.config; -export default configSlice.reducer; +/** + * Handles global application settings. + * + * * This slice handles: + * - `theme`: The application theme (default, dark, or light). + * - `drawerOpen`: Whether the application drawer (sidebar) is open. + * - `codeKey`: The preferred keybinding type for code editing (Sublime, Vim, etc.). + * - `disableScrollSync`: A flag to enable or disable scroll synchronization. + */ +const reducer = configSlice.reducer; + +export default reducer; diff --git a/frontend/src/store/documentSlice.ts b/frontend/src/store/documentSlice.ts index d735a374..a828df8b 100644 --- a/frontend/src/store/documentSlice.ts +++ b/frontend/src/store/documentSlice.ts @@ -1,5 +1,5 @@ -import { createSlice } from "@reduxjs/toolkit"; import type { PayloadAction } from "@reduxjs/toolkit"; +import { createSlice } from "@reduxjs/toolkit"; import { RootState } from "./store"; export interface Document { @@ -20,7 +20,7 @@ const initialState: DocumentState = { data: null, }; -export const documentSlice = createSlice({ +const documentSlice = createSlice({ name: "document", initialState, reducers: { @@ -34,4 +34,10 @@ export const { setDocumentData } = documentSlice.actions; export const selectDocument = (state: RootState) => state.document; -export default documentSlice.reducer; +/** + * Handles document management state. + * This slice is designed to manage the currently active document, its metadata, and related state in the application. + */ +const reducer = documentSlice.reducer; + +export default reducer; diff --git a/frontend/src/store/editorSlice.ts b/frontend/src/store/editorSlice.ts index b4652f32..cb55836c 100644 --- a/frontend/src/store/editorSlice.ts +++ b/frontend/src/store/editorSlice.ts @@ -59,4 +59,16 @@ export const { setMode, setShareRole, setDoc, setClient, setCmView } = editorSli export const selectEditor = (state: RootState) => state.editor; -export default editorSlice.reducer; +/** + * Manages the state of the collaborative code editor + * + * * This slice handles: + * - `mode`: The editor's current mode (edit, read, or both). + * - `shareRole`: The user's role in the session (e.g., viewer, editor). + * - `doc`: The Yorkie document for real-time collaboration. + * - `client`: The Yorkie client for syncing data with the server. + * - `cmView`: The CodeMirror editor instance. + */ +const reducer = editorSlice.reducer; + +export default reducer; diff --git a/frontend/src/store/featureSettingSlice.ts b/frontend/src/store/featureSettingSlice.ts index bd38a0c6..c00c7939 100644 --- a/frontend/src/store/featureSettingSlice.ts +++ b/frontend/src/store/featureSettingSlice.ts @@ -44,4 +44,13 @@ export const { setYorkieIntelligence, setFileUpload } = featureSettingSlice.acti export const selectFeatureSetting = (state: RootState) => state.featureSetting; -export default featureSettingSlice.reducer; +/** + * Manages settings for specific features (e.g., experimental feature toggles). + * + * * This slice handles: + * - `yorkieIntelligence`: Settings for the Yorkie Intelligence feature + * - `fileUpload`: Settings for file upload functionality + */ +const reducer = featureSettingSlice.reducer; + +export default reducer; diff --git a/frontend/src/store/store.ts b/frontend/src/store/store.ts index d2f97b9f..826e4557 100644 --- a/frontend/src/store/store.ts +++ b/frontend/src/store/store.ts @@ -17,11 +17,17 @@ const persistConfig = { }; const rootReducer = combineReducers({ - // Persistent slices + /* + * Persistent slices: + * These slices persist their state in local storage and can restore it when the app restarts. + */ auth: authSlice, config: configSlice, - // Volatile slices + /** + * Volatile slices: + * These slices only retain their state during a session. Their state is reset when the app restarts. + */ user: userSlice, editor: editorSlice, workspace: workspaceSlice, diff --git a/frontend/src/store/userSlice.ts b/frontend/src/store/userSlice.ts index a38540ed..4af12c05 100644 --- a/frontend/src/store/userSlice.ts +++ b/frontend/src/store/userSlice.ts @@ -32,4 +32,17 @@ export const { setUserData } = userSlice.actions; export const selectUser = (state: RootState) => state.user; -export default userSlice.reducer; +/** + * Manage user profile and user-specific information. + * + * * This slice handles: + * - Storing user data, including: + * - `id`: Unique identifier for the user. + * - `nickname`: User's nickname, or `null` if not set. + * - `lastWorkspaceSlug`: The last accessed workspace's slug. + * - `updatedAt`: Timestamp of the last user update. + * - `createdAt`: Timestamp of when the user was created. + */ +const reducer = userSlice.reducer; + +export default reducer; diff --git a/frontend/src/store/workspaceSlice.ts b/frontend/src/store/workspaceSlice.ts index 482fd521..e9b497b7 100644 --- a/frontend/src/store/workspaceSlice.ts +++ b/frontend/src/store/workspaceSlice.ts @@ -32,4 +32,9 @@ export const { setWorkspaceData } = workspaceSlice.actions; export const selectWorkspace = (state: RootState) => state.workspace; -export default workspaceSlice.reducer; +/** + * Manages workspace-related state. + */ +const reducer = workspaceSlice.reducer; + +export default reducer;