Skip to content

Commit

Permalink
refactor: dynamically route to different quizes
Browse files Browse the repository at this point in the history
  • Loading branch information
Linus Bolls authored and Linus Bolls committed May 31, 2024
1 parent 538d14c commit d14aba0
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 161 deletions.
43 changes: 43 additions & 0 deletions app/[...slugs]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import NoSSR from '@/components/NoSSR';
import Quiz from '@/components/quiz';
import { chapters } from '@/content';

const arraysAreSame = (array1: string[], array2: string[]) =>
array1.length === array2.length &&
array1.every((value, index) => value === array2[index]);

export interface QuizPageProps {
params: { slugs: string[]; exercise: number };
}
export default function QuizPage({ params }: QuizPageProps) {
const chapter = chapters.find((i) =>
arraysAreSame(i.slugs.concat(['quiz']), params.slugs)
);

if (!chapter)
return (
<div className='flex w-full h-screen'>
<main className='p-4 w-full'>
<h1>Error: failed to find this quiz</h1>
</main>
</div>
);

return (
<div className='flex w-full h-screen'>
{/* <ExerciseSidebar
chapter={3}
path='/informal/definitions/'
isQuestionActive={(index) => {
return pathname === `/informal/definitions/${index + 1}`;
}}
initialQuestionIdx={0}
/> */}
<main className='p-4 w-full'>
<NoSSR>
<Quiz chapter={chapter.id} showExerciseId={false} />
</NoSSR>
</main>
</div>
);
}
27 changes: 0 additions & 27 deletions app/informal/definitions/quiz/page.tsx

This file was deleted.

40 changes: 0 additions & 40 deletions app/informal/page.tsx

This file was deleted.

40 changes: 0 additions & 40 deletions app/propositional/page.tsx

This file was deleted.

27 changes: 0 additions & 27 deletions app/propositional/translations/quiz/page.tsx

This file was deleted.

27 changes: 0 additions & 27 deletions app/syllogistic/translations/quiz/page.tsx

This file was deleted.

6 changes: 6 additions & 0 deletions content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const feedback_single_person =
'stands for a single person, and so translates into a small letter.';

export interface Chapter {
slugs: string[];
id: number;
title: string;
header: string;
Expand All @@ -20,6 +21,7 @@ export interface Chapter {

const chapters = [
{
slugs: ['syllogistic', 'translations'],
id: 1,
title: 'Syllogistic Translations: Easy',
header: 'Translates into logic as:',
Expand Down Expand Up @@ -401,6 +403,7 @@ const chapters = [
],
},
{
slugs: ['propositional', 'translations'],
id: 6,
title: 'Propositional Translations: Easy',
header: 'Translates into logic as:',
Expand Down Expand Up @@ -1152,6 +1155,7 @@ const chapters = [
],
},
{
slugs: ['informal', 'definitions'],
id: 3,
title: 'Meanings and Definitions',
header: 'What is wrong with this definition?',
Expand Down Expand Up @@ -2075,6 +2079,7 @@ const chapters = [
],
},
{
slugs: ['translations', 'easy'],
id: 6.1,
title: 'Easier Translations',
header: 'Translates into logic as:',
Expand Down Expand Up @@ -2329,6 +2334,7 @@ const chapters = [
],
},
{
slugs: ['translations', 'hard'],
id: 6.8,
title: 'Harder Translations',
header: 'Translates into logic as:',
Expand Down

1 comment on commit d14aba0

@vercel
Copy link

@vercel vercel bot commented on d14aba0 May 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.