select : load first image

This commit is contained in:
isUnknown 2025-06-11 14:45:11 +02:00
parent c187bf3aaa
commit 2100021e7b
2 changed files with 22 additions and 4 deletions

View file

@ -52,25 +52,38 @@
</template> </template>
<script setup> <script setup>
import { ref, watch } from 'vue'; import { onBeforeMount, ref, watch } from 'vue';
import { storeToRefs } from 'pinia'; import { storeToRefs } from 'pinia';
import { useDialogStore } from '../stores/dialog'; import { useDialogStore } from '../stores/dialog';
const { items, label, isCompareModeEnabled } = defineProps({ // Props
const { items, label, isCompareModeEnabled, index } = defineProps({
label: String, label: String,
items: Array, items: Array,
isCompareModeEnabled: { isCompareModeEnabled: {
type: Boolean, type: Boolean,
default: false, default: false,
}, },
index: Number,
}); });
// Emitters
const emit = defineEmits(['update:selectedItems']); const emit = defineEmits(['update:selectedItems']);
// Variables
const currentValue = ref(null); const currentValue = ref(null);
// Stores
const { activeTracks } = storeToRefs(useDialogStore()); const { activeTracks } = storeToRefs(useDialogStore());
// Hooks
onBeforeMount(() => {
if (index === 0) {
currentValue.value = items[0];
}
});
// Watchers
watch( watch(
() => isCompareModeEnabled, () => isCompareModeEnabled,
(newValue) => { (newValue) => {
@ -94,6 +107,7 @@ watch(activeTracks, (newValue) => {
} }
}); });
// Functions
function changeCurrent(item) { function changeCurrent(item) {
emit('update:selectedItems', item); emit('update:selectedItems', item);
} }

View file

@ -3,11 +3,12 @@
<header class="tracks-header | flex"> <header class="tracks-header | flex">
<div class="tracks"> <div class="tracks">
<Selector <Selector
v-for="track in tracks" v-for="(track, index) in tracks"
:key="track.slug" :key="track.slug"
:label="track.title" :label="track.title"
:items="track.variations" :items="track.variations"
:isCompareModeEnabled="isCompareModeEnabled" :isCompareModeEnabled="isCompareModeEnabled"
:index="index"
@update:selectedItems="selectTrack" @update:selectedItems="selectTrack"
/> />
</div> </div>
@ -67,8 +68,11 @@ const rawTracks = page.value.steps.find(
).files.dynamic; ).files.dynamic;
onBeforeMount(() => { onBeforeMount(() => {
activeTracks.value = [rawTracks[Object.keys(rawTracks)[0]][0]]; const firstTrack = rawTracks[Object.keys(rawTracks)[0]];
const firstVariation = firstTrack[0];
activeTracks.value = [firstVariation];
// TO RE-ENABLE
// if (route.hash.length > 0) { // if (route.hash.length > 0) {
// const trackToOpen = tracks.value.find( // const trackToOpen = tracks.value.find(
// (track) => track.slug === route.hash.substring(1) // (track) => track.slug === route.hash.substring(1)