A self-hosted media server and file management system
Vue ffmpegfile-serverjellyfinlaravelmediamedia-playermedia-servermediabrowsermediaservermusicmusic-librarymusic-playermusicplayerself-hostedvuejs
feat: add folder info tags to spotlightand individual links
aminnausinca26268d61e8
diff --git a/resources/js/components/home/HomeSpotlight.vue b/resources/js/components/home/HomeSpotlight.vueindex a8c2ad14..99e59b6f 100644--- a/resources/js/components/home/HomeSpotlight.vue+++ b/resources/js/components/home/HomeSpotlight.vue@@ -3,8 +3,8 @@ import type { SwipeDirection } from '@aminnausin/cedar-ui';import type { SpotlightItem } from '@/service/home/useSpotlightItems';import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';+import { handleStorageURL, toPlural } from '@/service/util';import { cn, useSwipeHandler } from '@aminnausin/cedar-ui';-import { handleStorageURL } from '@/service/util';import { ButtonBase } from '@/components/cedar-ui/button';import ButtonOverlay from '@/components/buttons/ButtonOverlay.vue';@@ -15,20 +15,22 @@ import ProiconsInfoSquare from '~icons/proicons/info-square';import ProiconsPlay from '~icons/proicons/play';import IconPause from '@/components/icons/IconPause.vue';-const props = withDefaults(defineProps<{ items: SpotlightItem[]; intervalMs?: number; isLoading?: boolean }>(), { intervalMs: 6000 });-let timer: ReturnType<typeof setTimeout> | null = null;-let startedAt = 0;-let remaining = props.intervalMs;++const props = withDefaults(defineProps<{ items: SpotlightItem[]; intervalMs?: number; isLoading?: boolean }>(), { intervalMs: 6000 });++let remainingTime = props.intervalMs;const activeIndex = ref(0);-const isPaused = ref(false);+const activeFolder = computed(() => activeItem.value?.folder ?? null);+const activeItem = computed(() => props.items[activeIndex.value] ?? null);++const activeUrl = computed(() => (activeFolder.value ? `/${activeFolder.value.category_id}/${activeFolder.value.id}/details` : '/'));+const hasMounted = ref(false);const hasPaused = ref(false);--const activeItem = computed(() => props.items[activeIndex.value] ?? null);-const activeFolder = computed(() => activeItem.value?.folder ?? null);+const isPaused = ref(false);const bannerSrc = computed(() =>@@ -38,25 +40,36 @@ const bannerSrc = computed('/storage/thumbnails/default.webp',);-const activeUrl = computed(() => (activeFolder.value ? `/${activeFolder.value.category_id}/${activeFolder.value.id}/details` : '/'));+const folderInfoTags = computed(() => {+ if (!activeFolder.value) return [];++ const getCount = (title: string, value: number = activeFolder.value.file_count) => `${value} ${title}${toPlural(value)}`;++ if (!activeFolder.value.series?.seasons) return [getCount('File')];+ if (activeFolder.value.is_majority_audio) return [getCount('Track')];++ const tags = [getCount('Episode', activeFolder.value.series.episodes)];++ if (activeFolder.value.series.seasons > 1) {+ tags.push(getCount('Season', activeFolder.value.series.seasons));+ }++ return tags;+});const swipeDirections = ref<SwipeDirection[]>(['left', 'right']);const leaveDirection = ref<string>();-const leaveOffset = ref(0);-const leavingId = ref<number | null>(null);const { offset, isSwiping, onPointerDown, onPointerMove, onPointerUp } = useSwipeHandler({directions: swipeDirections,swipeThreshold: { px: 45 },- onSwipeOut: onClose,+ onSwipeOut,});-function onClose() {+function onSwipeOut() {if (Math.abs(offset.value.x) < 45) return;- leavingId.value = activeFolder.value?.id ?? null;leaveDirection.value = offset.value.x > 0 ? '100%' : '-100%';- leaveOffset.value = offset.value.x;(offset.value.x > 0 ? nextFolder : previousFolder)();}@@ -70,49 +83,49 @@ const previousFolder = () => {activeIndex.value = activeIndex.value === 0 ? props.items.length - 1 : (activeIndex.value - 1) % props.items.length;};-function start() {+function startTimer() {if (timer || isPaused.value || props.items.length <= 1) return;startedAt = performance.now();timer = setTimeout(() => {- remaining = props.intervalMs;+ remainingTime = props.intervalMs;nextFolder();- }, remaining);+ }, remainingTime);}-function pause() {+function pauseTimer() {if (!timer) return;clearTimeout(timer);timer = null;- remaining -= performance.now() - startedAt;+ remainingTime -= performance.now() - startedAt;}-function reset() {- remaining = props.intervalMs;+function resetTimer() {+ remainingTime = props.intervalMs;if (timer) {clearTimeout(timer);timer = null;}- start();+ startTimer();}const goTo = (index: number) => {activeIndex.value = index;};-watch(isPaused, (paused) => (paused ? pause() : start()));+watch(isPaused, (paused) => (paused ? pauseTimer() : startTimer()));watch([activeIndex, () => props.items.length], () => {- if (hasMounted.value) reset();+ if (hasMounted.value) resetTimer();});onMounted(() => {hasMounted.value = true;- reset();+ resetTimer();});onBeforeUnmount(() => timer && clearTimeout(timer));</script>@@ -155,65 +168,56 @@ onBeforeUnmount(() => timer && clearTimeout(timer));<div :class="cn('size-full bg-linear-to-b from-transparent to-neutral-950/40 text-white', '@container relative flex p-3')"><div class="flex w-full flex-1 flex-col items-center justify-center gap-x-4 gap-y-2 @md:flex-row @md:items-end @lg:flex-nowrap @lg:gap-x-12">- <div :class="cn('swipe group/spotlight-link relative flex w-full flex-1 @md:w-auto')" :style="{ '--offset-x': `${0}px` }" :data-swiping="isSwiping">+ <div :class="cn('swipe relative flex w-full flex-1 @md:w-auto')" :style="{ '--offset-x': `${0}px` }" :data-swiping="isSwiping"><Transition:name="hasMounted ? 'banner-fade' : ''"- @after-leave="- () => {- leaveDirection = '0%';- leaveOffset = 0;- }- "- @before-leave="- (el) => {- console.log(leaveOffset);-- (el as HTMLElement).style.setProperty('--leave-direction', leaveDirection ?? '0%');- // (el as HTMLElement).style.setProperty('--offset-x', `30%`);-- // console.log((el as HTMLElement).style.getPropertyValue('--offset-x'));- }- "+ @after-leave="leaveDirection = '0%'"+ @before-leave="(el) => (el as HTMLElement).style.setProperty('--leave-direction', leaveDirection ?? '0%')"><div- :title="activeFolder.name":key="activeFolder?.id":style="{ '--leave-direction': leaveDirection }"class="flex size-full flex-col items-center justify-end gap-3 @md:flex-row @md:items-end @md:justify-start">- <LazyImage- alt="poster"- :class="cn('aspect-2-3 w-full rounded-md object-cover transition-[zoom] group-hover/spotlight-link:zoom-110')"- :src="activeFolder?.series?.poster_image?.path ?? handleStorageURL(activeFolder?.series?.thumbnail_url) ?? '/storage/thumbnails/default.webp'"- :wrapper-class="cn('shrink-0 shadow-sm relative', 'w-32 sm:w-24 2xl:w-30 3xl:w-36 opacity-100 ease-in h-fit select-none ')"- />-- <div class="flex flex-col gap-0.5 text-center @md:text-start">+ <RouterLink :to="activeUrl" class="peer" title="View folder details">+ <LazyImage+ :alt="`${activeFolder.title} poster`"+ :class="cn('aspect-2-3 duration-input w-full rounded-lg object-cover shadow-sm transition-shadow')"+ :src="activeFolder?.series?.poster_image?.path ?? handleStorageURL(activeFolder?.series?.thumbnail_url) ?? '/storage/thumbnails/default.webp'"+ :wrapper-class="cn('shrink-0 relative', 'w-32 sm:w-24 2xl:w-30 3xl:w-36 opacity-100 ease-in h-fit select-none ')"+ />+ </RouterLink>++ <RouterLink+ :aria-label="`View folder details for ${activeFolder.title}`"+ class="group/spotlight-link flex flex-col gap-0.5 text-center @md:text-start peer-hover:[&_h1]:underline"+ :to="activeUrl"+ ><span class="text-xs tracking-wide whitespace-nowrap uppercase">{{ activeItem.label }}</span>- <RouterLink :to="activeUrl">- <h1 class="line-clamp-2 text-xl font-semibold text-balance capitalize hover:underline md:text-2xl">- {{ activeFolder?.title }}- </h1>- </RouterLink>+ <h1 class="line-clamp-2 text-xl font-semibold text-balance capitalize group-hover/spotlight-link:underline md:text-2xl">+ {{ activeFolder?.title }}+ </h1><p v-if="activeFolder?.series?.description" class="xs:line-clamp-1 hidden max-w-xl text-sm text-pretty sm:line-clamp-2">{{ activeFolder.series.description }}</p>- <div- class="@md:-mx-1: mt-1 flex h-5 w-full flex-wrap justify-center gap-1 overflow-clip [overflow-clip-margin:4px] @md:justify-start"- v-if="activeFolder.series?.folder_tags?.length"- >- <MediaTag- v-for="tag in activeFolder.series.folder_tags.slice(0, Math.min(4, activeFolder.series.folder_tags.length))"- :key="tag.id"- class="bg-surface-3! text-foreground-0! py-0.5 text-xs dark:bg-neutral-900!"- >- {{ tag.name }}+ <div class="@md:-mx-1: mt-1 flex h-5 w-full flex-wrap justify-center gap-1 overflow-clip [overflow-clip-margin:4px] @md:justify-start">+ <MediaTag v-for="tag in folderInfoTags" :key="tag" class="bg-surface-3! text-foreground-0! py-0.5 text-xs dark:bg-neutral-900!">+ {{ tag }}</MediaTag>+ <template v-if="activeFolder.series?.folder_tags?.length">+ <MediaTag+ v-for="tag in [...activeFolder.series.folder_tags.slice(0, Math.min(3, activeFolder.series.folder_tags.length))]"+ :key="tag.id"+ class="bg-surface-3! text-foreground-0! py-0.5 text-xs dark:bg-neutral-900!"+ >+ {{ tag.name }}+ </MediaTag>+ </template></div><div class="mt-1 hidden! h-8 @md:block"></div>- </div>+ </RouterLink></div></Transition></div>@@ -224,8 +228,7 @@ onBeforeUnmount(() => timer && clearTimeout(timer));type="button"class="group/spotlight-nav block h-3 flex-1 px-0.5 py-1":key="item.folder.id"- :title="`Show spotilight item ${index + 1}/${items.length}`"- :aria-label="`Show spotilight item ${index + 1}/${items.length}`"+ :title="`Show spotilight item ${index + 1} of ${items.length}`":aria-current="index === activeIndex ? 'true' : undefined"@click="goTo(index)">