mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-06 12:52:26 +00:00
fix: ensure watch history is sorted by most recent first
- Enforce descending month order in `js/nostr/watchHistory.js` by explicitly sorting keys before flattening buckets. - Update `js/feedEngine/watchHistoryFeed.js` and `js/historyView.js` to use `video.created_at` as a fallback sort key when `watchedAt` is missing or equal. - Verified logic with `tests/verify_sort.mjs`.
This commit is contained in:
1 parent
ad961cd401
commit
f2f55830e8
3 files changed
+55
-8
No files matched your search
@@ -195,8 +195,19 @@ function createWatchHistorySource({ service = watchHistoryService } = {}) {
|
||||
}
|
||||
|
||||
results.sort((a, b) => {
|
||||
if (a.watchedAt !== b.watchedAt) {
|
||||
return b.watchedAt - a.watchedAt;
|
||||
const watchedA = a?.watchedAt || 0;
|
||||
const watchedB = b?.watchedAt || 0;
|
||||
if (watchedA !== watchedB) {
|
||||
return watchedB - watchedA;
|
||||
}
|
||||
const createdA = Number.isFinite(a?.video?.created_at)
|
||||
? a.video.created_at
|
||||
: 0;
|
||||
const createdB = Number.isFinite(b?.video?.created_at)
|
||||
? b.video.created_at
|
||||
: 0;
|
||||
if (createdA !== createdB) {
|
||||
return createdB - createdA;
|
||||
}
|
||||
return a.pointerKey.localeCompare(b.pointerKey);
|
||||
});
|
||||
@@ -488,8 +499,19 @@ function createWatchHistorySorter() {
|
||||
}
|
||||
const copy = [...items];
|
||||
copy.sort((a, b) => {
|
||||
if (a?.watchedAt !== b?.watchedAt) {
|
||||
return (b?.watchedAt || 0) - (a?.watchedAt || 0);
|
||||
const watchedA = a?.watchedAt || 0;
|
||||
const watchedB = b?.watchedAt || 0;
|
||||
if (watchedA !== watchedB) {
|
||||
return watchedB - watchedA;
|
||||
}
|
||||
const createdA = Number.isFinite(a?.video?.created_at)
|
||||
? a.video.created_at
|
||||
: 0;
|
||||
const createdB = Number.isFinite(b?.video?.created_at)
|
||||
? b.video.created_at
|
||||
: 0;
|
||||
if (createdA !== createdB) {
|
||||
return createdB - createdA;
|
||||
}
|
||||
const aKey = typeof a?.pointerKey === "string" ? a.pointerKey : "";
|
||||
const bKey = typeof b?.pointerKey === "string" ? b.pointerKey : "";
|
||||
|
||||
Reference in new issue
Block a user