From db1bb55a307fe4588738bf7b00d723c4db30f784 Mon Sep 17 00:00:00 2001 From: Kavi Gupta Date: Sun, 5 Jan 2025 21:21:32 -0500 Subject: [PATCH] make today's name optional --- react/src/components/quiz-panel.tsx | 4 ++-- react/src/navigation/PageDescriptor.ts | 2 +- react/src/quiz/quiz-result.tsx | 12 ++++++++---- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/react/src/components/quiz-panel.tsx b/react/src/components/quiz-panel.tsx index 3b7df6571..b99754793 100644 --- a/react/src/components/quiz-panel.tsx +++ b/react/src/components/quiz-panel.tsx @@ -9,7 +9,7 @@ import { QuizQuestionDispatch } from '../quiz/quiz-question' import { QuizResult } from '../quiz/quiz-result' import { useHeaderTextClass } from '../utils/responsive' -export function QuizPanel(props: { quizDescriptor: QuizDescriptor, todayName: string, todaysQuiz: QuizQuestionsModel }): ReactNode { +export function QuizPanel(props: { quizDescriptor: QuizDescriptor, todayName?: string, todaysQuiz: QuizQuestionsModel }): ReactNode { // set a unique key for the quiz panel so that it will re-render when the quiz changes // this is necessary because the quiz panel is a stateful component with all the questions cached. return ( @@ -22,7 +22,7 @@ export function QuizPanel(props: { quizDescriptor: QuizDescriptor, todayName: st ) } -function QuizPanelNoResets(props: { quizDescriptor: QuizDescriptor, todayName: string, todaysQuiz: QuizQuestionsModel }): ReactNode { +function QuizPanelNoResets(props: { quizDescriptor: QuizDescriptor, todayName?: string, todaysQuiz: QuizQuestionsModel }): ReactNode { // We don't want to save certain quiz types, so bypass the persistent store for those const headerClass = useHeaderTextClass() const persistentQuizHistory = QuizLocalStorage.shared.history.use() diff --git a/react/src/navigation/PageDescriptor.ts b/react/src/navigation/PageDescriptor.ts index 694b1a57b..a23a0e5b6 100644 --- a/react/src/navigation/PageDescriptor.ts +++ b/react/src/navigation/PageDescriptor.ts @@ -141,7 +141,7 @@ export type PageData = | { kind: 'index' } | { kind: 'about' } | { kind: 'dataCredit' } - | { kind: 'quiz', quizDescriptor: QuizDescriptor, quiz: QuizQuestionsModel, parameters: string, todayName: string } + | { kind: 'quiz', quizDescriptor: QuizDescriptor, quiz: QuizQuestionsModel, parameters: string, todayName?: string } | { kind: 'mapper', settings: MapSettings, view: boolean } | { kind: 'error' diff --git a/react/src/quiz/quiz-result.tsx b/react/src/quiz/quiz-result.tsx index 9a54929e6..204d95d1d 100644 --- a/react/src/quiz/quiz-result.tsx +++ b/react/src/quiz/quiz-result.tsx @@ -21,7 +21,7 @@ export type CorrectPattern = (boolean | 0 | 1)[] interface QuizResultProps { quizDescriptor: QuizDescriptor - todayName: string + todayName?: string history: { // eslint-disable-next-line no-restricted-syntax -- Persistent data correct_pattern: CorrectPattern @@ -149,7 +149,7 @@ export function QuizResult(props: QuizResultProps): ReactNode { interface ShareButtonProps { buttonRef: React.RefObject - todayName: string + todayName: string | undefined correctPattern: CorrectPattern quizKind: QuizKind } @@ -345,10 +345,14 @@ export function Summary(props: { correctPattern: CorrectPattern, quizKind: QuizK ) } -export async function summary(juxtaColors: JuxtastatColors, todayName: string, correctPattern: CorrectPattern, quizKind: QuizKind): Promise<[string, string]> { +export async function summary(juxtaColors: JuxtastatColors, todayName: string | undefined, correctPattern: CorrectPattern, quizKind: QuizKind): Promise<[string, string]> { // wordle-style summary const [, summaryText] = summaryTexts(correctPattern, quizKind) - let text = `${nameOfQuizKind(quizKind)} ${todayName} ${summaryText}` + let text = nameOfQuizKind(quizKind) + if (todayName !== undefined) { + text += ` ${todayName}` + } + text += ` ${summaryText}` text += '\n' text += '\n'