diff --git a/app/[chapter]/[subchapter]/quiz/page.tsx b/app/[chapter]/[subchapter]/quiz/page.tsx index 20cb0f4..eff4943 100644 --- a/app/[chapter]/[subchapter]/quiz/page.tsx +++ b/app/[chapter]/[subchapter]/quiz/page.tsx @@ -63,6 +63,7 @@ export default function QuizPage({ return ( { + console.log('quiz_started'); posthog.capture('quiz_started', { questionsCount: questions.length, }); diff --git a/components/button.tsx b/components/button.tsx index 566a866..ebb6447 100644 --- a/components/button.tsx +++ b/components/button.tsx @@ -1,6 +1,8 @@ import { cn } from '@/lib/utils'; -type ButtonProps = React.HTMLProps; +type ButtonProps = React.ComponentPropsWithoutRef<'button'> & { + onClick?: () => void; +}; const Button = (props: ButtonProps) => { return ( diff --git a/components/faqAccordion.tsx b/components/faqAccordion.tsx index 05127db..c4e198a 100644 --- a/components/faqAccordion.tsx +++ b/components/faqAccordion.tsx @@ -9,7 +9,7 @@ function AccordionItem({ title, content, initiallyOpen = false }: any) {

diff --git a/components/option.tsx b/components/option.tsx index f67e8a5..18643a3 100644 --- a/components/option.tsx +++ b/components/option.tsx @@ -1,5 +1,6 @@ import classNames from 'classnames'; import React from 'react'; +import { useHotkeys } from 'react-hotkeys-hook'; export interface OptionProps extends React.HTMLProps { index?: number; @@ -8,7 +9,8 @@ export interface OptionProps extends React.HTMLProps { isSelected: boolean; isCorrect: boolean; showSolution: boolean; - onClick: () => void; + onSelect: () => void; + keyboardShortcut: string; } const Option: React.FC = ({ @@ -18,7 +20,8 @@ const Option: React.FC = ({ isSelected, isCorrect, showSolution, - onClick, + onSelect, + keyboardShortcut, ...props }) => { const optionClasses = classNames( @@ -34,11 +37,17 @@ const Option: React.FC = ({ } ); + useHotkeys(keyboardShortcut, () => { + if (showSolution) return; + onSelect(); + (document.activeElement as HTMLElement)?.blur(); + }); + return ( )} + + {nextQuestionButton}
diff --git a/components/quiz/keyboardKeys.tsx b/components/quiz/keyboardKeys.tsx index 74b2b3b..519fee8 100644 --- a/components/quiz/keyboardKeys.tsx +++ b/components/quiz/keyboardKeys.tsx @@ -1,18 +1,18 @@ -export function KeyboardKeys() { +export function KeyboardKeys({ questionsAmount }: { questionsAmount: number }) { return ( -

+

You can use keys{' '} - + 1 {' '} to{' '} - - 7 + + {questionsAmount} {' or '} - + Arrow key up {' '} - + {' + '} - + Enter {' '} to navigate the quiz. diff --git a/package.json b/package.json index 6248688..98855f5 100644 --- a/package.json +++ b/package.json @@ -24,9 +24,10 @@ "next": "14.1.3", "posthog-js": "^1.121.4", "posthog-node": "^4.0.0", - "react": "^18", + "react": "^18.2.0", "react-canvas-confetti": "^2.0.7", - "react-dom": "^18", + "react-dom": "^18.2.0", + "react-hotkeys-hook": "^4.5.0", "tailwind-merge": "^2.2.2", "tailwindcss-animate": "^1.0.7" }, @@ -34,8 +35,8 @@ "@testing-library/jest-dom": "^6.4.2", "@testing-library/react": "^15.0.2", "@types/node": "^20", - "@types/react": "^18", - "@types/react-dom": "^18", + "@types/react": "^18.2.0", + "@types/react-dom": "^18.2.0", "@typescript-eslint/eslint-plugin": "^6.21.0", "@vitejs/plugin-react": "^4.2.1", "autoprefixer": "^10.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 49fe773..de74214 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -39,14 +39,17 @@ dependencies: specifier: ^4.0.0 version: 4.0.0 react: - specifier: ^18 + specifier: ^18.2.0 version: 18.2.0 react-canvas-confetti: specifier: ^2.0.7 version: 2.0.7(react@18.2.0) react-dom: - specifier: ^18 + specifier: ^18.2.0 version: 18.2.0(react@18.2.0) + react-hotkeys-hook: + specifier: ^4.5.0 + version: 4.5.0(react-dom@18.2.0)(react@18.2.0) tailwind-merge: specifier: ^2.2.2 version: 2.3.0 @@ -65,10 +68,10 @@ devDependencies: specifier: ^20 version: 20.12.7 '@types/react': - specifier: ^18 + specifier: ^18.2.0 version: 18.2.78 '@types/react-dom': - specifier: ^18 + specifier: ^18.2.0 version: 18.2.25 '@typescript-eslint/eslint-plugin': specifier: ^6.21.0 @@ -4043,6 +4046,16 @@ packages: react: 18.2.0 scheduler: 0.23.0 + /react-hotkeys-hook@4.5.0(react-dom@18.2.0)(react@18.2.0): + resolution: {integrity: sha512-Samb85GSgAWFQNvVt3PS90LPPGSf9mkH/r4au81ZP1yOIFayLC3QAvqTgGtJ8YEDMXtPmaVBs6NgipHO6h4Mug==} + peerDependencies: + react: '>=16.8.1' + react-dom: '>=16.8.1' + dependencies: + react: 18.2.0 + react-dom: 18.2.0(react@18.2.0) + dev: false + /react-is@16.13.1: resolution: {integrity: sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==} dev: true