Skip to content

A self-hosted media server and file management system

fix: spotlight items are not sorted by date and get confusing

aminnausin243d7cd87904
diff --git a/app/Http/Resources/FolderResource.php b/app/Http/Resources/FolderResource.php
index baf283a6..ffd98fa1 100755
--- a/app/Http/Resources/FolderResource.php
+++ b/app/Http/Resources/FolderResource.php
@@ -39,6 +39,7 @@ class FolderResource extends JsonResource {
'created_at' => $this->series?->created_at,
'updated_at' => $this->series?->updated_at,
'edited_at' => $this->series?->edited_at,
+ 'released_at' => $this->series?->started_at,
];
}
}
diff --git a/resources/js/contracts/media.ts b/resources/js/contracts/media.ts
index 9527f92d..fbcffa71 100644
--- a/resources/js/contracts/media.ts
+++ b/resources/js/contracts/media.ts
@@ -37,6 +37,7 @@ export interface FolderResource {
scanned_at?: string;
updated_at?: string;
edited_at?: string;
+ released_at?: string;
}
export interface SeriesResource {
diff --git a/resources/js/service/explore/useSpotlightItems.ts b/resources/js/service/explore/useSpotlightItems.ts
index 3fa6c748..5a320003 100644
--- a/resources/js/service/explore/useSpotlightItems.ts
+++ b/resources/js/service/explore/useSpotlightItems.ts
@@ -1,25 +1,36 @@
import type { FolderResource } from '@/contracts/media';
-export type SpotlightItem = { folder: FolderResource; label: string; subtitle?: string };
+import { CompareStrategies } from '@/service/sort/strategies';
+import { sortObjectNew } from '@/service/sort/baseSort';
+
+export type SpotlightItem = { id: number; folder: FolderResource; label: string; subtitle?: string; timestamp: Date };
export function interleaveSpotlightItems(
- groups: { items: FolderResource[]; label: string; buildSubtitle?: (folder: FolderResource) => string | undefined }[],
+ groups: { items: FolderResource[]; label: string; buildSubtitle?: (folder: FolderResource) => string | undefined; dateField: keyof FolderResource }[],
perGroup = 4,
): SpotlightItem[] {
const seen = new Set<number>();
- const queues = groups.map(({ items, label, buildSubtitle }) => {
+ const queues = groups.map(({ items, label, buildSubtitle, dateField }) => {
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, buildSubtitle };
+ return { label, items: deduped, buildSubtitle, dateField };
});
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, subtitle: q.buildSubtitle?.(q.items[i]) });
+ for (const q of queues)
+ if (q.items[i])
+ result.push({
+ id: q.items[i].id,
+ folder: q.items[i],
+ label: q.label,
+ subtitle: q.buildSubtitle?.(q.items[i]),
+ timestamp: new Date(q.items[i][q.dateField] as string),
+ });
}
- return result;
+ return result.sort(sortObjectNew([{ key: 'timestamp', compareFn: CompareStrategies.date }], -1));
}
diff --git a/resources/js/views/ExploreView.vue b/resources/js/views/ExploreView.vue
index a92fcceb..63914794 100644
--- a/resources/js/views/ExploreView.vue
+++ b/resources/js/views/ExploreView.vue
@@ -34,9 +34,9 @@ const gridFolderCount = computed(() => {
const spotlightItems = computed(() =>
interleaveSpotlightItems(
[
- { items: recentlyUpdated.value ?? [], label: 'Just Updated' },
- { items: recentlyAdded.value ?? [], label: 'Just Added' },
- { items: recentlyReleased.value ?? [], label: 'Just Released' },
+ { items: recentlyUpdated.value ?? [], label: 'Just Updated', dateField: 'updated_at' },
+ { items: recentlyAdded.value ?? [], label: 'Just Added', dateField: 'created_at' },
+ { items: recentlyReleased.value ?? [], label: 'Just Released', dateField: 'released_at' },
],
4,
),