Skip to content

Commit

Permalink
feat: remove entries level
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Jul 16, 2024
1 parent e77c77d commit 527686b
Show file tree
Hide file tree
Showing 15 changed files with 22 additions and 62 deletions.
5 changes: 1 addition & 4 deletions src/renderer/src/hooks/biz/useNavigateEntry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ type NavigateEntryOptions = Partial<{
feedId: string | null
entryId: string | null
view: FeedViewType
level: string | null

}>
/**
* @description a hook to navigate to `feedId`, `entryId`, add search for `view`, `level`
Expand All @@ -18,7 +16,7 @@ type NavigateEntryOptions = Partial<{
export const useNavigateEntry = () => navigateEntry

export const navigateEntry = (options: NavigateEntryOptions) => {
const { entryId, feedId, level, view } = options || {}
const { entryId, feedId, view } = options || {}
const { params, searchParams } = getReadonlyRoute()
let finalFeedId = feedId || params.feedId || ROUTE_FEED_PENDING

Expand All @@ -32,7 +30,6 @@ export const navigateEntry = (options: NavigateEntryOptions) => {
nextSearchParams.set("view", view.toString())
setSidebarActiveView(view)
}
level && nextSearchParams.set("level", level.toString())

return getStableRouterNavigate()?.(
`/feeds/${finalFeedId}/${
Expand Down
2 changes: 0 additions & 2 deletions src/renderer/src/hooks/biz/useRouteParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export interface BizRouteParams {
view: FeedViewType
entryId?: string
feedId?: string
level?: string
isCollection: boolean
isAllFeeds: boolean
isPendingEntry: boolean
Expand All @@ -59,7 +58,6 @@ const parseRouteParams = (params: Params<any>, search: URLSearchParams): BizRout
view,
entryId: params.entryId || undefined,
feedId: params.feedId || undefined,
level: search.get("level") || undefined,
// alias
isCollection: params.feedId === FEED_COLLECTION_LIST,
isAllFeeds: params.feedId === ROUTE_FEED_PENDING,
Expand Down
5 changes: 0 additions & 5 deletions src/renderer/src/lib/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ import * as semver from "semver"

import { getStorageNS } from "./ns"

export const levels = {
folder: "folder",
feed: "feed",
}

export const views = [
{
name: "Articles",
Expand Down
16 changes: 5 additions & 11 deletions src/renderer/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { clsx } from "clsx"
import { memoize } from "lodash-es"
import { twMerge } from "tailwind-merge"

import { FEED_COLLECTION_LIST, levels } from "./constants"
import { FEED_COLLECTION_LIST, ROUTE_FEED_PENDING } from "./constants"

export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
Expand All @@ -14,11 +14,9 @@ export function clamp(value, min, max) {
}

export function getEntriesParams({
level,
id,
view,
}: {
level?: string
id?: number | string
view?: number
}) {
Expand All @@ -27,14 +25,10 @@ export function getEntriesParams({
feedIdList?: string[]
collected?: boolean
} = {}
if (level === levels.folder) {
if (id === FEED_COLLECTION_LIST) {
params.collected = true
} else {
params.feedIdList = id ? `${id}`.split(",") : undefined
}
} else if (level === levels.feed) {
params.feedId = `${id}`
if (id === FEED_COLLECTION_LIST) {
params.collected = true
} else if (id && id !== ROUTE_FEED_PENDING) {
params.feedIdList = `${id}`.split(",")
}
return {
view,
Expand Down
1 change: 0 additions & 1 deletion src/renderer/src/models/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export type ExtractBizResponse<T extends (...args: any[]) => any> = Exclude<
>

export type ActiveList = {
level: string
id: string | number
name: string
view: number
Expand Down
7 changes: 3 additions & 4 deletions src/renderer/src/modules/entry-column/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
useRouteParamsSelector,
useRouteParms,
} from "@renderer/hooks/biz/useRouteParams"
import { levels, views } from "@renderer/lib/constants"
import { views } from "@renderer/lib/constants"
import { shortcuts } from "@renderer/lib/shortcuts"
import { useEntries } from "@renderer/queries/entries"
import { entryActions, useEntryIdsByFeedIdOrView } from "@renderer/store/entry"
Expand Down Expand Up @@ -63,13 +63,12 @@ export const useEntriesByView = () => {
const routeParams = useRouteParms()
const unreadOnly = useGeneralSettingKey("unreadOnly")

const { level, feedId, view, isAllFeeds, isCollection } = routeParams
const { feedId, view, isAllFeeds, isCollection } = routeParams

const folderIds = useFolderFeedsByFeedId(feedId)

const query = useEntries({
level,
id: level === levels.folder ? folderIds?.join(",") : feedId,
id: folderIds?.join(",") || feedId,
view,
...(unreadOnly === true && { read: false }),

Expand Down
8 changes: 1 addition & 7 deletions src/renderer/src/modules/entry-column/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { useIsOnline } from "@renderer/hooks/common/useIsOnline"
import { apiClient } from "@renderer/lib/api-fetch"
import {
FEED_COLLECTION_LIST,
levels,
ROUTE_ENTRY_PENDING,
ROUTE_FEED_IN_FOLDER,
views,
Expand Down Expand Up @@ -179,11 +178,7 @@ const ListHeader: FC<{
await apiClient.reads.all.$post({
json: {
...getEntriesParams({
level: routerParams?.level,
id:
routerParams.level === levels.folder ?
folderIds?.join(",") :
feedId,
id: folderIds?.join(",") || feedId,
view: routerParams?.view,
}),
},
Expand All @@ -192,7 +187,6 @@ const ListHeader: FC<{
if (typeof routerParams.feedId === "number" || routerParams.isAllFeeds) {
subscriptionActions.markReadByView(routerParams.view)
} else if (
routerParams.level === levels.folder &&
routerParams.feedId?.startsWith(ROUTE_FEED_IN_FOLDER)
) {
subscriptionActions.markReadByFolder(
Expand Down
7 changes: 2 additions & 5 deletions src/renderer/src/modules/feed-column/category.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
} from "@renderer/components/ui/collapsible"
import { useNavigateEntry } from "@renderer/hooks/biz/useNavigateEntry"
import { useRouteParamsSelector } from "@renderer/hooks/biz/useRouteParams"
import { levels, ROUTE_FEED_IN_FOLDER } from "@renderer/lib/constants"
import { ROUTE_FEED_IN_FOLDER } from "@renderer/lib/constants"
import { stopPropagation } from "@renderer/lib/dom"
import { showNativeMenu } from "@renderer/lib/native-menu"
import { cn } from "@renderer/lib/utils"
Expand Down Expand Up @@ -57,7 +57,6 @@ function FeedCategoryImpl({
entryId: null,
// TODO joint feedId is too long, need to be optimized
feedId: `${ROUTE_FEED_IN_FOLDER}${folderName}`,
level: levels.folder,
view,
})
}
Expand All @@ -68,9 +67,7 @@ function FeedCategoryImpl({
)

const isActive = useRouteParamsSelector(
(routerParams) =>
routerParams?.level === levels.folder &&
routerParams.feedId === `${ROUTE_FEED_IN_FOLDER}${folderName}`,
(routerParams) => routerParams.feedId === `${ROUTE_FEED_IN_FOLDER}${folderName}`,
)
const { present } = useModalStack()

Expand Down
5 changes: 1 addition & 4 deletions src/renderer/src/modules/feed-column/item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
import { useNavigateEntry } from "@renderer/hooks/biz/useNavigateEntry"
import { useRouteParamsSelector } from "@renderer/hooks/biz/useRouteParams"
import { useDeleteSubscription } from "@renderer/hooks/biz/useSubscriptionActions"
import { levels } from "@renderer/lib/constants"
import dayjs from "@renderer/lib/dayjs"
import { nextFrame } from "@renderer/lib/dom"
import { showNativeMenu } from "@renderer/lib/native-menu"
Expand Down Expand Up @@ -48,7 +47,6 @@ const FeedItemImpl = ({
feedId,
entryId: null,
view,
level: levels.feed,
})
// focus to main container in order to let keyboard can navigate entry items by arrow keys
nextFrame(() => {
Expand All @@ -64,8 +62,7 @@ const FeedItemImpl = ({
const { present } = useModalStack()

const isActive = useRouteParamsSelector(
(routerParams) =>
routerParams?.level === levels.feed && routerParams.feedId === feedId,
(routerParams) => routerParams.feedId === feedId,
)

const feed = useFeedById(feedId)
Expand Down
3 changes: 1 addition & 2 deletions src/renderer/src/modules/feed-column/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useUISettingKey } from "@renderer/atoms/settings/ui"
import { useNavigateEntry } from "@renderer/hooks/biz/useNavigateEntry"
import { useRouteFeedId } from "@renderer/hooks/biz/useRouteParams"
import { useAuthQuery } from "@renderer/hooks/common"
import { FEED_COLLECTION_LIST, levels, views } from "@renderer/lib/constants"
import { FEED_COLLECTION_LIST, views } from "@renderer/lib/constants"
import { stopPropagation } from "@renderer/lib/dom"
import type { FeedViewType } from "@renderer/lib/enum"
import { cn } from "@renderer/lib/utils"
Expand Down Expand Up @@ -137,7 +137,6 @@ export function FeedList({
navigate({
entryId: null,
feedId: FEED_COLLECTION_LIST,
level: levels.folder,
view,
})
}
Expand Down
4 changes: 1 addition & 3 deletions src/renderer/src/modules/search/cmdk.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
TooltipTrigger,
} from "@renderer/components/ui/tooltip"
import { useNavigateEntry } from "@renderer/hooks/biz/useNavigateEntry"
import { levels, ROUTE_ENTRY_PENDING } from "@renderer/lib/constants"
import { ROUTE_ENTRY_PENDING } from "@renderer/lib/constants"
import type { FeedViewType } from "@renderer/lib/enum"
import { cn, pluralize } from "@renderer/lib/utils"
import { getFeedById } from "@renderer/store/feed"
Expand Down Expand Up @@ -261,8 +261,6 @@ const SearchItem = memo(function Item({
feedId: feedId!,
entryId,
view,

level: levels.feed,
})
}}
>
Expand Down
11 changes: 3 additions & 8 deletions src/renderer/src/queries/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,18 @@ import { entryActions } from "@renderer/store/entry"

export const entries = {
entries: ({
level,
id,
view,
read,
}: {
level?: string
id?: number | string
view?: number
read?: boolean
}) =>
defineQuery(
["entries", id, level, view, read],
["entries", id, view, read],
async ({ pageParam }) =>
entryActions.fetchEntries({
level,
id,
view,
read,
Expand Down Expand Up @@ -53,18 +50,16 @@ export const entries = {
}

export const useEntries = ({
level,
id,
view,
read,
}: {
level?: string
id?: number | string
view?: number
read?: boolean
}) =>
useAuthInfiniteQuery(entries.entries({ level, id, view, read }), {
enabled: level !== undefined && id !== undefined,
useAuthInfiniteQuery(entries.entries({ id, view, read }), {
enabled: id !== undefined,
getNextPageParam: (lastPage) => {
if (!lastPage.data?.length) {
return null
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/store/entry/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const useEntryIdsByFolderName = (
const feedIds = useFolderFeedsByFeedId(folderName)
return useEntryStore(
useShallow(() => {
if (!feedIds) return []
if (!feedIds) return null

return getFilteredFeedIds(feedIds, filter)
}),
Expand Down
2 changes: 0 additions & 2 deletions src/renderer/src/store/entry/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class EntryActions {
}

async fetchEntries({
level,
id,
view,
read,
Expand All @@ -79,7 +78,6 @@ class EntryActions {
read,
// withContent: true,
...getEntriesParams({
level,
id,
view,
}),
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/src/store/subscription/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export const useSubscriptionByFeedId = (feedId: FeedId) =>
useSubscriptionStore((state) => state.data[feedId])

export const useFolderFeedsByFeedId = (feedId?: string) =>
useSubscriptionStore((state): string[] => {
if (typeof feedId !== "string") return []
useSubscriptionStore((state): string[] | null => {
if (typeof feedId !== "string") return null
if (feedId === FEED_COLLECTION_LIST) { return [feedId] }

if (!feedId.startsWith(ROUTE_FEED_IN_FOLDER)) {
return []
return null
}

const folderName = feedId.replace(ROUTE_FEED_IN_FOLDER, "")
Expand Down

0 comments on commit 527686b

Please sign in to comment.