diff options
| author | Max Nanis | 2025-05-28 04:41:37 +0100 |
|---|---|---|
| committer | Max Nanis | 2025-05-28 04:41:37 +0100 |
| commit | 8caa77413ea372e5cbd2980a9922d701af359c04 (patch) | |
| tree | 9341e2f70fab6b2678fdff53c002954ef69c7b3e /src/models/questionSlice.ts | |
| download | panel-ui-8caa77413ea372e5cbd2980a9922d701af359c04.tar.gz panel-ui-8caa77413ea372e5cbd2980a9922d701af359c04.zip | |
initial commit
Diffstat (limited to 'src/models/questionSlice.ts')
| -rw-r--r-- | src/models/questionSlice.ts | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/models/questionSlice.ts b/src/models/questionSlice.ts new file mode 100644 index 0000000..6a4da6f --- /dev/null +++ b/src/models/questionSlice.ts @@ -0,0 +1,36 @@ +import {createSlice, PayloadAction} from '@reduxjs/toolkit' +import type {RootState} from '@/store' +import {UpkQuestion} from "@/api/models/upk-question.ts" + +const initialState: UpkQuestion[] = [] + +// Create the slice and pass in the initial state +const questionSlice = createSlice({ + name: 'questions', + initialState, + reducers: { + setQuestions(state, action: PayloadAction<UpkQuestion[]>) { + return action.payload; + }, + questionAdded(state, action: PayloadAction<UpkQuestion>) { + state.push(action.payload); + }, + setAnswer(state, action: PayloadAction<{ questionId: string, val: string }>) { + const {questionId, val} = action.payload + console.log(questionId, val) + const existingQuestion = state.find(q => q.questionId === action.payload.questionId) + if (existingQuestion) { + // existingQuestion.addAnswer(action.payload.val) + // existingQuestion.error_msg = "yess" + } + } + } +}) + +// Export the generated reducer function +export const {setAnswer, setQuestions, questionAdded, questionUpdated} = questionSlice.actions; +export default questionSlice.reducer + +export const selectAllQuestions = (state: RootState) => state.questions + +export const selectQuestionById = (state: RootState, questionId: string) => state.questions.find(q => q.id === questionId)
\ No newline at end of file |
