designtopack/src/components/project/virtual-sample/DynamicView.vue

125 lines
3.1 KiB
Vue
Raw Normal View History

<template>
<div class="dialog__inner">
<header class="flex">
<div class="options-selector">
<button
v-for="(track, index) in tracks"
class="btn btn--image"
2024-12-17 15:08:03 +01:00
:aria-pressed="activeTracks.includes(track) ? true : false"
:aria-controls="track.slug"
2024-12-16 15:46:19 +01:00
:style="`--btn-image: url(${getFrontViewUrl(track)});`"
2024-12-17 15:08:03 +01:00
@click="selectTrack(track)"
>
<span>{{ track.title }}</span>
</button>
</div>
2024-12-17 15:08:03 +01:00
<button
class="btn | ml-auto"
:class="{ 'btn--secondary': isCompareModeEnabled }"
2024-12-17 15:08:03 +01:00
@click="isCompareModeEnabled = !isCompareModeEnabled"
>
2024-12-17 15:29:26 +01:00
<span>{{
isCompareModeEnabled
? "Quitter le mode comparer"
: "Comparer les pistes"
}}</span>
</button>
</header>
<div class="track">
2024-12-17 15:08:03 +01:00
<template v-for="activeTrack in activeTracks" :key="activeTrack.title">
<Interactive360
v-if="activeTrack.files.length > 1"
:activeTrack="activeTrack"
/>
<figure v-else>
<img :src="activeTrack.files[0].url" alt="" />
</figure>
</template>
2024-12-17 15:29:26 +01:00
<div
v-if="isCompareModeEnabled && activeTracks.length < 2"
class="track-empty | bg-white rounded-xl w-full p-32"
>
<p>Cliquez sur la piste que vous souhaitez comparer</p>
</div>
</div>
</div>
</template>
<script setup>
import { ref, computed, watch } from "vue";
import { storeToRefs } from "pinia";
import { usePageStore } from "../../../stores/page";
2024-12-16 15:46:19 +01:00
import Interactive360 from "./Interactive360.vue";
import { useDialogStore } from "../../../stores/dialog";
const { page } = storeToRefs(usePageStore());
const { isCommentsOpen, isCommentPanelEnabled } = storeToRefs(useDialogStore());
const tracks = computed(
() => page.value.steps[page.value.steps.length - 1].files.dynamic
);
2024-12-17 15:08:03 +01:00
const isCompareModeEnabled = ref(false);
watch(isCompareModeEnabled, (newValue) => {
if (newValue) {
isCommentsOpen.value = false;
isCommentPanelEnabled.value = false;
} else {
isCommentPanelEnabled.value = true;
}
2024-12-17 15:29:26 +01:00
if (!newValue && activeTracks.value.length === 2) {
activeTracks.value.pop();
}
});
2024-12-17 15:08:03 +01:00
const activeTracks = ref([tracks.value[0]]);
2024-12-16 15:46:19 +01:00
function getFrontViewUrl(track) {
if (track.files.length > 1) {
return track.files[7].url;
2024-12-16 15:29:54 +01:00
} else {
2024-12-16 15:46:19 +01:00
return track.files[0].url;
2024-12-16 15:29:54 +01:00
}
2024-12-16 15:46:19 +01:00
}
2024-12-17 15:08:03 +01:00
function selectTrack(track) {
2024-12-17 15:29:26 +01:00
if (!isCompareModeEnabled.value) {
activeTracks.value = [track];
return;
}
if (activeTracks.value.length === 1 && !activeTracks.value.includes(track)) {
activeTracks.value.push(track);
return;
}
if (activeTracks.value.length === 2) {
2024-12-17 15:08:03 +01:00
if (activeTracks.value.includes(track)) {
2024-12-17 15:29:26 +01:00
removeTrack(track);
2024-12-17 15:08:03 +01:00
} else {
2024-12-17 16:35:32 +01:00
activeTracks.value.pop();
2024-12-17 15:08:03 +01:00
activeTracks.value.push(track);
}
}
}
2024-12-17 15:29:26 +01:00
function removeTrack(track) {
activeTracks.value = activeTracks.value.filter(
(activeTrack) => activeTrack.title !== track.title
);
}
</script>
2024-12-16 15:29:54 +01:00
<style>
.track figure {
position: relative;
}
.track .drag-zone {
position: absolute;
inset: 0;
z-index: 2;
}
</style>