aboutsummaryrefslogtreecommitdiff
path: root/src/models/questionSlice.ts
diff options
context:
space:
mode:
authorMax Nanis2025-06-23 17:20:31 +0700
committerMax Nanis2025-06-23 17:20:31 +0700
commit8138549f64403874eb7c7ddfbde1cc2cc2c03695 (patch)
treeff16ff5bf7b0a5454fd181d178a6f799b9141d64 /src/models/questionSlice.ts
parent5e8b1b89bfffd0202bc6c5f64aac943053d79d32 (diff)
downloadpanel-ui-8138549f64403874eb7c7ddfbde1cc2cc2c03695.tar.gz
panel-ui-8138549f64403874eb7c7ddfbde1cc2cc2c03695.zip
Typescript validation finally passes.
Diffstat (limited to 'src/models/questionSlice.ts')
-rw-r--r--src/models/questionSlice.ts16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/models/questionSlice.ts b/src/models/questionSlice.ts
index 3ef2218..9cba93e 100644
--- a/src/models/questionSlice.ts
+++ b/src/models/questionSlice.ts
@@ -6,7 +6,7 @@ import {assert} from "@/lib/utils.ts"
import {Selector} from "react-redux";
export interface ProfileQuestion extends UpkQuestion {
- active: false
+ active: boolean
}
const initialState: ProfileQuestion[] = []
@@ -20,7 +20,11 @@ const questionSlice = createSlice({
// },
setQuestions(state, action: PayloadAction<ProfileQuestion[]>) {
const existingIds = new Set(state.map(q => q.question_id));
- const newQuestions = action.payload.filter(q => !existingIds.has(q.question_id));
+ const newQuestions = action.payload.filter(q => !existingIds.has(q.question_id)).map((q) => ({
+ ...q,
+ active: false,
+ }));
+
state.push(...newQuestions);
},
questionAdded(state, action: PayloadAction<ProfileQuestion>) {
@@ -72,9 +76,9 @@ export const makeSelectQuestionsByIds = (ids: string[]) =>
export const selectActiveQuestion = (state: RootState) => state.questions.find(i => i.active)
export const selectAnswers = (state: RootState) => state.answers
-export const selectFirstAvailableQuestion = createSelector(
+export const selectFirstAvailableQuestion: Selector<RootState, ProfileQuestion | null> = createSelector(
[selectQuestions, selectAnswers],
- (questions, answers): Selector<RootState, ProfileQuestion | null> => {
+ (questions, answers) => {
/* This is used when the app loads up the Questions page and we
need to find the first Question that we'll present to
the Respondent.
@@ -99,9 +103,9 @@ export const selectFirstAvailableQuestion = createSelector(
}
)
-export const selectNextAvailableQuestion = createSelector(
+export const selectNextAvailableQuestion: Selector<RootState, ProfileQuestion | null> = createSelector(
[selectQuestions, selectAnswers],
- (questions, answers): Selector<RootState, ProfileQuestion | null> => {
+ (questions, answers) => {
/* This takes the current active position and finds the next available
question to answer.