Skip to content

Commit 0a167ac

Browse files
committed
fix(desktop): sort local entires by publishedAt
1 parent 2a4dde0 commit 0a167ac

File tree

1 file changed

+16
-2
lines changed
  • apps/desktop/layer/renderer/src/store/entry

1 file changed

+16
-2
lines changed

apps/desktop/layer/renderer/src/store/entry/helper.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ import { useSubscriptionStore } from "../subscription"
77
import { useEntryStore } from "./store"
88
import type { EntryFilter } from "./types"
99

10+
export const getSortedEntryIds = (entriesIds: string[]) => {
11+
const state = useEntryStore.getState()
12+
const idsSorted = entriesIds.sort((a, b) => {
13+
const entryA = state.flatMapEntries[a]
14+
const entryB = state.flatMapEntries[b]
15+
if (!entryA || !entryB) return 0
16+
return (
17+
new Date(entryB.entries.publishedAt).getTime() -
18+
new Date(entryA.entries.publishedAt).getTime()
19+
)
20+
})
21+
return idsSorted
22+
}
23+
1024
export const getFilteredFeedIds = (feedIds: string[], filter?: EntryFilter) => {
1125
const state = useEntryStore.getState()
1226
const ids = [] as string[]
@@ -24,9 +38,9 @@ export const getFilteredFeedIds = (feedIds: string[], filter?: EntryFilter) => {
2438
result.push(entryId)
2539
}
2640
}
27-
return result
41+
return getSortedEntryIds(result)
2842
}
29-
return ids
43+
return getSortedEntryIds(ids)
3044
}
3145

3246
const unread = create({

0 commit comments

Comments
 (0)