57 lines
1.5 KiB
Vue
Raw Normal View History

2021-09-28 12:39:12 +02:00
<template>
2021-11-03 09:10:23 +01:00
<div id="edit-workout" class="view">
2021-09-28 12:39:12 +02:00
<div class="container">
2021-09-29 11:32:05 +02:00
<WorkoutEdition
:authUser="authUser"
:sports="sports"
:workout="workoutData.workout"
:loading="workoutData.loading"
/>
2021-09-28 12:39:12 +02:00
</div>
</div>
</template>
<script setup lang="ts">
import { computed, watch, onBeforeMount, ComputedRef } from 'vue'
2021-09-28 12:39:12 +02:00
import { useRoute } from 'vue-router'
2021-09-28 17:48:17 +02:00
import WorkoutEdition from '@/components/Workout/WorkoutEdition.vue'
import {
AUTH_USER_STORE,
SPORTS_STORE,
WORKOUTS_STORE,
} from '@/store/constants'
2021-09-28 12:39:12 +02:00
import { ISport } from '@/types/sports'
2021-10-30 12:01:55 +02:00
import { IUserProfile } from '@/types/user'
2021-09-28 12:39:12 +02:00
import { IWorkoutData } from '@/types/workouts'
import { useStore } from '@/use/useStore'
const route = useRoute()
const store = useStore()
2021-09-28 12:39:12 +02:00
const authUser: ComputedRef<IUserProfile> = computed(
() => store.getters[AUTH_USER_STORE.GETTERS.AUTH_USER_PROFILE]
)
const sports: ComputedRef<ISport[]> = computed(
() => store.getters[SPORTS_STORE.GETTERS.SPORTS]
)
const workoutData: ComputedRef<IWorkoutData> = computed(
() => store.getters[WORKOUTS_STORE.GETTERS.WORKOUT_DATA]
)
2021-09-28 12:39:12 +02:00
onBeforeMount(() => {
store.dispatch(WORKOUTS_STORE.ACTIONS.GET_WORKOUT_DATA, {
workoutId: route.params.workoutId,
})
2021-09-28 12:39:12 +02:00
})
watch(
() => route.params.workoutId,
async (newWorkoutId) => {
if (!newWorkoutId) {
store.commit(WORKOUTS_STORE.MUTATIONS.EMPTY_WORKOUT)
}
}
)
2021-09-28 12:39:12 +02:00
</script>