|
| 1 | +<template> |
| 2 | + <div |
| 3 | + :class="{ |
| 4 | + 'absolute flex flex-col text-muted-color text-right top-0 h-full overflow-y-scroll no-scrollbar': true, |
| 5 | + 'right-6': !isTouch, |
| 6 | + 'right-2': isTouch, |
| 7 | + 'bg-gradient-to-l from-(--p-surface-0) pt-14 dark:from-(--p-surface-900) text-shadow-sm group pb-24': true, |
| 8 | + }" |
| 9 | + @mouseleave="scrollToView" |
| 10 | + > |
| 11 | + <div v-for="yearChunk in dates" :key="yearChunk.header" class=""> |
| 12 | + <span |
| 13 | + :class="{ |
| 14 | + 'sticky inline-block top-0 font-semibold z-10 shadow-surface-950 drop-shadow-md text-3xl scale-75 text-muted-color-emphasis': true, |
| 15 | + 'group-hover:scale-100 transition-all duration-150 origin-right': true, |
| 16 | + 'scale-100': currentYear === parseInt(yearChunk.header, 10), |
| 17 | + }" |
| 18 | + > |
| 19 | + {{ yearChunk.header }} |
| 20 | + </span> |
| 21 | + <!-- We only apply the hover property for items bellow the current scrolling year, |
| 22 | + this avoids the upper part of the element to scroll up and down and some jerky behaviours. --> |
| 23 | + <div :class="{ 'date-wrapper group-hover:grid-rows-[1]': currentYear > parseInt(yearChunk.header, 10) }"> |
| 24 | + <div class="overflow-hidden flex flex-col"> |
| 25 | + <span |
| 26 | + v-for="monthChunk in yearChunk.data" |
| 27 | + :key="monthChunk.time_date" |
| 28 | + :data-date-pointer="monthChunk.time_date" |
| 29 | + :class="{ |
| 30 | + 'cursor-pointer transition-all duration-150 scale-75 ease-in-out origin-right': true, |
| 31 | + 'hover:text-primary-emphasis hover:font-bold hover:scale-100': !isTouch, |
| 32 | + 'scale-110 text-primary-emphasis font-bold': currentDate === monthChunk.time_date, |
| 33 | + }" |
| 34 | + @click="emits('load', monthChunk.time_date)" |
| 35 | + >{{ monthChunk.format }} |
| 36 | + </span> |
| 37 | + </div> |
| 38 | + </div> |
| 39 | + </div> |
| 40 | + </div> |
| 41 | +</template> |
| 42 | +<script setup lang="ts"> |
| 43 | +import { useSplitter } from "@/composables/album/splitter"; |
| 44 | +import { isTouchDevice } from "@/utils/keybindings-utils"; |
| 45 | +import { useDebounceFn } from "@vueuse/core"; |
| 46 | +import { ref } from "vue"; |
| 47 | +import { onMounted } from "vue"; |
| 48 | +import { watch } from "vue"; |
| 49 | +import { computed } from "vue"; |
| 50 | +import { useRoute } from "vue-router"; |
| 51 | +
|
| 52 | +const route = useRoute(); |
| 53 | +const props = defineProps<{ |
| 54 | + dates: App.Http.Resources.Models.Utils.TimelineData[]; |
| 55 | +}>(); |
| 56 | +
|
| 57 | +const { spliter } = useSplitter(); |
| 58 | +
|
| 59 | +const dates = computed(() => { |
| 60 | + return spliter( |
| 61 | + props.dates, |
| 62 | + (d) => d.time_date.split("-")[0], |
| 63 | + (d) => d.time_date.split("-")[0], |
| 64 | + ); |
| 65 | +}); |
| 66 | +
|
| 67 | +const currentDate = computed(() => (route.params.date as string | undefined) ?? ""); |
| 68 | +const currentYear = computed(() => parseInt(currentDate.value.split("-")[0], 10)); |
| 69 | +
|
| 70 | +const isTouch = ref(isTouchDevice()); |
| 71 | +
|
| 72 | +const emits = defineEmits<{ |
| 73 | + load: [date: string]; |
| 74 | +}>(); |
| 75 | +
|
| 76 | +// Scroll magic side |
| 77 | +// Select the current date and center it in the view |
| 78 | +const scrollToView = useDebounceFn(() => { |
| 79 | + if (!currentDate.value) { |
| 80 | + return; |
| 81 | + } |
| 82 | +
|
| 83 | + const el = document.querySelector(`[data-date-pointer="${currentDate.value}"]`); |
| 84 | + if (el) { |
| 85 | + el.scrollIntoView({ behavior: "smooth", block: "center" }); |
| 86 | + } |
| 87 | +}, 100); |
| 88 | +
|
| 89 | +// If the date change, we update! |
| 90 | +watch(() => route.params.date, scrollToView, { immediate: true }); |
| 91 | +
|
| 92 | +// Also do that at when loading the component |
| 93 | +onMounted(() => |
| 94 | + // But wait! if we do it too early the dom is not rendered and this does not work. |
| 95 | + // Let's wait 500ms for the rendering, then select the element. |
| 96 | + setTimeout(scrollToView, 500), |
| 97 | +); |
| 98 | +</script> |
| 99 | +<style> |
| 100 | +.date-wrapper { |
| 101 | + display: grid; |
| 102 | + grid-template-rows: 0fr; |
| 103 | + transition: grid-template-rows 0.25s ease-out; |
| 104 | +
|
| 105 | + &:is(:where(.group):hover *) { |
| 106 | + grid-template-rows: 1fr; |
| 107 | + } |
| 108 | +} |
| 109 | +</style> |
0 commit comments