2021-09-28 12:39:12 +02:00
|
|
|
<template>
|
|
|
|
<div id="edit-workout">
|
|
|
|
<div class="container">
|
2021-09-28 17:48:17 +02:00
|
|
|
<WorkoutEdition :sports="sports" :workout="workoutData.workout" />
|
2021-09-28 12:39:12 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import {
|
|
|
|
computed,
|
|
|
|
defineComponent,
|
|
|
|
watch,
|
|
|
|
onBeforeMount,
|
|
|
|
ComputedRef,
|
|
|
|
} from 'vue'
|
|
|
|
import { useRoute } from 'vue-router'
|
|
|
|
|
2021-09-28 17:48:17 +02:00
|
|
|
import WorkoutEdition from '@/components/Workout/WorkoutEdition.vue'
|
2021-09-28 12:39:12 +02:00
|
|
|
import { SPORTS_STORE, WORKOUTS_STORE } from '@/store/constants'
|
|
|
|
import { ISport } from '@/types/sports'
|
|
|
|
import { IWorkoutData } from '@/types/workouts'
|
|
|
|
import { useStore } from '@/use/useStore'
|
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
name: 'EditWorkout',
|
|
|
|
components: {
|
2021-09-28 17:48:17 +02:00
|
|
|
WorkoutEdition,
|
2021-09-28 12:39:12 +02:00
|
|
|
},
|
|
|
|
setup() {
|
|
|
|
const route = useRoute()
|
|
|
|
const store = useStore()
|
|
|
|
|
|
|
|
onBeforeMount(() => {
|
|
|
|
store.dispatch(WORKOUTS_STORE.ACTIONS.GET_WORKOUT_DATA, {
|
|
|
|
workoutId: route.params.workoutId,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
const sports: ComputedRef<ISport[]> = computed(
|
|
|
|
() => store.getters[SPORTS_STORE.GETTERS.SPORTS]
|
|
|
|
)
|
|
|
|
const workoutData: ComputedRef<IWorkoutData> = computed(
|
|
|
|
() => store.getters[WORKOUTS_STORE.GETTERS.WORKOUT_DATA]
|
|
|
|
)
|
|
|
|
|
|
|
|
watch(
|
|
|
|
() => route.params.workoutId,
|
|
|
|
async (newWorkoutId) => {
|
|
|
|
if (!newWorkoutId) {
|
|
|
|
store.commit(WORKOUTS_STORE.MUTATIONS.EMPTY_WORKOUT)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
return { sports, workoutData }
|
|
|
|
},
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
@import '~@/scss/base';
|
|
|
|
</style>
|