Skip to content

A self-hosted media server and file management system

feat: basic lazy image?

aminnausin7a97fc9bac18
diff --git a/resources/js/components/cards/data/LibraryCard.vue b/resources/js/components/cards/data/LibraryCard.vue
index 7b190586..6d52a641 100644
--- a/resources/js/components/cards/data/LibraryCard.vue
+++ b/resources/js/components/cards/data/LibraryCard.vue
@@ -1,8 +1,8 @@
<script setup lang="ts">
import type { CategoryResource, FolderResource } from '@/types/resources';
-import { formatFileSize, handleStorageURL, toFormattedDate } from '@/service/util';
import { startScanFilesTask, startVerifyFilesTask, toggleCategoryPrivacy } from '@/service/siteAPI';
+import { formatFileSize, handleStorageURL, toFormattedDate } from '@/service/util';
import { computed, ref, useTemplateRef, watch } from 'vue';
import { useQueryClient } from '@tanstack/vue-query';
import { updateCategory } from '@/service/mediaAPI.ts';
@@ -10,6 +10,7 @@ import { BasePopover } from '@/components/cedar-ui/popover';
import { toast } from '@aminnausin/cedar-ui';
import LibraryCardMenu from '@/components/menus/LibraryCardMenu.vue';
+import LazyImage from '@/components/lazy/LazyImage.vue';
import ProiconsMoreVertical from '~icons/proicons/more-vertical';
@@ -98,11 +99,10 @@ watch(
<template>
<div class="data-card group flex w-full flex-col rounded-xl shadow-lg ring-1 ring-gray-900/5">
<RouterLink :to="`/${data?.name}`" class="peer relative h-40 w-full">
- <img
+ <LazyImage
class="peer mb-auto h-full w-full rounded-t-xl object-cover shadow-xs ring-1 ring-gray-900/5 ring-inset hover:ring-4"
:src="handleStorageURL(defaultFolder?.series?.thumbnail_url) ?? '/storage/thumbnails/default.webp'"
alt="Folder Cover Art"
- loading="lazy"
/>
<span class="ring-primary/90 absolute top-0 left-0 h-full w-full rounded-t-xl transition duration-(--duration-input) ease-in-out ring-inset hover:ring-2"></span>
</RouterLink>
@@ -148,7 +148,7 @@ watch(
</span>
<span class="flex flex-wrap items-center justify-between gap-x-2 pt-1 sm:hidden sm:pt-0">
<p class="" :title="`Date Added ${data?.created_at ? toFormattedDate(new Date(data?.created_at + ' EST')) : 'N/A'}`">
- {{ data?.created_at ? toFormattedDate(new Date(data?.created_at + ' EST')) : 'N/A' }}
+ {{ toFormattedDate(data?.created_at) }}
</p>
<p class="" :title="`Total Size ${formatFileSize(data.total_size)}`">
{{ formatFileSize(data.total_size) }}
diff --git a/resources/js/components/cards/data/LibraryFolderCard.vue b/resources/js/components/cards/data/LibraryFolderCard.vue
index d341eced..e06f3892 100644
--- a/resources/js/components/cards/data/LibraryFolderCard.vue
+++ b/resources/js/components/cards/data/LibraryFolderCard.vue
@@ -1,5 +1,5 @@
<script setup lang="ts">
-import { type FolderResource } from '@/types/resources';
+import type { FolderResource } from '@/types/resources';
import { formatFileSize, handleStorageURL, toFormattedDate } from '@/service/util';
import { useTemplateRef } from 'vue';
@@ -7,6 +7,7 @@ import { BasePopover } from '@/components/cedar-ui/popover';
import { ButtonIcon } from '@/components/cedar-ui/button';
import LibraryFolderCardMenu from '@/components/menus/LibraryFolderCardMenu.vue';
+import LazyImage from '@/components/lazy/LazyImage.vue';
import ProiconsMoreVertical from '~icons/proicons/more-vertical';
import CircumShare1 from '~icons/circum/share-1';
@@ -18,19 +19,17 @@ const popover = useTemplateRef('popover');
<template>
<div class="data-card group flex w-full flex-col rounded-xl shadow-lg ring-1 ring-gray-900/5">
<RouterLink :to="`/${encodeURI(data.path)}`" class="relative h-40 w-full">
- <img
+ <LazyImage
class="mb-auto h-full w-full rounded-t-md object-cover shadow-xs ring-1 ring-gray-900/5"
:src="handleStorageURL(data?.series?.thumbnail_url) ?? '/storage/thumbnails/default.webp'"
alt="Folder Cover Art"
- loading="lazy"
/>
+
<span class="ring-primary/90 absolute top-0 left-0 h-full w-full rounded-t-md ring-inset hover:ring-2"></span>
</RouterLink>
- <section class="flex h-full flex-1 flex-col gap-2 p-3">
+ <section class="flex h-full flex-1 flex-col gap-2 p-3" v-if="data">
<div class="xs:flex-nowrap flex flex-wrap items-start justify-between gap-1">
- <h3 class="group-hover:text-primary capitalize">
- {{ data?.title ?? data?.name }}
- </h3>
+ <h3 class="group-hover:text-primary capitalize">{{ data.id }} - {{ data?.title ?? data?.name }}</h3>
<span class="flex gap-2 text-sm *:h-6">
<ButtonIcon :title="'Open Folder In New Tab'" :to="`/${encodeURI(data.path)}`" class="size-6 p-0">
<template #icon><CircumShare1 class="size-4" /></template>
@@ -45,9 +44,9 @@ const popover = useTemplateRef('popover');
</BasePopover>
</span>
</div>
- <span class="text-foreground-1 mt-auto flex h-full w-full flex-col gap-1 text-sm" v-if="data">
+ <span class="text-foreground-1 mt-auto flex h-full w-full flex-col gap-1 text-sm">
<span class="mt-auto flex flex-wrap items-start justify-between">
- <p class="">{{ data.is_majority_audio ? 'Tracks' : 'Videos' }}: {{ data?.file_count ?? '?' }}</p>
+ <p class="">{{ 'Files' }}: {{ data?.file_count ?? '?' }}</p>
</span>
<span class="flex items-center justify-between gap-x-2">
diff --git a/resources/js/components/lazy/LazyImage.vue b/resources/js/components/lazy/LazyImage.vue
new file mode 100644
index 00000000..5a12ac29
--- /dev/null
+++ b/resources/js/components/lazy/LazyImage.vue
@@ -0,0 +1,30 @@
+<script setup lang="ts">
+import { ref, useAttrs } from 'vue';
+import { SvgSpinners90RingWithBg } from '../cedar-ui/icons';
+
+defineOptions({ inheritAttrs: false });
+
+const props = defineProps<{ src?: string }>();
+const attrs = useAttrs();
+
+const isLoading = ref(true);
+const isError = ref(false);
+</script>
+<template>
+ <div class="relative contents">
+ <div v-if="src && isLoading && !isError" class="absolute inset-0 flex items-center justify-center">
+ <SvgSpinners90RingWithBg class="size-4" />
+ </div>
+ <img
+ v-bind="attrs"
+ :src="src"
+ loading="lazy"
+ :class="[{ 'scale-85 opacity-0': isLoading }, 'transition-all ease-in-out']"
+ @load="
+ isLoading = false;
+ isError = false;
+ "
+ @error="isError = true"
+ />
+ </div>
+</template>
diff --git a/resources/js/components/video/VideoInfoPanel.vue b/resources/js/components/video/VideoInfoPanel.vue
index d72f8656..ed7a2ae8 100755
--- a/resources/js/components/video/VideoInfoPanel.vue
+++ b/resources/js/components/video/VideoInfoPanel.vue
@@ -27,6 +27,7 @@ import ProiconsMoreVertical from '~icons/proicons/more-vertical';
import CircumShare1 from '~icons/circum/share-1';
import ProiconsEye from '~icons/proicons/eye';
import CircumEdit from '~icons/circum/edit';
+import LazyImage from '../lazy/LazyImage.vue';
const defaultDescription = `No description yet.`;
@@ -224,7 +225,7 @@ onMounted(() => {
</ul>
</section>
<div id="mp4-folder-info" class="xs:block aspect-2-3 relative hidden h-32 rounded-md object-cover shadow-md">
- <img
+ <LazyImage
id="folder-thumbnail"
class="aspect-2-3 h-full rounded-md object-cover ring-1 ring-gray-900/5"
alt="Folder Cover Art"