Skip to content

Commit

Permalink
fix(store): fix selector fallback value
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <tukon479@gmail.com>
  • Loading branch information
Innei committed Nov 13, 2024
1 parent 07b075a commit 0ca5abc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
4 changes: 3 additions & 1 deletion apps/renderer/src/store/entry/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ export const useEntryIdsByFeedId = (feedId: string, filter?: EntryFilter) =>
export const useEntryIdsByView = (view: FeedViewType, filter?: EntryFilter) => {
const feedIds = useFeedIdByView(view)

return useEntryStore(useCallback(() => getFilteredFeedIds(feedIds, filter), [feedIds, filter]))
return useEntryStore(
useCallback(() => getFilteredFeedIds(feedIds, filter) || [], [feedIds, filter]),
)
}

export const useEntryIdsByFeedIds = (feedIds: string[], filter: EntryFilter = {}) =>
Expand Down
17 changes: 12 additions & 5 deletions apps/renderer/src/store/subscription/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,29 @@ import { useSubscriptionStore } from "./store"
type FeedId = string

export const useFeedIdByView = (view: FeedViewType) =>
useSubscriptionStore(useCallback((state) => feedIdByViewSelector(view)(state), [view]))
useSubscriptionStore(useCallback((state) => feedIdByViewSelector(view)(state) || [], [view]))

export const useCategoryOpenStateByView = (view: FeedViewType) =>
useSubscriptionStore(useCallback((state) => categoryOpenStateByViewSelector(view)(state), [view]))
useSubscriptionStore(
useCallback((state) => categoryOpenStateByViewSelector(view)(state) || {}, [view]),
)

export const useSubscriptionByView = (view: FeedViewType) =>
useSubscriptionStore(useCallback((state) => subscriptionByViewSelector(view)(state), [view]))
useSubscriptionStore(
useCallback((state) => subscriptionByViewSelector(view)(state) || [], [view]),
)

export const useSubscriptionByFeedId = (feedId: FeedId) =>
useSubscriptionStore(
useCallback((state) => subscriptionByFeedIdSelector(feedId)(state), [feedId]),
useCallback((state) => subscriptionByFeedIdSelector(feedId)(state) || null, [feedId]),
)

export const useFolderFeedsByFeedId = ({ feedId, view }: { feedId?: string; view: FeedViewType }) =>
useSubscriptionStore(
useCallback((state) => folderFeedsByFeedIdSelector({ feedId, view })(state), [feedId, view]),
useCallback(
(state) => folderFeedsByFeedIdSelector({ feedId, view })(state) || [],
[feedId, view],
),
)

export const useListSubscriptionCount = () => useSubscriptionStore(listSubscriptionCountSelector)
Expand Down

0 comments on commit 0ca5abc

Please sign in to comment.