diff --git a/src/components/ButtonAddGoalOrChallenge.vue b/src/components/ButtonAddGoalOrChallenge.vue index a1f6360ba3e4036b7c6073b591bb9bce3dac9589..315df32fde52a4eb46597be56b1a0c2e6b6ba4cd 100644 --- a/src/components/ButtonAddGoalOrChallenge.vue +++ b/src/components/ButtonAddGoalOrChallenge.vue @@ -29,9 +29,9 @@ const props = defineProps({ buttonText: String, type: String, showModal: Boolean -}); +}) -const emit = defineEmits(['update:showModal']); +const emit = defineEmits(['update:showModal']) const router = useRouter() @@ -39,12 +39,11 @@ const btnText = ref(props.buttonText) const routeToGoalOrChallenge = () => { if (props.type === 'goal') { - router.push('/sparemaal'); + router.push('/sparemaal') } else if (props.type === 'challenge') { - router.push('/spareutfordringer'); + router.push('/spareutfordringer') } else if (props.type === 'generatedChallenge') { - emit('update:showModal', true); + emit('update:showModal', true) } -}; - +} </script> diff --git a/src/components/GeneratedChallengesModal.vue b/src/components/GeneratedChallengesModal.vue index b210806086374c03083d7f59b580a4eb6cf3cfc5..b8fc7885f79c104922d00f01dca1e3360e0d016c 100644 --- a/src/components/GeneratedChallengesModal.vue +++ b/src/components/GeneratedChallengesModal.vue @@ -25,9 +25,16 @@ Personlig tilpassede spareutfordringer: </div> <div class="grid grid-cols-7 sm:grid-cols-11 gap-2 p-3 pb-1 border-b-2"> - <span class="font-bold col-span-2 md:col-span-3 sm:text-lg pt-1 mb-0">Tittel</span> - <span class="font-bold col-span-2 md:col-span-2 sm:text-lg pt-1 mb-0">MÃ¥lsum</span> - <span class="font-bold col-span-2 md:col-span-1 sm:text-lg pt-1 pr-1 md:pr-3 mb-0">Frist</span> + <span class="font-bold col-span-2 md:col-span-3 sm:text-lg pt-1 mb-0" + >Tittel</span + > + <span class="font-bold col-span-2 md:col-span-2 sm:text-lg pt-1 mb-0" + >MÃ¥lsum</span + > + <span + class="font-bold col-span-2 md:col-span-1 sm:text-lg pt-1 pr-1 md:pr-3 mb-0" + >Frist</span + > <span class="col-span-2"></span> </div> <div class="space-y-2"> @@ -37,13 +44,21 @@ :class="{ 'bg-gray-100': index % 2 === 0 }" class="grid grid-cols-7 md:grid-cols-7 sm:grid-cols-2 lg:grid-cols-7 gap-4 items-center border p-3 rounded mt-[-8px]" > - <span class="break-words col-span-2 md:col-span-1 lg:col-span-2 text-lg">{{ challenge.title }}</span> - <span class="col-span-2 md:col-span-2 lg:col-span-1 text-lg">{{ challenge.target }}</span> - <span class="col-span-2 md:col-span-1 lg:col-span-2 text-lg">{{ challenge.due }}</span> + <span class="break-words col-span-2 md:col-span-1 lg:col-span-2 text-lg">{{ + challenge.title + }}</span> + <span class="col-span-2 md:col-span-2 lg:col-span-1 text-lg">{{ + challenge.target + }}</span> + <span class="col-span-2 md:col-span-1 lg:col-span-2 text-lg">{{ + challenge.due + }}</span> <div class="col-span-7 sm:col-start-3 sm:col-span-2 md:col-span-2 lg:col-span-2 flex items-center justify-end space-x-2" > - <span v-if="challenge.isAccepted" class="font-bold text-lg">Godtatt!</span> + <span v-if="challenge.isAccepted" class="font-bold text-lg" + >Godtatt!</span + > <button @click="acceptChallenge(challenge)" class="text-white font-bold py-1 px-4 mt-[-14px] sm:mt-0" @@ -61,43 +76,46 @@ </div> </template> - <script setup> import { ref, reactive, onMounted } from 'vue' import authInterceptor from '@/services/authInterceptor' -const showModal = ref(true); -const generatedChallenges = reactive([]); +const showModal = ref(true) +const generatedChallenges = reactive([]) async function fetchGeneratedChallenges() { try { - const response = await authInterceptor.get('/challenges/generate'); + const response = await authInterceptor.get('/challenges/generate') if (response.status === 200) { - generatedChallenges.splice(0, generatedChallenges.length, ...response.data.map(ch => ({ - ...ch, - due: new Date(ch.due).toISOString().split('T')[0], - dueFull: ch.due, - accepted: false - }))); - console.log('Generated challenges:', generatedChallenges); + generatedChallenges.splice( + 0, + generatedChallenges.length, + ...response.data.map((ch) => ({ + ...ch, + due: new Date(ch.due).toISOString().split('T')[0], + dueFull: ch.due, + accepted: false + })) + ) + console.log('Generated challenges:', generatedChallenges) } else { - console.log('No challenges found for the user.'); - generatedChallenges.splice(0, generatedChallenges.length); + console.log('No challenges found for the user.') + generatedChallenges.splice(0, generatedChallenges.length) } } catch (error) { - console.error('Error fetching challenges:', error); + console.error('Error fetching challenges:', error) } } onMounted(() => { - fetchGeneratedChallenges(); - localStorage.setItem('lastModalShow', Date.now().toString()); -}); + fetchGeneratedChallenges() + localStorage.setItem('lastModalShow', Date.now().toString()) +}) function acceptChallenge(challenge) { if (!challenge) { - console.error('No challenge data provided to acceptChallenge function.'); - return; + console.error('No challenge data provided to acceptChallenge function.') + return } const postData = { title: challenge.title, @@ -107,18 +125,19 @@ function acceptChallenge(challenge) { description: challenge.description, due: challenge.dueFull, type: challenge.type - }; - authInterceptor.post('/challenges', postData) - .then(response => { - console.log('Challenge accepted and saved:', response.data); - challenge.isAccepted = true; + } + authInterceptor + .post('/challenges', postData) + .then((response) => { + console.log('Challenge accepted and saved:', response.data) + challenge.isAccepted = true + }) + .catch((error) => { + console.error('Failed to save challenge:', error) }) - .catch(error => { - console.error('Failed to save challenge:', error); - }); } const closeModal = () => { - showModal.value = false; + showModal.value = false } </script> diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue index f5e61d9874b0851cb1ab6e7ef8244ff72485f8a2..d8dfa5375f552fb9318961ec8001d1e984513106 100644 --- a/src/views/HomeView.vue +++ b/src/views/HomeView.vue @@ -49,18 +49,18 @@ const goals = ref<Goal[]>([]) const goal = ref<Goal | null | undefined>(null) onMounted(async () => { - await goalStore.getUserGoals(); - await challengeStore.getUserChallenges(); - challenges.value = challengeStore.challenges; - goals.value = goalStore.goals; - goal.value = goals.value[0]; - console.log('Goals:', goals.value); + await goalStore.getUserGoals() + await challengeStore.getUserChallenges() + challenges.value = challengeStore.challenges + goals.value = goalStore.goals + goal.value = goals.value[0] + console.log('Goals:', goals.value) - const lastModalShow = localStorage.getItem('lastModalShow'); + const lastModalShow = localStorage.getItem('lastModalShow') if (!lastModalShow || Date.now() - Number(lastModalShow) >= 24 * 60 * 60 * 1000) { - showModal.value = true; + showModal.value = true } -}); +}) // Define your speech array const speechArray = [