blob: b99f508e033bb56de415f4b7ce5adea3fe389b83 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
import {createSlice, PayloadAction} from '@reduxjs/toolkit'
import type {RootState} from '@/store'
import {QuestionInfo} from "@/api";
const initialState: QuestionInfo[] = []
const upkQuestionSlice = createSlice({
name: 'upkQuestions',
initialState,
reducers: {
setUpkQuestions(state, action: PayloadAction<QuestionInfo[]>) {
const existingIds = new Set(state.map(q => q.question_id));
const newQuestions = action.payload.filter(q => !existingIds.has(q.property_id));
state.push(...newQuestions);
},
}
})
export const {
setUpkQuestions,
} = upkQuestionSlice.actions;
export default upkQuestionSlice.reducer
// We need to fetch the next available Question that either doesn't have an Answer, or the Answer
// isn't Answer.completed
export const selectUpkQuestions = (state: RootState) => state.questions
|