From 54a2cf080041ee843b8c5b0391d467d062ee037c Mon Sep 17 00:00:00 2001 From: Joyelle Ndagijimana Date: Thu, 20 Mar 2025 23:28:21 +0100 Subject: [PATCH] feat: thema's filteren op categorie en leeftijd werkt --- frontend/src/components/BrowseThemes.vue | 26 +++- frontend/src/utils/constants.ts | 24 +++- frontend/src/views/homepage/UserHomePage.vue | 131 ++++++++++++------- 3 files changed, 120 insertions(+), 61 deletions(-) diff --git a/frontend/src/components/BrowseThemes.vue b/frontend/src/components/BrowseThemes.vue index 8de21c71..1c1642c7 100644 --- a/frontend/src/components/BrowseThemes.vue +++ b/frontend/src/components/BrowseThemes.vue @@ -2,10 +2,19 @@ import ThemeCard from "@/components/ThemeCard.vue"; import { ref, onMounted, watch } from "vue"; import { useI18n } from "vue-i18n"; - import {THEMESITEMS} from "@/utils/constants.ts"; + import {AGE_TO_THEMES, THEMESITEMS} from "@/utils/constants.ts"; // Receive the selectedTheme from the parent component - const props = defineProps<{ selectedTheme: string }>(); + const props = defineProps({ + selectedTheme: { + type: String, + required: true + }, + selectedAge: { + type: String, + required: true + } + }); const {locale} = useI18n(); @@ -38,8 +47,17 @@ // Watch for selectedTheme change and filter themes watch(() => props.selectedTheme, (newTheme) => { - if (newTheme && newTheme !== "all") { - cards.value = allCards.value.filter(theme => THEMESITEMS[newTheme].includes(theme.key)); + if (newTheme) { + cards.value = allCards.value.filter(theme => THEMESITEMS[newTheme].includes(theme.key) && AGE_TO_THEMES[props.selectedAge]?.includes(theme.key)); + } else { + cards.value = allCards.value; + } + }); + + // Watch for selectedAge change and filter themes + watch(() => props.selectedAge, (newAge) => { + if (newAge) { + cards.value = allCards.value.filter(theme => THEMESITEMS[props.selectedTheme].includes(theme.key) && AGE_TO_THEMES[newAge]?.includes(theme.key)); } else { cards.value = allCards.value; } diff --git a/frontend/src/utils/constants.ts b/frontend/src/utils/constants.ts index f6129671..e046d9c3 100644 --- a/frontend/src/utils/constants.ts +++ b/frontend/src/utils/constants.ts @@ -16,12 +16,22 @@ export const THEMESITEMS: Record = { "algorithms": ["math_with_python", "python_programming", "stem", "algorithms", "basics_ai"], }; - export const AGEITEMS = [ - "all", - "primary-school", - "lower-secondary", - "upper-secondary", - "high-school", - "older", + "all", "primary-school", "lower-secondary", "upper-secondary", "high-school", "older" ]; + +export const AGE_TO_THEMES: Record = { + "all": THEMES_KEYS, + "primary-school": ["wegostem", "computational_thinking", "physical_computing"], + "lower-secondary": ["socialrobot", "art", "wegostem", "computational_thinking", "physical_computing"], + "upper-secondary": ["kiks", "art", "socialrobot", "agriculture", + "computational_thinking", "math_with_python", "python_programming", + "stem", "care", "chatbot", "algorithms", "basics_ai"], + "high-school": [ + "kiks", "art", "agriculture", "computational_thinking", "math_with_python", "python_programming", + "stem", "care", "chatbot", "algorithms", "basics_ai" + ], + "older": [ + "kiks", "computational_thinking", "algorithms", "basics_ai" + ] +}; diff --git a/frontend/src/views/homepage/UserHomePage.vue b/frontend/src/views/homepage/UserHomePage.vue index 7acffb11..20b38433 100644 --- a/frontend/src/views/homepage/UserHomePage.vue +++ b/frontend/src/views/homepage/UserHomePage.vue @@ -1,19 +1,49 @@