From d14aba0373eb4a9dd381c9afe4a0ca48c29429f7 Mon Sep 17 00:00:00 2001 From: Linus Bolls Date: Fri, 31 May 2024 18:44:50 +0200 Subject: [PATCH] refactor: dynamically route to different quizes --- app/[...slugs]/page.tsx | 43 ++++++++++++++++++++ app/informal/definitions/quiz/page.tsx | 27 ------------ app/informal/page.tsx | 40 ------------------ app/propositional/page.tsx | 40 ------------------ app/propositional/translations/quiz/page.tsx | 27 ------------ app/syllogistic/translations/quiz/page.tsx | 27 ------------ content.tsx | 6 +++ 7 files changed, 49 insertions(+), 161 deletions(-) create mode 100644 app/[...slugs]/page.tsx delete mode 100644 app/informal/definitions/quiz/page.tsx delete mode 100644 app/informal/page.tsx delete mode 100644 app/propositional/page.tsx delete mode 100644 app/propositional/translations/quiz/page.tsx delete mode 100644 app/syllogistic/translations/quiz/page.tsx diff --git a/app/[...slugs]/page.tsx b/app/[...slugs]/page.tsx new file mode 100644 index 0000000..4b0d36a --- /dev/null +++ b/app/[...slugs]/page.tsx @@ -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 ( +
+
+

Error: failed to find this quiz

+
+
+ ); + + return ( +
+ {/* { + return pathname === `/informal/definitions/${index + 1}`; + }} + initialQuestionIdx={0} + /> */} +
+ + + +
+
+ ); +} diff --git a/app/informal/definitions/quiz/page.tsx b/app/informal/definitions/quiz/page.tsx deleted file mode 100644 index 9d60d64..0000000 --- a/app/informal/definitions/quiz/page.tsx +++ /dev/null @@ -1,27 +0,0 @@ -import NoSSR from '@/components/NoSSR'; -import Quiz from '@/components/quiz'; - -export interface QuizPageProps { - params: { exercise: number }; -} -export default function QuizPage({}: QuizPageProps) { - return ( - <> -
- {/* { - return pathname === `/informal/definitions/${index + 1}`; - }} - initialQuestionIdx={0} - /> */} -
- - - -
-
- - ); -} diff --git a/app/informal/page.tsx b/app/informal/page.tsx deleted file mode 100644 index cdfce68..0000000 --- a/app/informal/page.tsx +++ /dev/null @@ -1,40 +0,0 @@ -import { Sidebar } from '@/components/sidebar'; - -export const metadata = { - title: 'Logicola | Informal Logic', - description: - 'Basic Propositional Logic exercises. Translating from natural language to symbolic form. LogiCola is a program to help students learn logic.', - creator: 'Malik Piara', - keywords: [ - 'logic', - 'propositional logic', - 'introduction to logic', - 'basic propositional logic', - 'propositional logic translations', - 'download logicola', - ], - publisher: 'Malik Piara', - openGraph: { - images: '/malik_mini.jpeg', - authors: ['Malik'], - }, - icons: { - icon: '/next.svg', - }, -}; - -export default function BasicPropositionalLogic() { - return ( - <> -
- -
-

- Chapter 3: Informal Logic -

- {/* */} -
-
- - ); -} diff --git a/app/propositional/page.tsx b/app/propositional/page.tsx deleted file mode 100644 index cdfce68..0000000 --- a/app/propositional/page.tsx +++ /dev/null @@ -1,40 +0,0 @@ -import { Sidebar } from '@/components/sidebar'; - -export const metadata = { - title: 'Logicola | Informal Logic', - description: - 'Basic Propositional Logic exercises. Translating from natural language to symbolic form. LogiCola is a program to help students learn logic.', - creator: 'Malik Piara', - keywords: [ - 'logic', - 'propositional logic', - 'introduction to logic', - 'basic propositional logic', - 'propositional logic translations', - 'download logicola', - ], - publisher: 'Malik Piara', - openGraph: { - images: '/malik_mini.jpeg', - authors: ['Malik'], - }, - icons: { - icon: '/next.svg', - }, -}; - -export default function BasicPropositionalLogic() { - return ( - <> -
- -
-

- Chapter 3: Informal Logic -

- {/* */} -
-
- - ); -} diff --git a/app/propositional/translations/quiz/page.tsx b/app/propositional/translations/quiz/page.tsx deleted file mode 100644 index 7e9592a..0000000 --- a/app/propositional/translations/quiz/page.tsx +++ /dev/null @@ -1,27 +0,0 @@ -import NoSSR from '@/components/NoSSR'; -import Quiz from '@/components/quiz'; - -export interface QuizPageProps { - params: { exercise: number }; -} -export default function QuizPage({}: QuizPageProps) { - return ( - <> -
- {/* { - return pathname === `/informal/definitions/${index + 1}`; - }} - initialQuestionIdx={0} - /> */} -
- - - -
-
- - ); -} diff --git a/app/syllogistic/translations/quiz/page.tsx b/app/syllogistic/translations/quiz/page.tsx deleted file mode 100644 index 7bd557c..0000000 --- a/app/syllogistic/translations/quiz/page.tsx +++ /dev/null @@ -1,27 +0,0 @@ -import NoSSR from '@/components/NoSSR'; -import Quiz from '@/components/quiz'; - -export interface QuizPageProps { - params: { exercise: number }; -} -export default function QuizPage({}: QuizPageProps) { - return ( - <> -
- {/* { - return pathname === `/informal/definitions/${index + 1}`; - }} - initialQuestionIdx={0} - /> */} -
- - - -
-
- - ); -} diff --git a/content.tsx b/content.tsx index 975bbd5..de03b65 100644 --- a/content.tsx +++ b/content.tsx @@ -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; @@ -20,6 +21,7 @@ export interface Chapter { const chapters = [ { + slugs: ['syllogistic', 'translations'], id: 1, title: 'Syllogistic Translations: Easy', header: 'Translates into logic as:', @@ -401,6 +403,7 @@ const chapters = [ ], }, { + slugs: ['propositional', 'translations'], id: 6, title: 'Propositional Translations: Easy', header: 'Translates into logic as:', @@ -1152,6 +1155,7 @@ const chapters = [ ], }, { + slugs: ['informal', 'definitions'], id: 3, title: 'Meanings and Definitions', header: 'What is wrong with this definition?', @@ -2075,6 +2079,7 @@ const chapters = [ ], }, { + slugs: ['translations', 'easy'], id: 6.1, title: 'Easier Translations', header: 'Translates into logic as:', @@ -2329,6 +2334,7 @@ const chapters = [ ], }, { + slugs: ['translations', 'hard'], id: 6.8, title: 'Harder Translations', header: 'Translates into logic as:',