Skip to content

Commit

Permalink
[C] update typing
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgoff authored and Blake Mason committed Nov 1, 2023
1 parent 6606536 commit 9879df2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions contexts/StoredAnswersContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { createContext, useCallback, useSyncExternalStore } from "react";
import { Query } from "@/gql/student-schema/graphql";
import { Answers, InvestigationId } from "@/types/answers";
import { AnswerData, Answers, InvestigationId } from "@/types/answers";

function setLocalStorage(investigationId: InvestigationId, answers: Answers) {
if (!investigationId) return;
Expand All @@ -16,7 +16,7 @@ function setLocalStorage(investigationId: InvestigationId, answers: Answers) {
const StoredAnswersContext = createContext<{
answers: Answers;
onChangeCallback?: (
data: string | object,
data: AnswerData,
questionId: string,
answerId?: string | null
) => void;
Expand Down Expand Up @@ -59,7 +59,7 @@ function StoredAnswersProvider(props: {
const answers = (JSON.parse(storedAnswers) as Answers) ?? {};

const onChangeCallback = useCallback(
(data: string | object, questionId: string, answerId?: string | null) => {
(data: AnswerData, questionId: string, answerId?: string | null) => {
const prevAnswers = (JSON.parse(getSnapshot()) as Answers) ?? {};
const newAnswers = Object.assign({}, prevAnswers, {
[questionId]: {
Expand Down
4 changes: 3 additions & 1 deletion types/answers.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ export type InlineQuestionData = {
[key: QuestionId]: TextInput | SelectInput | MultiselectInput;
};

export type AnswerData = SimpleQuestionData | InlineQuestionData;

export interface Answer {
data: SimpleQuestionData | InlineQuestionData;
data: AnswerData;
id?: string;
questionId?: QuestionId;
}
Expand Down

0 comments on commit 9879df2

Please sign in to comment.