A self-hosted media server and file management system
Vue ffmpegfile-serverjellyfinlaravelmediamedia-playermedia-servermediabrowsermediaservermusicmusic-librarymusic-playermusicplayerself-hostedvuejs
feat: home activity feed
aminnausin5076697a6cd1
diff --git a/resources/js/components/home/HomeActivityFeed.vue b/resources/js/components/home/HomeActivityFeed.vuenew file mode 100644index 00000000..499952cf--- /dev/null+++ b/resources/js/components/home/HomeActivityFeed.vue@@ -0,0 +1,106 @@+<script setup lang="ts">+import type { FolderResource, VideoResource } from '@/contracts/media';++import { groupActivityFeed, useActivityFeed } from '@/service/home/useActivityFeed';+import { TableLoadingSpinner } from '@/components/cedar-ui/table';+import { toPlural } from '@/service/util';+import { computed } from 'vue';+import { cn } from '@aminnausin/cedar-ui';++import SidebarHeader from '@/components/headers/SidebarHeader.vue';+import LazyImage from '@/components/lazy/LazyImage.vue';++import ProiconsMusicNote2 from '~icons/proicons/music-note-2';+import CircumPlay1 from '~icons/circum/play-1';+import IconFolder from '@/components/icons/IconFolder.vue';++const props = defineProps<{+ videos?: VideoResource[];+ music?: VideoResource[];+ updatedFolders?: FolderResource[];+ isLoading?: boolean;+}>();++const foldersRef = computed(() => props.updatedFolders);+const videosRef = computed(() => props.videos);+const musicRef = computed(() => props.music);++const feed = useActivityFeed(videosRef, musicRef, foldersRef, 12);+const groups = computed(() => groupActivityFeed(feed.value));++const typeIcon = (type: string) => (type === 'audio' ? ProiconsMusicNote2 : type === 'folder' ? IconFolder : CircumPlay1);+</script>++<template>+ <section class="flex flex-col gap-3">+ <SidebarHeader title="New content feed">+ <template #title> What's new </template>+ </SidebarHeader>++ <div v-if="isLoading" class="flex flex-col gap-1">+ <div v-for="n in 5" :key="n" class="flex h-20 animate-pulse items-center">+ <div class="h-20 w-22 shrink-0 rounded-l-md bg-neutral-300 dark:bg-neutral-950/80" />+ <div class="bg-surface-3 flex h-full flex-1 flex-col gap-1.5 rounded-r-md p-2">+ <div class="h-3 w-3/4 rounded-md bg-neutral-300 dark:bg-neutral-700/60" />+ <div class="h-3 w-1/3 rounded-md bg-neutral-200 dark:bg-neutral-700/40" />+ </div>+ </div>+ </div>++ <TableLoadingSpinner v-else-if="!feed.length" :is-loading="false" no-results-message="Nothing new yet" class="h-16 text-sm" />++ <div v-else v-for="group in groups" :key="group.label" class="flex flex-col gap-2">+ <div class="text-foreground-2 flex items-center justify-between gap-1 text-xs tracking-wide uppercase">+ <div>+ {{ group.label }}+ </div>++ <div>{{ group.items.length }} Update{{ toPlural(group.items.length) }}</div>+ </div>+ <RouterLink+ v-for="item in group.items"+ :key="item.id"+ :to="item.url"+ :class="cn('group flex items-center', 'hover:bg-surface-1 dark:hover:bg-surface-2 duration-input data-card h-16 rounded shadow-sm transition-colors')"+ >+ <div class="relative flex h-full w-22 shrink-0 items-center overflow-hidden rounded-l-sm">+ <template v-if="item.thumbnail">+ <div+ class="absolute inset-0 scale-120 blur-sm"+ :style="{+ backgroundImage: `url('${item.thumbnail}')`,+ backgroundPosition: 'center',+ backgroundSize: 'cover',+ backgroundRepeat: 'no-repeat',+ }"+ ></div>++ <LazyImage+ :src="item.thumbnail"+ :alt="item.title"+ wrapper-class="absolute inset-0 flex items-center justify-center z-1"+ :class="cn('aspect-video w-full object-cover', { 'aspect-square': item.type === 'audio' })"+ loading="lazy"+ />+ </template>+ <div v-else class="bg-surface-3 flex size-full items-center justify-center">+ <component :is="typeIcon(item.type)" class="text-foreground-2 size-3.5" />+ </div>+ <span+ v-if="item.isNew"+ class="bg-primary/40 group-hover:bg-primary/60 3xl:text-[10px] absolute top-1 left-1 z-2 rounded-full px-1.5 py-0.5 text-[8px] leading-none text-white transition-colors"+ >+ NEW+ </span>+ </div>+ <div class="flex h-full w-full items-center gap-3 overflow-hidden p-2 pe-3">+ <div class="flex h-full min-w-0 flex-1 flex-col justify-between">+ <p class="truncate text-sm">{{ item.title }}</p>+ <p class="text-foreground-2 mt-0.5 truncate text-xs">{{ item.subtitle }}</p>+ </div>+ <component :is="typeIcon(item.type)" class="text-foreground-2 group-hover:text-foreground-0 size-3.5 shrink-0 transition-colors" />+ </div>+ </RouterLink>+ </div>+ </section>+</template>diff --git a/resources/js/components/home/HomeSpotlight.vue b/resources/js/components/home/HomeSpotlight.vueindex 32f9c9d3..b718311b 100644--- a/resources/js/components/home/HomeSpotlight.vue+++ b/resources/js/components/home/HomeSpotlight.vue@@ -1,5 +1,4 @@<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';diff --git a/resources/js/components/panels/NavBar.vue b/resources/js/components/panels/NavBar.vueindex 4004ae43..876a0d30 100755--- a/resources/js/components/panels/NavBar.vue+++ b/resources/js/components/panels/NavBar.vue@@ -1,4 +1,6 @@<script setup lang="ts">+import type { Component } from 'vue';+import { breakpointsTailwind, useBreakpoints } from '@vueuse/core';import { useDropdownMenuItems } from '@/components/panels/DropdownMenuItems';import { RouterLink, useRoute } from 'vue-router';@@ -18,6 +20,7 @@ import SidebarDrawer from '@/components/drawers/SidebarDrawer.vue';import LazyImage from '@/components/lazy/LazyImage.vue';import MaterialSymbolsLightHistory from '~icons/material-symbols-light/history';+import ProiconsSparkle2 from '~icons/proicons/sparkle-2';import CircumMonitor from '~icons/circum/monitor';import ProiconsMenu from '~icons/proicons/menu';import IconFolder from '@/components/icons/IconFolder.vue';@@ -36,13 +39,13 @@ const toggleDropdown = () => {showDropdown.value = !showDropdown.value;};-const toggleVideoSidebar = (sidebar: 'folders' | 'history') => {+const toggleRightSidebar = (sidebar: 'feed' | 'folders' | 'history', drawerComponent: Component = SidebarDrawer) => {cycleSideBar(sidebar, 'list-card');if (selectedSideBar.value !== sidebar) return;- if (getScreenSizeRank() < 3) {- drawer.open(route.name === 'folder-details' ? FolderDetailsSidebarDrawer : VideoSidebarDrawer, {+ if (getScreenSizeRank() < 3 && drawerComponent) {+ drawer.open(drawerComponent, {showHeader: false,showFooter: false,onClose: () => {@@ -83,10 +86,13 @@ watch(isDesktop, (now) => {switch (route.name) {case 'home':- toggleVideoSidebar(currentSidebar === 'history' ? 'history' : 'folders');+ toggleRightSidebar(currentSidebar === 'history' ? 'history' : 'folders', VideoSidebarDrawer);+ break;+ case 'explore':+ toggleRightSidebar('feed');break;case 'folder':- toggleVideoSidebar('folders');+ toggleRightSidebar('folders', FolderDetailsSidebarDrawer);break;case 'config':toggleLeftSidebar('config');@@ -155,12 +161,18 @@ watch(isDesktop, (now) => {<div class="ml-auto flex flex-wrap items-center justify-end gap-1 sm:w-auto sm:max-w-sm sm:shrink-0 sm:flex-nowrap sm:justify-normal"><span id="video-navbar" class="flex items-center gap-1 antialiased"><template v-if="$route.name === 'home' || $route.name === 'folder-details'">- <NavButton @click="toggleVideoSidebar('folders')" :label="'folders'" :active="selectedSideBar == 'folders'" title="Toggle folder browser" class="p-0">+ <NavButton+ @click="toggleRightSidebar('folders', $route.name === 'home' ? VideoSidebarDrawer : FolderDetailsSidebarDrawer)"+ :label="'folders'"+ :active="selectedSideBar == 'folders'"+ title="Toggle folder browser"+ class="p-0"+ ><IconFolder class="size-6" stroke-width="0.0" /></NavButton><NavButtonv-if="userData"- @click="toggleVideoSidebar('history')"+ @click="toggleRightSidebar('history', VideoSidebarDrawer)":label="'history'":active="selectedSideBar === 'history'"title="Toggle recent watch history"@@ -169,6 +181,23 @@ watch(isDesktop, (now) => {<MaterialSymbolsLightHistory class="size-6" stroke-width="0.25" stroke="currentColor" /></NavButton></template>+ <NavButton+ v-if="$route.name === 'explore'"+ @click="toggleRightSidebar('feed')"+ :label="'activity feed'"+ :active="selectedSideBar == 'feed'"+ title="Toggle activity feed"+ class="p-0"+ >+ <ProiconsSparkle2 class="size-6" />+ <!-- <svg class="size-6" xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24">+ <path d="M0 0h24v24H0z" fill="none" />+ <path+ fill="currentColor"+ d="M6.528 7.75a.75.75 0 1 1-1.5 0a.75.75 0 0 1 1.5 0M5.781 15a.75.75 0 0 0 0 1.5h5a.75.75 0 1 0 0-1.5zm-.75-3.25a.75.75 0 0 1 .75-.75h5a.75.75 0 1 1 0 1.5h-5a.75.75 0 0 1-.75-.75M15 21a1.986 1.986 0 0 0 1.934-1.597l.48-2.403h2.836A1.75 1.75 0 0 0 22 15.25V9.261A2.26 2.26 0 0 0 19.75 7v-.004H14.5V5.25A2.25 2.25 0 0 0 12.25 3h-8A2.25 2.25 0 0 0 2 5.25v12.5A3.25 3.25 0 0 0 5.25 21zM3.5 5.25a.75.75 0 0 1 .75-.75h8a.75.75 0 0 1 .75.75v13.764q0 .251.06.486H5.25a1.75 1.75 0 0 1-1.75-1.75zm11 3.246h3.11a2 2 0 0 0-.088.322l-2.059 10.291a.486.486 0 0 1-.963-.095zm4.493.616a.761.761 0 0 1 1.507.15v5.988a.25.25 0 0 1-.25.25h-2.535z"+ />+ </svg> -->+ </NavButton><NavButtonv-if="$route.name === 'dashboard'"@click="toggleLeftSidebar('dashboard')"diff --git a/resources/js/service/home/useActivityFeed.ts b/resources/js/service/home/useActivityFeed.tsnew file mode 100644index 00000000..708bada3--- /dev/null+++ b/resources/js/service/home/useActivityFeed.ts@@ -0,0 +1,106 @@+import type { FolderResource, VideoResource } from '@/contracts/media';+import type { ComputedRef, Ref } from 'vue';++import { computed } from 'vue';++export type ActivityItemType = 'video' | 'audio' | 'folder';++export interface ActivityItem {+ id: string;+ type: ActivityItemType;+ title: string;+ subtitle: string;+ timestamp: string;+ thumbnail?: string;+ url: string;+ isNew: boolean;+ isAudio?: boolean;+}++const isRecent = (timestamp?: string) => !!timestamp && Date.now() - new Date(timestamp).getTime() < 1000 * 60 * 60 * 24; // 24h++const episodeLabel = (media: VideoResource) => {+ if (media.episode != null) return `Episode ${media.episode}`;+ return 'New video';+};++const videoToActivity = (media: VideoResource): ActivityItem => {+ const timestamp = media.season && media.episode ? (media.metadata?.file_modified_at ?? media.created_at) : media.created_at;+ return {+ id: `video-${media.id}`,+ type: 'video',+ title: media.title ?? media.name,+ subtitle: episodeLabel(media),+ timestamp,+ thumbnail: media.metadata?.poster_image?.path,+ url: media.url ?? '/',+ isNew: isRecent(timestamp),+ };+};++const audioToActivity = (media: VideoResource): ActivityItem => ({+ id: `audio-${media.id}`,+ type: 'audio',+ title: media.title ?? media.name,+ subtitle: [media.artist, media.album].filter(Boolean).join(' · ') || 'New track',+ timestamp: media.metadata?.file_modified_at ?? media.created_at,+ thumbnail: media.metadata?.poster_image?.path,+ url: media.url ?? '/',+ isNew: isRecent(media.metadata?.file_modified_at ?? media.created_at),+});++const folderToActivity = (folder: FolderResource): ActivityItem => ({+ id: `folder-${folder.id}`,+ type: 'folder',+ title: folder.title,+ subtitle: 'Just updated',+ timestamp: folder.series?.updated_at ?? folder.created_at ?? '',+ thumbnail: folder.series?.poster_image?.path,+ url: `/${folder.category_id}/${folder.id}/details`,+ isNew: isRecent(folder.series?.updated_at),+ isAudio: folder.is_majority_audio,+});++export const useActivityFeed = (+ videos: Ref<VideoResource[] | undefined> | ComputedRef<VideoResource[] | undefined>,+ music: Ref<VideoResource[] | undefined> | ComputedRef<VideoResource[] | undefined>,+ updatedFolders: Ref<FolderResource[] | undefined> | ComputedRef<FolderResource[] | undefined>,+ limit = 14,+) =>+ computed<ActivityItem[]>(() => {+ const items = [...(videos.value ?? []).map(videoToActivity), ...(music.value ?? []).map(audioToActivity), ...(updatedFolders.value ?? []).map(folderToActivity)].filter(+ (item) => item.timestamp,+ );++ return items.sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime()).slice(0, limit);+ });++export const groupLabel = (timestamp: string): string => {+ const date = new Date(timestamp);+ const now = new Date();+ const startOf = (d: Date) => new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime();+ const diffDays = Math.round((startOf(now) - startOf(date)) / 86400000);++ if (diffDays === 0) return 'Today';+ if (diffDays === 1) return 'Yesterday';+ if (diffDays < 7) return `${diffDays} days ago`;+ return date.toLocaleDateString(undefined, { month: 'short', day: 'numeric' });+};++/**+ * Groups feed items by their generated group label based on their timestamp+ * @param items+ * @returns { label: string; items: ActivityItem[] }[]+ */+export const groupActivityFeed = (items: ActivityItem[]): { label: string; items: ActivityItem[] }[] => {+ const groups: { label: string; items: ActivityItem[] }[] = [];++ for (const item of items) {+ const label = groupLabel(item.timestamp);+ const last = groups[groups.length - 1];+ if (last?.label === label) last.items.push(item);+ else groups.push({ label, items: [item] });+ }++ return groups;+};diff --git a/resources/js/views/HomeView.vue b/resources/js/views/HomeView.vueindex b120442a..cd2ce0b0 100644--- a/resources/js/views/HomeView.vue+++ b/resources/js/views/HomeView.vue@@ -12,6 +12,7 @@ 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 HomeActivityFeed from '@/components/home/HomeActivityFeed.vue';import HomeSpotlight from '@/components/home/HomeSpotlight.vue';import HomeShelf from '@/components/home/HomeShelf.vue';@@ -24,6 +25,8 @@ const { data: recentlyReleased, isLoading: isLoadingRecentlyReleased } = useRececonst { data: recentlyUpdated, isLoading: isLoadingRecentlyUpdated } = useRecentlyUpdated();const { data: recentlyAdded, isLoading: isLoadingRecentlyAdded } = useRecentlyAdded();+const isLoadingActivity = computed(() => isLoadingRecentlyUploaded.value || isLoadingRecentlyUploadedMusic.value || isLoadingRecentlyUpdated.value);+const breakpoints = useBreakpoints({ ...breakpointsTailwind, '3xl': 2000 });const gridFolderCount = computed(() => {@@ -46,6 +49,7 @@ const spotlightItems = computed(() =>onMounted(() => {pageTitle.value = 'Explore';+ useAppStore().cycleSideBar('feed', 'list-card');});</script>@@ -128,5 +132,8 @@ onMounted(() => {</HomeShelf></div></template>+ <template v-slot:sidebar>+ <HomeActivityFeed :videos="recentlyUploaded" :music="recentlyUploadedMusic" :updated-folders="recentlyUpdated" :is-loading="isLoadingActivity" />+ </template></LayoutBase></template>