aboutsummaryrefslogtreecommitdiff
path: root/src/models/upkQuestionSlice.ts
blob: 79bef09871d0985797f48afe12c8aee86af53097 (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
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[]>) {
            console.log("setUpkQuestions:", state)
            const existingIds = new Set(state.map(q => q.property_id));
            const newQuestions = action.payload.filter(q => !existingIds.has(q.property_id));
            state.push(...newQuestions);
        },
    }
})

export const {
    setUpkQuestions,
} = upkQuestionSlice.actions;
export default upkQuestionSlice.reducer