Skip to content
Snippets Groups Projects
Commit a9b64054 authored by Valdemar Åstorp Beere's avatar Valdemar Åstorp Beere
Browse files

refactor(homepage):

Moved data form child to parent component
parent c064bdb7
No related branches found
No related tags found
3 merge requests!66Final merge,!32refactor(component):,!4Pipeline fix
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
<p class="text-center" data-cy="challenge-title">{{challenge.title}}</p> <p class="text-center" data-cy="challenge-title">{{challenge.title}}</p>
<img <img
@click="editChallenge(challenge)" @click="editChallenge(challenge)"
:data-cy="'challenge-icon-'+challenge.id"
:src="getChallengeIcon(challenge)" :src="getChallengeIcon(challenge)"
class="max-w-20 max-h-20 cursor-pointer" class="max-w-20 max-h-20 cursor-pointer"
:alt="challenge.title" :alt="challenge.title"
...@@ -68,6 +69,7 @@ ...@@ -68,6 +69,7 @@
> >
<div <div
class="bg-green-600 h-2.5 rounded-full" class="bg-green-600 h-2.5 rounded-full"
data-cy="challenge-progress"
:style="{ :style="{
width: width:
(challenge.saved / challenge.target) * (challenge.saved / challenge.target) *
...@@ -83,6 +85,7 @@ ...@@ -83,6 +85,7 @@
<button <button
@click="incrementSaved(challenge)" @click="incrementSaved(challenge)"
:data-cy="'increment-challenge'+challenge.id"
type="button" type="button"
class="inline-block mb-2 ml-2 h-7 w-8 rounded-full p-1 uppercase leading-normal transition duration-150 ease-in-out focus:bg-green-accent-300 focus:shadow-green-2 focus:outline-none focus:ring-0 active:bg-green-600 active:shadow-green-200 motion-reduce:transition-none dark:shadow-black/30 dark:hover:shadow-dark-strong dark:focus:shadow-dark-strong dark:active:shadow-dark-strong" class="inline-block mb-2 ml-2 h-7 w-8 rounded-full p-1 uppercase leading-normal transition duration-150 ease-in-out focus:bg-green-accent-300 focus:shadow-green-2 focus:outline-none focus:ring-0 active:bg-green-600 active:shadow-green-200 motion-reduce:transition-none dark:shadow-black/30 dark:hover:shadow-dark-strong dark:focus:shadow-dark-strong dark:active:shadow-dark-strong"
> >
...@@ -194,29 +197,38 @@ import anime from 'animejs' ...@@ -194,29 +197,38 @@ import anime from 'animejs'
import type { Challenge } from '@/types/challenge' import type { Challenge } from '@/types/challenge'
import type { Goal } from '@/types/goal' import type { Goal } from '@/types/goal'
import confetti from 'canvas-confetti' import confetti from 'canvas-confetti'
import { useGoalStore } from '@/stores/goalStore'
import { useChallengeStore } from '@/stores/challengeStore'
import {useRouter} from "vue-router"; import {useRouter} from "vue-router";
import {useGoalStore} from "@/stores/goalStore";
import {useChallengeStore} from "@/stores/challengeStore";
const router = useRouter() const router = useRouter()
const goalStore = useGoalStore() const goalStore = useGoalStore()
const challengeStore = useChallengeStore() const challengeStore = useChallengeStore()
const challenges = ref<Challenge[]>([]) interface Props {
const goals = ref<Goal[]>([]) challenges: Challenge[]
goal: Goal | null | undefined
}
const props = defineProps<Props>()
const goal = ref<Goal | null | undefined>(null)
onMounted(async () => { const challenges = ref<Challenge[]>(props.challenges)
await goalStore.getUserGoals() const goal = ref<Goal | null | undefined>(props.goal)
await challengeStore.getUserChallenges()
challenges.value = challengeStore.challenges
goals.value = goalStore.goals
goal.value = goals.value[0]
console.log('Goals:', goals.value)
})
// Utilizing watch to specifically monitor for changes in the props
watch(() => props.goal, (newGoal, oldGoal) => {
if (newGoal !== oldGoal) {
goal.value = newGoal;
console.log('Updated goal:', goal.value);
}
}, { immediate: true });
watch(() => props.challenges, (newChallenges, oldChallenges) => {
if (newChallenges !== oldChallenges) {
challenges.value = newChallenges;
console.log('Updated challenges:', challenges.value);
}
}, { immediate: true });
// Reactive references for DOM elements // Reactive references for DOM elements
const iconRef = ref<HTMLElement | null>(null) const iconRef = ref<HTMLElement | null>(null)
const containerRef = ref<HTMLElement | null>(null) const containerRef = ref<HTMLElement | null>(null)
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<ButtonAddGoalOrChallenge :buttonText="'Legg til spareutfordring'" :type="'challenge'" /> <ButtonAddGoalOrChallenge :buttonText="'Legg til spareutfordring'" :type="'challenge'" />
</div> </div>
</div> </div>
<savings-path></savings-path> <savings-path :challenges="challenges" :goal="goal"></savings-path>
</div> </div>
</template> </template>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment