Переглянути джерело

:construction: create sentenceReducer

visuddhinanda 3 роки тому
батько
коміт
f62d157225
2 змінених файлів з 32 додано та 0 видалено
  1. 30 0
      dashboard/src/reducers/sentence.ts
  2. 2 0
      dashboard/src/store.ts

+ 30 - 0
dashboard/src/reducers/sentence.ts

@@ -0,0 +1,30 @@
+import { createSlice, PayloadAction } from "@reduxjs/toolkit";
+
+import type { RootState } from "../store";
+
+interface IState {
+  sentence: string[];
+}
+
+const initialState: IState = { sentence: [] };
+
+export const slice = createSlice({
+  name: "sentence",
+  initialState,
+  reducers: {
+    push: (state, action: PayloadAction<string>) => {
+      if (state.sentence.includes(action.payload) === false) {
+        state.sentence.push(action.payload);
+      }
+    },
+  },
+});
+
+export const { push } = slice.actions;
+
+export const sentence = (state: RootState): IState => state.sentence;
+
+export const sentenceList = (state: RootState): string[] =>
+  state.sentence.sentence;
+
+export default slice.reducer;

+ 2 - 0
dashboard/src/store.ts

@@ -10,6 +10,7 @@ import suggestionReducer from "./reducers/suggestion";
 import articleModeReducer from "./reducers/article-mode";
 import inlineDictReducer from "./reducers/inline-dict";
 import currentCourseReducer from "./reducers/current-course";
+import sentenceReducer from "./reducers/sentence";
 
 const store = configureStore({
   reducer: {
@@ -23,6 +24,7 @@ const store = configureStore({
     articleMode: articleModeReducer,
     inlineDict: inlineDictReducer,
     currentCourse: currentCourseReducer,
+    sentence: sentenceReducer,
   },
 });