Skip to content

A self-hosted media server and file management system

feat: fade and interweave different spotlighted folders

aminnausin494e00aecb18
diff --git a/resources/js/components/home/HomeHeroCarousel.vue b/resources/js/components/home/HomeHeroCarousel.vue
deleted file mode 100644
index 10b7bc17..00000000
--- a/resources/js/components/home/HomeHeroCarousel.vue
+++ /dev/null
@@ -1,155 +0,0 @@
-<script setup lang="ts">
-import type { FolderResource } from '@/contracts/media';
-
-import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
-import { handleStorageURL } from '@/service/util';
-import { ButtonBase } from '@/components/cedar-ui/button';
-import { cn } from '@aminnausin/cedar-ui';
-
-import LazyImage from '@/components/lazy/LazyImage.vue';
-
-import CircumPlay1 from '~icons/circum/play-1';
-
-let timer: ReturnType<typeof setTimeout> | null = null;
-
-const props = withDefaults(defineProps<{ items: FolderResource[]; intervalMs?: number }>(), { intervalMs: 6000 });
-
-const activeIndex = ref(0);
-const isPaused = ref(false);
-
-const activeFolder = computed(() => props.items[activeIndex.value] ?? null);
-
-const bannerSrc = computed(
- () =>
- activeFolder.value?.series?.banner_image?.path ??
- activeFolder.value?.series?.poster_image?.path ??
- handleStorageURL(activeFolder.value?.series?.thumbnail_url) ??
- '/storage/thumbnails/default.webp',
-);
-
-const activeUrl = computed(() => (activeFolder.value ? `/${activeFolder.value.category_id}/${activeFolder.value.id}/details` : '/'));
-
-const nextFolder = () => {
- if (!props.items.length) return;
- activeIndex.value = (activeIndex.value + 1) % props.items.length;
-};
-
-const restart = () => {
- if (timer) clearTimeout(timer);
- if (isPaused.value || props.items.length <= 1) return;
- timer = setTimeout(nextFolder, props.intervalMs);
-};
-
-const goTo = (index: number) => {
- activeIndex.value = index;
-};
-
-watch(activeIndex, restart);
-watch(isPaused, restart);
-
-onMounted(restart);
-onBeforeUnmount(() => timer && clearTimeout(timer));
-</script>
-
-<template>
- <RouterLink
- :to="activeUrl"
- :class="
- cn(
- 'ring-r-default/5 group relative block h-[clamp(200px,28vw,380px)] w-full overflow-hidden rounded-xl text-white ring-1',
- 'content-auto [contain-intrinsic-size:auto_300px]',
- )
- "
- @mouseenter="isPaused = true"
- @mouseleave="isPaused = false"
- >
- <div class="absolute inset-0">
- <TransitionGroup name="banner-fade">
- <LazyImage
- v-for="folder in [activeFolder]"
- :key="folder?.id"
- :src="bannerSrc"
- :alt="folder?.title"
- class="absolute inset-0 size-full object-cover"
- loading="eager"
- decoding="async"
- />
- </TransitionGroup>
- </div>
-
- <div class="absolute inset-0 flex w-full items-end gap-4 bg-linear-to-b from-transparent to-neutral-950/40 p-3 text-white">
- <div :class="cn('flex flex-1 items-end gap-4 transition-[gap] duration-300 ease-in', { 'gap-0 ease-out': !activeFolder.series?.banner_image?.path })">
- <LazyImage
- alt="poster"
- :class="cn('aspect-2-3 w-full max-w-24 rounded-md object-cover')"
- :src="activeFolder?.series?.poster_image?.path ?? handleStorageURL(activeFolder?.series?.thumbnail_url) ?? '/storage/thumbnails/default.webp'"
- :wrapper-class="
- cn(
- 'relative overflow-hidden transition-[width,height,margin, opacity] duration-300 ease-out origin-bottom-left shrink-0',
- activeFolder?.series?.banner_image?.path ? 'w-24 h-36 opacity-100 ease-in' : 'w-0 h-0 opacity-0',
- )
- "
- />
-
- <div class="flex flex-col gap-2">
- <span class="text-xs tracking-wide uppercase">New series</span>
- <h1 class="text-xl font-semibold md:text-2xl">{{ activeFolder?.title }}</h1>
- <p v-if="activeFolder?.series?.description" class="hidden max-w-xl text-sm sm:line-clamp-2">
- {{ activeFolder.series.description }}
- </p>
- <!-- <ButtonBase class="text-foreground-0 dark:text-foreground-i mt-1 w-fit gap-2 bg-white"> <CircumPlay1 class="size-4" /> View </ButtonBase> -->
- </div>
- </div>
- <div v-if="items.length > 1" class="pointer-events-none ms-auto flex max-w-64 flex-1 items-center">
- <ButtonBase
- v-for="(item, index) in items"
- :key="item.id"
- type="button"
- class="pointer-events-auto block h-3 flex-1 px-0.5 py-1"
- :aria-label="`Show ${item.title}`"
- @click.prevent="goTo(index)"
- >
- <div class="h-1 overflow-hidden rounded-full bg-white/25">
- <div
- :class="
- cn('bg-primary h-full', {
- 'w-full': index < activeIndex,
- 'w-0': index > activeIndex,
- 'hero-fill': index === activeIndex,
- })
- "
- :style="index === activeIndex ? { animationDuration: `${intervalMs}ms`, animationPlayState: isPaused ? 'paused' : 'running' } : undefined"
- />
- </div>
- </ButtonBase>
- </div>
- </div>
- </RouterLink>
-</template>
-<style lang="css" scoped>
-.banner-fade-enter-active {
- transition: opacity 0.4s ease;
-}
-.banner-fade-enter-from {
- opacity: 0;
-}
-.banner-fade-leave-active {
- position: absolute;
- inset: 0;
-}
-
-.hero-fill {
- animation-name: fill;
- animation-timing-function: linear;
- animation-fill-mode: forwards;
-}
-
-@keyframes fill {
- from {
- width: 0%;
- }
- to {
- width: 100%;
- }
-}
-</style>
diff --git a/resources/js/components/home/HomeSpotlight.vue b/resources/js/components/home/HomeSpotlight.vue
new file mode 100644
index 00000000..99ba3ffa
--- /dev/null
+++ b/resources/js/components/home/HomeSpotlight.vue
@@ -0,0 +1,188 @@
+<script setup lang="ts">
+import type { FolderResource } from '@/contracts/media';
+import type { SpotlightItem } from '@/service/home/useSpotlightItems';
+
+import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue';
+import { handleStorageURL } from '@/service/util';
+import { ButtonBase } from '@/components/cedar-ui/button';
+import { cn } from '@aminnausin/cedar-ui';
+
+import PlayerOSDBase from '@/components/video/OSD/PlayerOSDBase.vue';
+import LazyImage from '@/components/lazy/LazyImage.vue';
+
+import ProiconsPlay from '~icons/proicons/play';
+import IconPause from '@/components/icons/IconPause.vue';
+
+const props = withDefaults(defineProps<{ items: SpotlightItem[]; intervalMs?: number }>(), { intervalMs: 6000 });
+
+let timer: ReturnType<typeof setTimeout> | null = null;
+
+let startedAt = 0;
+let remaining = props.intervalMs;
+
+const activeIndex = ref(0);
+const isPaused = ref(false);
+
+const activeItem = computed(() => props.items[activeIndex.value] ?? null);
+const activeFolder = computed(() => activeItem.value?.folder ?? null);
+
+const bannerSrc = computed(
+ () =>
+ activeFolder.value?.series?.banner_image?.path ??
+ activeFolder.value?.series?.poster_image?.path ??
+ handleStorageURL(activeFolder.value?.series?.thumbnail_url) ??
+ '/storage/thumbnails/default.webp',
+);
+
+const activeUrl = computed(() => (activeFolder.value ? `/${activeFolder.value.category_id}/${activeFolder.value.id}/details` : '/'));
+
+const nextFolder = () => {
+ if (!props.items.length) return;
+ activeIndex.value = (activeIndex.value + 1) % props.items.length;
+};
+
+function start() {
+ if (timer || isPaused.value || props.items.length <= 1) return;
+
+ startedAt = performance.now();
+
+ timer = setTimeout(() => {
+ remaining = props.intervalMs;
+ nextFolder();
+ }, remaining);
+}
+
+function pause() {
+ if (!timer) return;
+
+ clearTimeout(timer);
+ timer = null;
+
+ remaining -= performance.now() - startedAt;
+}
+
+function reset() {
+ remaining = props.intervalMs;
+
+ if (timer) {
+ clearTimeout(timer);
+ timer = null;
+ }
+
+ start();
+}
+
+const goTo = (index: number) => {
+ activeIndex.value = index;
+};
+
+watch(isPaused, (paused) => (paused ? pause() : start()));
+watch(activeIndex, reset);
+
+onMounted(start);
+
+onBeforeUnmount(() => timer && clearTimeout(timer));
+</script>
+
+<template>
+ <div
+ :class="cn('ring-r-default/5 group dark relative block h-[clamp(200px,28vw,380px)] max-h-64 w-full ring-1', 'content-auto rounded-xl [contain-intrinsic-size:auto_300px]')"
+ @mouseenter="isPaused = true"
+ @mouseleave="isPaused = false"
+ >
+ <Transition name="banner-fade">
+ <div :key="activeFolder?.id" class="absolute inset-0">
+ <LazyImage :src="bannerSrc" :alt="activeFolder?.title" class="size-full rounded-xl object-cover" loading="eager" decoding="async" />
+
+ <div :class="cn('absolute inset-0 bg-linear-to-b from-transparent to-neutral-950/40 p-3 text-white', '@container flex')">
+ <div class="mt-auto flex h-fit w-full flex-wrap items-end justify-center gap-x-12 gap-y-2 @lg:flex-nowrap">
+ <RouterLink :class="cn('mt-auto flex h-fit flex-1 items-end gap-4 hover:text-white/90')" :to="activeUrl">
+ <LazyImage
+ alt="poster"
+ :class="cn('aspect-2-3 w-full max-w-24 rounded-md object-cover')"
+ :src="activeFolder?.series?.poster_image?.path ?? handleStorageURL(activeFolder?.series?.thumbnail_url) ?? '/storage/thumbnails/default.webp'"
+ :wrapper-class="cn('relative overflow-hidden origin-bottom-left shrink-0', 'w-16 @lg:w-24 opacity-100 ease-in')"
+ />
+
+ <div class="flex flex-col gap-0.5">
+ <span class="text-xs tracking-wide uppercase">{{ activeItem.label }}</span>
+ <h1 class="text-xl font-semibold capitalize md:text-2xl">{{ activeFolder?.title }}</h1>
+ <p v-if="activeFolder?.series?.description" class="hidden max-w-xl text-sm sm:line-clamp-2">
+ {{ activeFolder.series.description }}
+ </p>
+ </div>
+ </RouterLink>
+ <div v-if="items.length > 1" class="flex h-fit max-w-52 min-w-40 flex-1 items-center">
+ <ButtonBase
+ v-for="(item, index) in items"
+ :key="item.folder.id"
+ type="button"
+ class="group/spotlight-nav block h-3 flex-1 px-0.5 py-1"
+ :aria-label="`Show ${item.folder.title}`"
+ @click="goTo(index)"
+ >
+ <div class="duration-input h-1 overflow-hidden rounded-full bg-white/25 transition-colors group-hover/spotlight-nav:bg-white/50">
+ <div
+ :class="
+ cn('bg-primary group-hover/spotlight-nav:bg-primary-active h-full origin-left shadow', {
+ 'w-full': index < activeIndex,
+ 'w-0': index > activeIndex,
+ 'hero-fill': index === activeIndex,
+ })
+ "
+ :style="index === activeIndex ? { animationDuration: `${intervalMs}ms`, animationPlayState: isPaused ? 'paused' : 'running' } : undefined"
+ />
+ </div>
+ </ButtonBase>
+ </div>
+ </div>
+ </div>
+ </div>
+ </Transition>
+
+ <div class="absolute top-0 right-0 flex gap-1 p-3">
+ <PlayerOSDBase
+ :class="
+ cn('pointer-events-auto p-1 opacity-0 transition-opacity duration-300 ease-in', {
+ 'opacity-100 duration-150 ease-out': isPaused,
+ })
+ "
+ >
+ <ProiconsPlay v-if="isPaused" class="size-5" />
+ <IconPause v-else class="size-5" />
+ </PlayerOSDBase>
+ </div>
+ </div>
+</template>
+<style lang="css" scoped>
+* {
+ --banner-fade-duration: 0.7s;
+}
+
+.banner-fade-enter-active,
+.banner-fade-leave-active {
+ position: absolute;
+ inset: 0;
+ transition: opacity var(--banner-fade-duration) ease;
+}
+
+.banner-fade-enter-from,
+.banner-fade-leave-to {
+ opacity: 0;
+}
+
+.hero-fill {
+ animation-name: fill;
+ animation-timing-function: linear;
+ animation-fill-mode: forwards;
+}
+
+@keyframes fill {
+ 0% {
+ transform: scaleX(0);
+ }
+ 100% {
+ transform: scaleX(1);
+ }
+}
+</style>
diff --git a/resources/js/service/home/useSpotlightItems.ts b/resources/js/service/home/useSpotlightItems.ts
new file mode 100644
index 00000000..4bf8e0de
--- /dev/null
+++ b/resources/js/service/home/useSpotlightItems.ts
@@ -0,0 +1,22 @@
+import type { FolderResource } from '@/contracts/media';
+
+export type SpotlightItem = { folder: FolderResource; label: string };
+
+export function interleaveSpotlightItems(groups: { items: FolderResource[]; label: string }[], perGroup = 4): SpotlightItem[] {
+ const seen = new Set<number>();
+
+ const queues = groups.map(({ items, label }) => {
+ const windowed = items.slice(0, perGroup);
+ const deduped = windowed.filter((f) => (seen.has(f.id) ? false : (seen.add(f.id), true)));
+ return { label, items: deduped };
+ });
+
+ const result: SpotlightItem[] = [];
+ const maxLen = Math.max(...queues.map((q) => q.items.length));
+
+ for (let i = 0; i < maxLen; i++) {
+ for (const q of queues) if (q.items[i]) result.push({ folder: q.items[i], label: q.label });
+ }
+
+ return result;
+}
diff --git a/resources/js/views/HomeView.vue b/resources/js/views/HomeView.vue
index 6f4b602d..b120442a 100644
--- a/resources/js/views/HomeView.vue
+++ b/resources/js/views/HomeView.vue
@@ -2,6 +2,7 @@
import { useContinueWatching, useRecentlyAdded, useRecentlyReleased, useRecentlyUpdated, useRecentlyUploaded } from '@/service/home/useHomeQueries';
import { breakpointsTailwind, useBreakpoints } from '@vueuse/core';
import { toFormattedDate, toTimeSpan } from '@/service/util';
+import { interleaveSpotlightItems } from '@/service/home/useSpotlightItems';
import { computed, onMounted } from 'vue';
import { useAppStore } from '@/stores/AppStore';
import { storeToRefs } from 'pinia';
@@ -11,10 +12,10 @@ import LayoutBase from '@/layouts/LayoutBase.vue';
import RecentlyUploadedCard from '@/components/cards/data/RecentlyUploadedCard.vue';
import RecentlyWatchedCard from '@/components/cards/data/RecentlyWatchedCard.vue';
import BrowseFolderCard from '@/components/cards/data/BrowseFolderCard.vue';
-import HomeHeroCarousel from '@/components/home/HomeHeroCarousel.vue';
+import HomeSpotlight from '@/components/home/HomeSpotlight.vue';
import HomeShelf from '@/components/home/HomeShelf.vue';
-const { pageTitle, selectedSideBar } = storeToRefs(useAppStore());
+const { pageTitle } = storeToRefs(useAppStore());
const { data: recentlyUploadedMusic, isLoading: isLoadingRecentlyUploadedMusic } = useRecentlyUploaded('audio');
const { data: recentlyUploaded, isLoading: isLoadingRecentlyUploaded } = useRecentlyUploaded('video');
@@ -32,9 +33,19 @@ const gridFolderCount = computed(() => {
return 3;
});
+const spotlightItems = computed(() =>
+ interleaveSpotlightItems(
+ [
+ { items: recentlyUpdated.value ?? [], label: 'Just Updated' },
+ { items: recentlyAdded.value ?? [], label: 'Just Added' },
+ { items: recentlyReleased.value ?? [], label: 'Just Released' },
+ ],
+ 4,
+ ),
+);
+
onMounted(() => {
pageTitle.value = 'Explore';
- selectedSideBar.value = '';
});
</script>
@@ -42,7 +53,7 @@ onMounted(() => {
<LayoutBase>
<template #content>
<div id="content-home" class="page-height @container flex flex-col gap-8 text-sm">
- <HomeHeroCarousel v-if="recentlyAdded?.length" :items="recentlyAdded.slice(0, 5)" />
+ <HomeSpotlight v-if="spotlightItems.length" :items="spotlightItems" />
<HomeShelf
v-if="isLoadingContinueWatching || !!continueWatching?.length"