|
436 | 436 | :workout-media-attachments=" |
437 | 437 | workout?.media_attachments ? workout.media_attachments : [] |
438 | 438 | " |
| 439 | + :is-archive="isArchive" |
439 | 440 | /> |
440 | 441 | </div> |
441 | 442 | <ErrorMessage :message="errorMessages" v-if="errorMessages" /> |
|
516 | 517 |
|
517 | 518 | const { appConfig, errorMessages } = useApp() |
518 | 519 |
|
519 | | - let workoutFile: File | null = null |
| 520 | + const workoutFile: Ref<File | undefined> = ref(undefined) |
520 | 521 |
|
521 | 522 | const workoutForm = reactive({ |
522 | 523 | sport_id: '', |
|
573 | 574 | appConfig.value.file_sync_limit_import != |
574 | 575 | appConfig.value.file_limit_import |
575 | 576 | ) |
| 577 | + const isArchive: ComputedRef<boolean> = computed( |
| 578 | + () => |
| 579 | + isCreation.value && |
| 580 | + withFile.value && |
| 581 | + workoutFile.value !== undefined && |
| 582 | + workoutFile.value.name.endsWith('.zip') |
| 583 | + ) |
576 | 584 | const equipments: ComputedRef<IEquipment[]> = computed( |
577 | 585 | () => store.getters[EQUIPMENTS_STORE.GETTERS.EQUIPMENTS] |
578 | 586 | ) |
|
651 | 659 | } |
652 | 660 | function updateFile(event: Event) { |
653 | 661 | if ((event.target as HTMLInputElement).files) { |
654 | | - workoutFile = ((event.target as HTMLInputElement).files as FileList)[0] |
| 662 | + workoutFile.value = ( |
| 663 | + (event.target as HTMLInputElement).files as FileList |
| 664 | + )[0] |
655 | 665 | } |
656 | 666 | } |
657 | 667 | function formatWorkoutForm(workout: IWorkout) { |
|
775 | 785 | equipment_ids: workoutForm.equipment_ids, |
776 | 786 | title: workoutForm.title, |
777 | 787 | workout_visibility: workoutForm.workoutVisibility, |
778 | | - media_attachment_ids: mediaAttachementIds.value, |
| 788 | + media_attachment_ids: isArchive.value ? [] : mediaAttachementIds.value, |
779 | 789 | media_visibility: workoutForm.mediaVisibility, |
780 | 790 | } |
781 | 791 | if (props.workout.id) { |
|
798 | 808 | } |
799 | 809 | } else { |
800 | 810 | if (withFile.value) { |
801 | | - if (!workoutFile) { |
| 811 | + if (!workoutFile.value) { |
802 | 812 | const errorMessage = 'workouts.NO_FILE_PROVIDED' |
803 | 813 | store.commit(ROOT_STORE.MUTATIONS.SET_ERROR_MESSAGES, errorMessage) |
804 | 814 | return |
805 | 815 | } |
806 | | - payload.file = workoutFile |
| 816 | + payload.file = workoutFile.value |
807 | 817 | payload.analysis_visibility = workoutForm.analysisVisibility |
808 | 818 | payload.map_visibility = workoutForm.mapVisibility |
809 | 819 | store.dispatch(WORKOUTS_STORE.ACTIONS.ADD_WORKOUT, payload) |
|
858 | 868 | function updateSelectedEquipmentPieces(selectedIds: string[]) { |
859 | 869 | workoutForm.equipment_ids = selectedIds |
860 | 870 | } |
| 871 | +
|
861 | 872 | watch( |
862 | 873 | () => props.workout, |
863 | 874 | async ( |
|
898 | 909 | } |
899 | 910 | } |
900 | 911 | ) |
| 912 | + watch( |
| 913 | + () => withFile.value, |
| 914 | + async (newValue: boolean) => { |
| 915 | + if (!newValue) { |
| 916 | + workoutFile.value = undefined |
| 917 | + } |
| 918 | + } |
| 919 | + ) |
901 | 920 |
|
902 | 921 | onMounted(() => { |
903 | 922 | let element |
|
0 commit comments