Skip to content

Commit

Permalink
feat: sort list by insertedat
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Sep 23, 2024
1 parent d8ddffb commit 36fbbdd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
22 changes: 18 additions & 4 deletions apps/renderer/src/modules/entry-column/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useRouteParams, useRouteParamsSelector } from "~/hooks/biz/useRoutePara
import { useAuthQuery } from "~/hooks/common"
import { entries, useEntries } from "~/queries/entries"
import { entryActions, useEntryIdsByFeedIdOrView } from "~/store/entry"
import { isSubscriptionList, useFolderFeedsByFeedId } from "~/store/subscription"
import { isListSubscription, useFolderFeedsByFeedId } from "~/store/subscription"
import { feedUnreadActions } from "~/store/unread"

export const useEntryMarkReadHandler = (entriesIds: string[]) => {
Expand Down Expand Up @@ -60,6 +60,7 @@ export const useEntriesByView = ({
const unreadOnly = useGeneralSettingKey("unreadOnly")

const { feedId, view, isAllFeeds, isCollection } = routeParams
const isList = isListSubscription(feedId)

const folderIds = useFolderFeedsByFeedId({
feedId,
Expand All @@ -71,7 +72,7 @@ export const useEntriesByView = ({
view,
...(unreadOnly === true && { read: false }),
isArchived,
isList: isSubscriptionList(feedId),
isList,
}
const query = useEntries(entriesOptions)

Expand Down Expand Up @@ -166,7 +167,9 @@ export const useEntriesByView = ({

const sortEntries = isCollection
? sortEntriesIdByStarAt(mergedEntries[view])
: sortEntriesIdByEntryPublishedAt(mergedEntries[view])
: isList
? sortEntriesIdByEntryInsertedAt(mergedEntries[view])
: sortEntriesIdByEntryPublishedAt(mergedEntries[view])

const groupByDate = useGeneralSettingKey("groupByDate")
const groupedCounts: number[] | undefined = useMemo(() => {
Expand All @@ -184,7 +187,9 @@ export const useEntriesByView = ({
if (!entry) {
continue
}
const date = new Date(entry.entries.publishedAt).toDateString()
const date = new Date(
isList ? entry.entries.insertedAt : entry.entries.publishedAt,
).toDateString()
if (date !== lastDate) {
counts.push(1)
lastDate = date
Expand Down Expand Up @@ -249,3 +254,12 @@ function sortEntriesIdByStarAt(entries: string[]) {
return bStar.localeCompare(aStar)
})
}

function sortEntriesIdByEntryInsertedAt(entries: string[]) {
const entriesId2Map = entryActions.getFlattenMapEntries()
return entries
.slice()
.sort((a, b) =>
entriesId2Map[b]?.entries.insertedAt.localeCompare(entriesId2Map[a]?.entries.insertedAt),
)
}
2 changes: 1 addition & 1 deletion apps/renderer/src/store/subscription/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ export const getSubscriptionByFeedId = (feedId: FeedId) => {
return state.data[feedId]
}

export const isSubscriptionList = (feedId?: FeedId) => {
export const isListSubscription = (feedId?: FeedId) => {
if (!feedId) return false
const subscription = getSubscriptionByFeedId(feedId)
if (!subscription) return false
Expand Down

0 comments on commit 36fbbdd

Please sign in to comment.