feat: thema's worden gerefetched van de api als de taal veranderd
This commit is contained in:
parent
0d1ed55001
commit
9547c76e80
4 changed files with 42 additions and 23 deletions
|
@ -1,18 +1,30 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import ThemeCard from "@/components/ThemeCard.vue";
|
import ThemeCard from "@/components/ThemeCard.vue";
|
||||||
import {onMounted, ref} from "vue";
|
import { ref, onMounted, watch } from "vue";
|
||||||
|
import { useI18n } from "vue-i18n";
|
||||||
|
|
||||||
|
const { locale } = useI18n();
|
||||||
const cards = ref<Array<{ key: string; title: string; description: string; image: string }>>([]);
|
const cards = ref<Array<{ key: string; title: string; description: string; image: string }>>([]);
|
||||||
|
|
||||||
|
// Fetch themes based on the current language
|
||||||
const fetchThemes = async () => {
|
const fetchThemes = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch("http://localhost:3000/api/theme");
|
const language = localStorage.getItem("user-lang") || locale.value;
|
||||||
|
const response = await fetch(`http://localhost:3000/api/theme?language=${language}`);
|
||||||
cards.value = await response.json();
|
cards.value = await response.json();
|
||||||
|
console.log(cards.value);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching themes:", error);
|
console.error("Error fetching themes:", error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
onMounted(fetchThemes);
|
onMounted(fetchThemes);
|
||||||
|
|
||||||
|
// Refetch themes when language changes
|
||||||
|
watch(locale, () => {
|
||||||
|
fetchThemes();
|
||||||
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
|
@ -22,9 +22,9 @@
|
||||||
contain
|
contain
|
||||||
class="title-image"
|
class="title-image"
|
||||||
></v-img>
|
></v-img>
|
||||||
<span class="title">{{ t(title) }}</span>
|
<span class="title">{{ title }}</span>
|
||||||
</v-card-title>
|
</v-card-title>
|
||||||
<v-card-text class="description flex-grow-1">{{ t(description) }}</v-card-text>
|
<v-card-text class="description flex-grow-1">{{ description }}</v-card-text>
|
||||||
<v-card-actions>
|
<v-card-actions>
|
||||||
<v-btn :to="`theme/${path}`" variant="text">
|
<v-btn :to="`theme/${path}`" variant="text">
|
||||||
{{ t("read-more") }}
|
{{ t("read-more") }}
|
||||||
|
|
|
@ -28,5 +28,8 @@
|
||||||
"upper-secondary": "14-16 jahre alt",
|
"upper-secondary": "14-16 jahre alt",
|
||||||
"high-school": "16-18 jahre alt",
|
"high-school": "16-18 jahre alt",
|
||||||
"older": "18 und älter"
|
"older": "18 und älter"
|
||||||
|
},
|
||||||
|
"basics-ai": {
|
||||||
|
"title": "Grundlegende Prinzipien der AI"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,5 +29,9 @@
|
||||||
"high-school": "16-18 years old",
|
"high-school": "16-18 years old",
|
||||||
"older": "18 and older"
|
"older": "18 and older"
|
||||||
},
|
},
|
||||||
"read-more": "read-more"
|
"read-more": "read-more",
|
||||||
|
"basics-ai": {
|
||||||
|
"title": "Basic principles of AI",
|
||||||
|
"description": "Under this teaching theme, we combine several activities that cover the basics of artificial intelligence (AI). Students learn what AI is, how it works and how it can be applied in different domains."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue