@@ -21,20 +21,6 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 200;
|
||||
} | {
|
||||
input: {
|
||||
json: {
|
||||
userId: string;
|
||||
amount: string;
|
||||
entryId?: string | undefined;
|
||||
};
|
||||
};
|
||||
output: {
|
||||
code: 1;
|
||||
message: string;
|
||||
};
|
||||
outputFormat: "json";
|
||||
status: 400;
|
||||
};
|
||||
};
|
||||
"/wallets": {
|
||||
@@ -49,9 +35,9 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
|
||||
code: 0;
|
||||
data: {
|
||||
userId: string;
|
||||
createdAt: string;
|
||||
addressIndex: number;
|
||||
address: string | null;
|
||||
createdAt: string;
|
||||
powerToken: bigint;
|
||||
}[];
|
||||
};
|
||||
@@ -64,9 +50,9 @@ declare const routes: hono_hono_base.HonoBase<hono_types.BlankEnv, {
|
||||
code: 0;
|
||||
data: {
|
||||
userId: string;
|
||||
createdAt: string;
|
||||
addressIndex: number;
|
||||
address: string | null;
|
||||
createdAt: string;
|
||||
powerToken: bigint;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { apiClient } from "@renderer/lib/api-fetch"
|
||||
import { client } from "@renderer/lib/client"
|
||||
import type { EntryModel } from "@renderer/models"
|
||||
import { entryActions } from "@renderer/store/entry/entry"
|
||||
import { entryActions } from "@renderer/store"
|
||||
import { useMutation, useQuery } from "@tanstack/react-query"
|
||||
import type { FetchError } from "ofetch"
|
||||
import { ofetch } from "ofetch"
|
||||
|
||||
@@ -5,11 +5,15 @@ import { isUndefined } from "lodash-es"
|
||||
import { useCallback } from "react"
|
||||
import { useNavigate, useParams, useSearchParams } from "react-router-dom"
|
||||
|
||||
import { useRefValue } from "../common"
|
||||
|
||||
type NavigateEntryOptions = Partial<{
|
||||
feedId: string | null
|
||||
entryId: string | null
|
||||
view: FeedViewType
|
||||
level: string | null
|
||||
|
||||
category: string | null
|
||||
}>
|
||||
/**
|
||||
* @description a hook to navigate to `feedId`, `entryId`, add search for `view`, `level`
|
||||
@@ -18,26 +22,37 @@ export const useNavigateEntry = () => {
|
||||
const [searchParams] = useSearchParams()
|
||||
const navigate = useNavigate()
|
||||
const params = useParams()
|
||||
|
||||
const paramsRef = useRefValue(params)
|
||||
const searchRef = useRefValue(searchParams)
|
||||
return useCallback(
|
||||
(options: NavigateEntryOptions) => {
|
||||
const { entryId, feedId, level, view } = options || {}
|
||||
let finalFeedId = feedId || params.feedId || ROUTE_FEED_PENDING
|
||||
const { entryId, feedId, level, view, category } = options || {}
|
||||
let finalFeedId = feedId || paramsRef.current.feedId || ROUTE_FEED_PENDING
|
||||
|
||||
if ("feedId" in options && feedId === null) {
|
||||
finalFeedId = ROUTE_FEED_PENDING
|
||||
}
|
||||
|
||||
const nextSearchParams = new URLSearchParams(searchParams)
|
||||
const nextSearchParams = new URLSearchParams(searchRef.current)
|
||||
|
||||
!isUndefined(view) && nextSearchParams.set("view", view.toString())
|
||||
level && nextSearchParams.set("level", level.toString())
|
||||
|
||||
if ("category" in options) {
|
||||
if (!category) {
|
||||
nextSearchParams.delete("category")
|
||||
} else {
|
||||
nextSearchParams.set("category", category.toString())
|
||||
}
|
||||
}
|
||||
|
||||
return navigate(
|
||||
`/feeds/${finalFeedId}/${
|
||||
entryId || ROUTE_FEED_PENDING
|
||||
}?${nextSearchParams.toString()}`,
|
||||
)
|
||||
},
|
||||
[navigate, params.feedId, searchParams],
|
||||
[navigate, paramsRef, searchRef],
|
||||
)
|
||||
}
|
||||
|
||||
@@ -43,5 +43,6 @@ export const useRouteParms = () => {
|
||||
entryId: params.entryId || undefined,
|
||||
feedId: params.feedId || undefined,
|
||||
level: search.get("level") || undefined,
|
||||
category: search.get("category") || undefined,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,9 @@ import {
|
||||
PopoverTrigger,
|
||||
} from "@renderer/components/ui/popover"
|
||||
import { useRead, useRefValue } from "@renderer/hooks"
|
||||
import { useNavigateEntry } from "@renderer/hooks/biz/useNavigateEntry"
|
||||
import {
|
||||
useRouteEntryId,
|
||||
useRouteParms,
|
||||
} from "@renderer/hooks/biz/useRouteParams"
|
||||
import { apiClient } from "@renderer/lib/api-fetch"
|
||||
@@ -16,11 +18,10 @@ import { buildStorageNS } from "@renderer/lib/ns"
|
||||
import { getEntriesParams } from "@renderer/lib/utils"
|
||||
import { useEntries } from "@renderer/queries/entries"
|
||||
import {
|
||||
feedActions,
|
||||
getCurrentEntryId,
|
||||
entryActions,
|
||||
subscriptionActions,
|
||||
useFeedHeaderTitle,
|
||||
} from "@renderer/store"
|
||||
import { entryActions } from "@renderer/store/entry/entry"
|
||||
import {
|
||||
useEntry,
|
||||
useEntryIdsByFeedIdOrView,
|
||||
@@ -131,10 +132,14 @@ export function EntryColumn() {
|
||||
),
|
||||
}
|
||||
|
||||
const navigate = useNavigateEntry()
|
||||
return (
|
||||
<div
|
||||
className="relative flex h-full flex-1 flex-col"
|
||||
onClick={() => feedActions.setActiveEntry(null)}
|
||||
onClick={() =>
|
||||
navigate({
|
||||
entryId: null,
|
||||
})}
|
||||
data-total-count={virtuosoOptions.totalCount}
|
||||
>
|
||||
<ListHeader totalCount={virtuosoOptions.totalCount} />
|
||||
@@ -256,6 +261,7 @@ const ListHeader: FC<{
|
||||
setMarkPopoverOpen(false)
|
||||
}, [routerParams])
|
||||
|
||||
const headerTitle = useFeedHeaderTitle()
|
||||
return (
|
||||
<div className="mb-5 flex w-full flex-col pl-11 pr-4 pt-2.5">
|
||||
<div className="flex w-full justify-end">
|
||||
@@ -292,7 +298,7 @@ const ListHeader: FC<{
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<div className="text-lg font-bold leading-none">{routerParams?.name}</div>
|
||||
<div className="text-lg font-bold leading-none">{headerTitle}</div>
|
||||
<div className="text-xs font-medium text-zinc-400">
|
||||
{totalCount || 0}
|
||||
{" "}
|
||||
@@ -343,6 +349,9 @@ const EntryList: FC<VirtuosoProps<string, unknown>> = ({
|
||||
|
||||
const dataRef = useRefValue(virtuosoOptions.data!)
|
||||
|
||||
const currentEntryIdRef = useRefValue(useRouteEntryId())
|
||||
|
||||
const navigate = useNavigateEntry()
|
||||
useEffect(() => {
|
||||
if (!virtuosoRef.current) return
|
||||
if (!$mainContainer) return
|
||||
@@ -364,7 +373,7 @@ const EntryList: FC<VirtuosoProps<string, unknown>> = ({
|
||||
hotkeys(registerKeys, scope, (handler) => {
|
||||
const data = dataRef.current
|
||||
const currentActiveEntryIndex = data.indexOf(
|
||||
getCurrentEntryId() || "",
|
||||
currentEntryIdRef.current || "",
|
||||
)
|
||||
|
||||
switch (handler.key) {
|
||||
@@ -387,7 +396,10 @@ const EntryList: FC<VirtuosoProps<string, unknown>> = ({
|
||||
index: nextIndex,
|
||||
})
|
||||
const nextId = data![nextIndex]
|
||||
feedActions.setActiveEntry(nextId)
|
||||
|
||||
navigate({
|
||||
entryId: nextId,
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -409,7 +421,7 @@ const EntryList: FC<VirtuosoProps<string, unknown>> = ({
|
||||
|
||||
document.removeEventListener("focusin", focusHandler)
|
||||
}
|
||||
}, [$mainContainer])
|
||||
}, [$mainContainer, currentEntryIdRef, dataRef, navigate])
|
||||
|
||||
const handleKeyDown: React.KeyboardEventHandler<HTMLDivElement> = useCallback(
|
||||
(e) => {
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
WrappedElementProvider,
|
||||
} from "@renderer/providers/wrapped-element-provider"
|
||||
import { Queries } from "@renderer/queries"
|
||||
import { useEntry, useFeedStore } from "@renderer/store"
|
||||
import { useEntry, useFeedHeaderTitle } from "@renderer/store"
|
||||
import { m } from "framer-motion"
|
||||
import { useEffect, useState } from "react"
|
||||
|
||||
@@ -18,8 +18,7 @@ import { setEntryTitleMeta } from "./atoms"
|
||||
import { EntryHeader } from "./header"
|
||||
|
||||
export const EntryContent = ({ entryId }: { entryId: ActiveEntryId }) => {
|
||||
const activeList = useFeedStore((state) => state.activeList)
|
||||
|
||||
const title = useFeedHeaderTitle()
|
||||
if (!entryId) {
|
||||
return (
|
||||
<m.div
|
||||
@@ -28,7 +27,7 @@ export const EntryContent = ({ entryId }: { entryId: ActiveEntryId }) => {
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
>
|
||||
<Logo className="size-16 opacity-40 grayscale" />
|
||||
{activeList?.name}
|
||||
{title}
|
||||
</m.div>
|
||||
)
|
||||
}
|
||||
@@ -169,7 +168,9 @@ const TitleMetaHandler: Component<{
|
||||
} = useEntry(entryId)!
|
||||
|
||||
useEffect(() => {
|
||||
if (!isAtTop && entryTitle && feedTitle) { setEntryTitleMeta({ title: entryTitle, description: feedTitle }) }
|
||||
if (!isAtTop && entryTitle && feedTitle) {
|
||||
setEntryTitleMeta({ title: entryTitle, description: feedTitle })
|
||||
}
|
||||
return () => {
|
||||
setEntryTitleMeta(null)
|
||||
}
|
||||
|
||||
@@ -2,25 +2,21 @@ import {
|
||||
Collapsible,
|
||||
CollapsibleTrigger,
|
||||
} from "@renderer/components/ui/collapsible"
|
||||
import { useNavigateEntry } from "@renderer/hooks/biz/useNavigateEntry"
|
||||
import { useRouteParms } from "@renderer/hooks/biz/useRouteParams"
|
||||
import { levels } from "@renderer/lib/constants"
|
||||
import { showNativeMenu } from "@renderer/lib/native-menu"
|
||||
import { cn } from "@renderer/lib/utils"
|
||||
import type { FeedListModel } from "@renderer/models"
|
||||
import {
|
||||
feedActions,
|
||||
useUnreadStore,
|
||||
} from "@renderer/store"
|
||||
import { useUnreadStore } from "@renderer/store"
|
||||
import { AnimatePresence, m } from "framer-motion"
|
||||
import { useEffect, useState } from "react"
|
||||
import { useEffect, useMemo, useState } from "react"
|
||||
|
||||
import { useModalStack } from "../../components/ui/modal/stacked/hooks"
|
||||
import { CategoryRemoveDialogContent } from "./category-remove-dialog"
|
||||
import { CategoryRenameContent } from "./category-rename-dialog"
|
||||
import { FeedItem } from "./item"
|
||||
|
||||
const { setActiveList } = feedActions
|
||||
|
||||
export function FeedCategory({
|
||||
data,
|
||||
view,
|
||||
@@ -42,13 +38,17 @@ export function FeedCategory({
|
||||
}
|
||||
}, [expansion])
|
||||
|
||||
const navigate = useNavigateEntry()
|
||||
|
||||
const setCategoryActive = () => {
|
||||
if (view !== undefined) {
|
||||
setActiveList({
|
||||
navigate({
|
||||
entryId: null,
|
||||
// TODO joint feedId is too long, need to be optimized
|
||||
feedId: data.list.map((feed) => feed.feedId).join(","),
|
||||
level: levels.folder,
|
||||
id: data.list.map((feed) => feed.feedId).join(","),
|
||||
name: data.name,
|
||||
view,
|
||||
category: data.name,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -62,6 +62,13 @@ export function FeedCategory({
|
||||
(a, b) => (state.data[b.feedId] || 0) - (state.data[a.feedId] || 0),
|
||||
),
|
||||
)
|
||||
|
||||
const isActive = useMemo(
|
||||
() =>
|
||||
routerParams?.level === levels.folder &&
|
||||
routerParams.feedId === data.list.map((feed) => feed.feedId).join(","),
|
||||
[data.list, routerParams.feedId, routerParams?.level],
|
||||
)
|
||||
const { present } = useModalStack()
|
||||
return (
|
||||
<Collapsible
|
||||
@@ -73,9 +80,7 @@ export function FeedCategory({
|
||||
<div
|
||||
className={cn(
|
||||
"flex w-full items-center justify-between rounded-md px-2.5 transition-colors",
|
||||
routerParams?.level === levels.folder &&
|
||||
routerParams.name === data.name &&
|
||||
"bg-native-active",
|
||||
isActive && "bg-native-active",
|
||||
)}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
@@ -154,7 +159,7 @@ export function FeedCategory({
|
||||
{sortByUnreadFeedList.map((feed) => (
|
||||
<FeedItem
|
||||
key={feed.feedId}
|
||||
feed={feed}
|
||||
subscription={feed}
|
||||
view={view}
|
||||
className={data.name ? "pl-6" : "pl-2.5"}
|
||||
/>
|
||||
|
||||
@@ -15,23 +15,22 @@ import { levels } from "@renderer/lib/constants"
|
||||
import dayjs from "@renderer/lib/dayjs"
|
||||
import { showNativeMenu } from "@renderer/lib/native-menu"
|
||||
import { cn } from "@renderer/lib/utils"
|
||||
import type { SubscriptionResponse } from "@renderer/models"
|
||||
import { Queries } from "@renderer/queries"
|
||||
import {
|
||||
useUnreadStore,
|
||||
} from "@renderer/store"
|
||||
import type { SubscriptionPlainModel } from "@renderer/store"
|
||||
import { getFeedById, useFeedById, useUnreadStore } from "@renderer/store"
|
||||
import { useMutation } from "@tanstack/react-query"
|
||||
import { useCallback } from "react"
|
||||
import { toast } from "sonner"
|
||||
|
||||
import { FeedForm } from "../discover/feed-form"
|
||||
|
||||
type FeedItemData = SubscriptionPlainModel
|
||||
export function FeedItem({
|
||||
feed,
|
||||
subscription,
|
||||
view,
|
||||
className,
|
||||
}: {
|
||||
feed: SubscriptionResponse[number]
|
||||
subscription: FeedItemData
|
||||
view?: number
|
||||
className?: string
|
||||
}) {
|
||||
@@ -41,10 +40,11 @@ export function FeedItem({
|
||||
e.stopPropagation()
|
||||
if (view === undefined) return
|
||||
navigate({
|
||||
feedId: feed.feedId,
|
||||
feedId: subscription.feedId,
|
||||
entryId: null,
|
||||
view,
|
||||
level: levels.feed,
|
||||
category: null,
|
||||
})
|
||||
// focus to main container in order to let keyboard can navigate entry items by arrow keys
|
||||
requestAnimationFrame(() => {
|
||||
@@ -53,11 +53,11 @@ export function FeedItem({
|
||||
})
|
||||
})
|
||||
},
|
||||
[feed.feedId, navigate, view],
|
||||
[subscription.feedId, navigate, view],
|
||||
)
|
||||
|
||||
const deleteMutation = useMutation({
|
||||
mutationFn: async (feed: SubscriptionResponse[number]) =>
|
||||
mutationFn: async (feed: SubscriptionPlainModel) =>
|
||||
apiClient.subscriptions.$delete({
|
||||
json: {
|
||||
feedId: feed.feedId,
|
||||
@@ -67,13 +67,15 @@ export function FeedItem({
|
||||
onSuccess: (_, variables) => {
|
||||
Queries.subscription.byView(variables.view).invalidate()
|
||||
|
||||
const feed = getFeedById(variables.feedId)
|
||||
toast(
|
||||
<>
|
||||
Feed
|
||||
{" "}
|
||||
<i className="mr-px font-semibold">{variables.feeds.title}</i>
|
||||
<i className="mr-px font-semibold">{feed.title}</i>
|
||||
{" "}
|
||||
has been unfollowed.
|
||||
has been
|
||||
unfollowed.
|
||||
</>,
|
||||
{
|
||||
duration: 3000,
|
||||
@@ -82,14 +84,14 @@ export function FeedItem({
|
||||
onClick: async () => {
|
||||
await apiClient.subscriptions.$post({
|
||||
json: {
|
||||
url: variables.feeds.url,
|
||||
url: feed.url,
|
||||
view: variables.view,
|
||||
category: variables.category,
|
||||
isPrivate: variables.isPrivate,
|
||||
},
|
||||
})
|
||||
|
||||
Queries.subscription.byView(feed.view).invalidate()
|
||||
Queries.subscription.byView(variables.view).invalidate()
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -97,24 +99,31 @@ export function FeedItem({
|
||||
},
|
||||
})
|
||||
|
||||
const feedUnread = useUnreadStore((state) => state.data[feed.feedId] || 0)
|
||||
const feedUnread = useUnreadStore(
|
||||
(state) => state.data[subscription.feedId] || 0,
|
||||
)
|
||||
const { present } = useModalStack()
|
||||
|
||||
const routerParmas = useRouteParms()
|
||||
|
||||
const feed = useFeedById(subscription.feedId)
|
||||
|
||||
if (!feed) return null
|
||||
return (
|
||||
<div
|
||||
className={cn(
|
||||
"flex w-full items-center justify-between rounded-md py-[2px] pr-2.5 text-sm font-medium leading-loose",
|
||||
routerParmas?.level === levels.feed &&
|
||||
routerParmas.feedId === feed.feedId &&
|
||||
routerParmas.feedId === subscription.feedId &&
|
||||
"bg-native-active",
|
||||
className,
|
||||
)}
|
||||
onClick={handleNavigate}
|
||||
onDoubleClick={() => {
|
||||
window.open(
|
||||
`${import.meta.env.VITE_WEB_URL}/feed/${feed.feedId}?view=${view}`,
|
||||
`${import.meta.env.VITE_WEB_URL}/feed/${
|
||||
subscription.feedId
|
||||
}?view=${view}`,
|
||||
"_blank",
|
||||
)
|
||||
}}
|
||||
@@ -129,7 +138,11 @@ export function FeedItem({
|
||||
present({
|
||||
title: "Edit Feed",
|
||||
content: ({ dismiss }) => (
|
||||
<FeedForm asWidget id={feed.feedId} onSuccess={dismiss} />
|
||||
<FeedForm
|
||||
asWidget
|
||||
id={subscription.feedId}
|
||||
onSuccess={dismiss}
|
||||
/>
|
||||
),
|
||||
})
|
||||
},
|
||||
@@ -137,7 +150,7 @@ export function FeedItem({
|
||||
{
|
||||
type: "text",
|
||||
label: "Unfollow",
|
||||
click: () => deleteMutation.mutate(feed),
|
||||
click: () => deleteMutation.mutate(subscription),
|
||||
},
|
||||
{
|
||||
type: "separator",
|
||||
@@ -148,7 +161,7 @@ export function FeedItem({
|
||||
click: () =>
|
||||
window.open(
|
||||
`${import.meta.env.VITE_WEB_URL}/feed/${
|
||||
feed.feedId
|
||||
subscription.feedId
|
||||
}?view=${view}`,
|
||||
"_blank",
|
||||
),
|
||||
@@ -156,8 +169,12 @@ export function FeedItem({
|
||||
{
|
||||
type: "text",
|
||||
label: "Open Site in Browser",
|
||||
click: () =>
|
||||
feed.feeds.siteUrl && window.open(feed.feeds.siteUrl, "_blank"),
|
||||
click: () => {
|
||||
const feed = getFeedById(subscription.feedId)
|
||||
if (feed) {
|
||||
feed.siteUrl && window.open(feed.siteUrl, "_blank")
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
e,
|
||||
@@ -167,12 +184,12 @@ export function FeedItem({
|
||||
<div
|
||||
className={cn(
|
||||
"flex min-w-0 items-center",
|
||||
feed.feeds.errorAt && "text-red-900",
|
||||
feed.errorAt && "text-red-900",
|
||||
)}
|
||||
>
|
||||
<FeedIcon feed={feed.feeds} className="size-4" />
|
||||
<div className="truncate">{feed.feeds.title}</div>
|
||||
{feed.feeds.errorAt && (
|
||||
<FeedIcon feed={feed} className="size-4" />
|
||||
<div className="truncate">{feed.title}</div>
|
||||
{feed.errorAt && (
|
||||
<TooltipProvider delayDuration={300}>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
@@ -184,7 +201,7 @@ export function FeedItem({
|
||||
{" "}
|
||||
{dayjs
|
||||
.duration(
|
||||
dayjs(feed.feeds.errorAt).diff(dayjs(), "minute"),
|
||||
dayjs(feed.errorAt).diff(dayjs(), "minute"),
|
||||
"minute",
|
||||
)
|
||||
.humanize(true)}
|
||||
@@ -193,7 +210,7 @@ export function FeedItem({
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
)}
|
||||
{feed.isPrivate && (
|
||||
{subscription.isPrivate && (
|
||||
<TooltipProvider delayDuration={300}>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
|
||||
@@ -5,10 +5,13 @@ import { FEED_COLLECTION_LIST, levels, views } from "@renderer/lib/constants"
|
||||
import { stopPropagation } from "@renderer/lib/dom"
|
||||
import type { FeedViewType } from "@renderer/lib/enum"
|
||||
import { cn } from "@renderer/lib/utils"
|
||||
import type { FeedListModel, SubscriptionResponse } from "@renderer/models"
|
||||
import type {
|
||||
FeedListModel,
|
||||
} from "@renderer/models"
|
||||
import { Queries } from "@renderer/queries"
|
||||
import type { SubscriptionPlainModel } from "@renderer/store"
|
||||
import {
|
||||
feedActions,
|
||||
getFeedById,
|
||||
useSubscriptionByView,
|
||||
useUnreadStore,
|
||||
} from "@renderer/store"
|
||||
@@ -31,7 +34,7 @@ const useData = (view: FeedViewType) => {
|
||||
list: Record<
|
||||
string,
|
||||
{
|
||||
list: SubscriptionResponse
|
||||
list: SubscriptionPlainModel[]
|
||||
}
|
||||
>
|
||||
}
|
||||
@@ -39,8 +42,9 @@ const useData = (view: FeedViewType) => {
|
||||
const subscriptions = structuredClone(data)
|
||||
|
||||
for (const subscription of subscriptions) {
|
||||
if (!subscription.category && subscription.feeds.siteUrl) {
|
||||
const { domain } = parse(subscription.feeds.siteUrl)
|
||||
const feed = getFeedById(subscription.feedId)
|
||||
if (!subscription.category && feed.siteUrl) {
|
||||
const { domain } = parse(feed.siteUrl)
|
||||
if (domain) {
|
||||
if (!domains[domain]) {
|
||||
domains[domain] = 0
|
||||
@@ -51,11 +55,12 @@ const useData = (view: FeedViewType) => {
|
||||
}
|
||||
|
||||
for (const subscription of subscriptions) {
|
||||
const feed = getFeedById(subscription.feedId)
|
||||
if (!subscription.category) {
|
||||
if (subscription.feeds.siteUrl) {
|
||||
if (feed.siteUrl) {
|
||||
// FIXME @DIYgod
|
||||
// The logic here makes it impossible to remove the auto-generated category based on domain
|
||||
const { domain } = parse(subscription.feeds.siteUrl)
|
||||
const { domain } = parse(feed.siteUrl)
|
||||
if (domain && domains[domain] > 1) {
|
||||
subscription.category =
|
||||
domain.slice(0, 1).toUpperCase() + domain.slice(1)
|
||||
@@ -131,10 +136,10 @@ export function FeedList({
|
||||
onClick={(e) => {
|
||||
e.stopPropagation()
|
||||
if (view !== undefined) {
|
||||
feedActions.setActiveList({
|
||||
navigate({
|
||||
entryId: null,
|
||||
feedId: null,
|
||||
level: levels.view,
|
||||
id: view,
|
||||
name: views[view].name,
|
||||
view,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useBizInfiniteQuery, useBizQuery } from "@renderer/hooks"
|
||||
import { apiClient } from "@renderer/lib/api-fetch"
|
||||
import { defineQuery } from "@renderer/lib/defineQuery"
|
||||
import { entryActions } from "@renderer/store/entry/entry"
|
||||
import { entryActions } from "@renderer/store"
|
||||
|
||||
export const entries = {
|
||||
entries: ({
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { EntryModel } from "@renderer/models"
|
||||
import { useShallow } from "zustand/react/shallow"
|
||||
|
||||
import { useFeedIdByView } from "../subscription"
|
||||
import { useEntryStore } from "./entry"
|
||||
import { useEntryStore } from "./store"
|
||||
|
||||
interface EntryFilter {
|
||||
unread?: boolean
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
export * from "./entry"
|
||||
export * from "./hooks"
|
||||
export * from "./store"
|
||||
export * from "./types"
|
||||
|
||||
@@ -4,6 +4,7 @@ import type { EntryModel } from "@renderer/models"
|
||||
import { produce } from "immer"
|
||||
import { merge, omit } from "lodash-es"
|
||||
|
||||
import { feedActions } from "../feed"
|
||||
import { unreadActions } from "../unread"
|
||||
import { createZustandStore, getStoreActions } from "../utils/helper"
|
||||
import type { EntryActions, EntryState } from "./types"
|
||||
@@ -132,6 +133,10 @@ export const useEntryStore = createZustandStore<EntryState & EntryActions>(
|
||||
draft.flatMapEntries[entry.entries.id] || {},
|
||||
entry,
|
||||
)
|
||||
|
||||
const feeds = entries.map((entry) => entry.feeds)
|
||||
// Insert to feed store
|
||||
feedActions.upsertMany(feeds)
|
||||
}
|
||||
return draft
|
||||
}),
|
||||
@@ -1,38 +0,0 @@
|
||||
import type { ActiveEntryId, ActiveList } from "@renderer/models"
|
||||
import { create } from "zustand"
|
||||
|
||||
import { getStoreActions } from "./utils/helper"
|
||||
|
||||
interface FeedStoreActions {
|
||||
setActiveList: (value: ActiveList) => void
|
||||
setActiveEntry: (value: ActiveEntryId) => void
|
||||
}
|
||||
interface FeedStoreState {
|
||||
activeList: ActiveList
|
||||
activeEntryId: ActiveEntryId
|
||||
}
|
||||
|
||||
type FeedStore = FeedStoreState & Readonly<FeedStoreActions>
|
||||
export const useFeedStore = create<FeedStore>((set) => ({
|
||||
activeList: {
|
||||
level: "view",
|
||||
id: 0,
|
||||
name: "Articles",
|
||||
view: 0,
|
||||
},
|
||||
activeEntryId: null,
|
||||
activeEntryIndex: null,
|
||||
|
||||
// Actions
|
||||
setActiveEntry: (value) => set({ activeEntryId: value }),
|
||||
setActiveList: (value) => set({ activeList: value }),
|
||||
}))
|
||||
|
||||
export const feedActions = getStoreActions(useFeedStore)
|
||||
|
||||
export const getCurrentFeedId = () => useFeedStore.getState().activeList.id
|
||||
export const getCurrentEntryId = () => useFeedStore.getState().activeEntryId
|
||||
|
||||
/** Hooks */
|
||||
export const useFeedActiveList = () =>
|
||||
useFeedStore((state) => state.activeList)
|
||||
@@ -0,0 +1,23 @@
|
||||
import { useRouteParms } from "@renderer/hooks/biz/useRouteParams"
|
||||
import { ROUTE_FEED_PENDING, views } from "@renderer/lib/constants"
|
||||
import type { FeedModel } from "@renderer/models"
|
||||
import { useShallow } from "zustand/react/shallow"
|
||||
|
||||
import { useFeedStore } from "./store"
|
||||
|
||||
export const useFeedById = (feedId: Nullable<string>): FeedModel | null =>
|
||||
useFeedStore((state) => (feedId ? state.feeds[feedId] : null))
|
||||
|
||||
export const useFeedByIdSelector = <T>(
|
||||
feedId: Nullable<string>,
|
||||
selector: (feed: FeedModel) => T,
|
||||
) => useFeedStore(useShallow((state) => (feedId && state.feeds[feedId] ? selector(state.feeds[feedId]) : null)))
|
||||
|
||||
export const useFeedHeaderTitle = () => {
|
||||
const { feedId: currentFeedId, category, view } = useRouteParms()
|
||||
|
||||
const feedTitle = useFeedByIdSelector(currentFeedId, (feed) => feed.title)
|
||||
return currentFeedId === ROUTE_FEED_PENDING ?
|
||||
views[view].name :
|
||||
category || feedTitle
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export * from "./hooks"
|
||||
export * from "./store"
|
||||
export * from "./types"
|
||||
@@ -0,0 +1,39 @@
|
||||
import { produce } from "immer"
|
||||
|
||||
import { createZustandStore, getStoreActions } from "../utils/helper"
|
||||
import type { FeedActions, FeedState } from "./types"
|
||||
|
||||
export const useFeedStore = createZustandStore<FeedState & FeedActions>(
|
||||
"feed",
|
||||
{
|
||||
version: 1,
|
||||
},
|
||||
)((set) => ({
|
||||
feeds: {},
|
||||
clear() {
|
||||
set({ feeds: {} })
|
||||
},
|
||||
upsertMany(feeds) {
|
||||
set((state) =>
|
||||
produce(state, (state) => {
|
||||
for (const feed of feeds) {
|
||||
if (feed.id) { state.feeds[feed.id] = feed }
|
||||
}
|
||||
}),
|
||||
)
|
||||
},
|
||||
|
||||
optimisticUpdate(feedId, changed) {
|
||||
set((state) =>
|
||||
produce(state, (state) => {
|
||||
const feed = state.feeds[feedId]
|
||||
if (!feed) return
|
||||
|
||||
Object.assign(feed, changed)
|
||||
}),
|
||||
)
|
||||
},
|
||||
}))
|
||||
export const feedActions = getStoreActions(useFeedStore)
|
||||
|
||||
export const getFeedById = (feedId: string) => useFeedStore.getState().feeds[feedId]
|
||||
@@ -0,0 +1,13 @@
|
||||
import type { FeedModel } from "@renderer/models"
|
||||
|
||||
type FeedId = string
|
||||
|
||||
export interface FeedState {
|
||||
feeds: Record<FeedId, FeedModel>
|
||||
}
|
||||
|
||||
export interface FeedActions {
|
||||
upsertMany: (feeds: FeedModel[]) => void
|
||||
optimisticUpdate: (feedId: FeedId, changed: Partial<FeedModel>) => void
|
||||
clear: () => void
|
||||
}
|
||||
@@ -2,20 +2,23 @@ import { apiClient } from "@renderer/lib/api-fetch"
|
||||
import { FeedViewType } from "@renderer/lib/enum"
|
||||
import type { SubscriptionModel } from "@renderer/models"
|
||||
import { produce } from "immer"
|
||||
import { omit } from "lodash-es"
|
||||
|
||||
import { entryActions } from "./entry/entry"
|
||||
import { entryActions } from "./entry/store"
|
||||
import { feedActions } from "./feed"
|
||||
import { unreadActions } from "./unread"
|
||||
import { createZustandStore, getStoreActions } from "./utils/helper"
|
||||
|
||||
type FeedId = string
|
||||
export type SubscriptionPlainModel = Omit<SubscriptionModel, "feeds">
|
||||
interface SubscriptionState {
|
||||
data: Record<FeedId, SubscriptionModel>
|
||||
data: Record<FeedId, SubscriptionPlainModel>
|
||||
dataIdByView: Record<FeedViewType, FeedId[]>
|
||||
}
|
||||
|
||||
interface SubscriptionActions {
|
||||
upsert: (feedId: FeedId, subscription: SubscriptionModel) => void
|
||||
fetchByView: (view?: FeedViewType) => Promise<SubscriptionModel[]>
|
||||
upsertMany: (subscription: SubscriptionPlainModel[]) => void
|
||||
fetchByView: (view?: FeedViewType) => Promise<SubscriptionPlainModel[]>
|
||||
markReadByView: (view?: FeedViewType) => void
|
||||
internal_reset: () => void
|
||||
clear: () => void
|
||||
@@ -66,23 +69,20 @@ export const useSubscriptionStore = createZustandStore<
|
||||
}))
|
||||
}
|
||||
|
||||
set((state) =>
|
||||
produce(state, (state) => {
|
||||
res.data.forEach((subscription) => {
|
||||
state.data[subscription.feeds.id] = subscription
|
||||
state.dataIdByView[subscription.view].push(subscription.feeds.id)
|
||||
return state
|
||||
})
|
||||
}),
|
||||
)
|
||||
get().upsertMany(res.data)
|
||||
feedActions.upsertMany(res.data.map((s) => s.feeds))
|
||||
|
||||
return res.data
|
||||
},
|
||||
upsert: (feedId, subscription) => {
|
||||
upsertMany: (subscriptions) => {
|
||||
set((state) =>
|
||||
produce(state, (state) => {
|
||||
state.data[feedId] = subscription
|
||||
return state
|
||||
subscriptions.forEach((subscription) => {
|
||||
state.data[subscription.feedId] = omit(subscription, "feeds")
|
||||
state.dataIdByView[subscription.view].push(subscription.feedId)
|
||||
|
||||
return state
|
||||
})
|
||||
}),
|
||||
)
|
||||
},
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { entryActions } from "../entry/entry"
|
||||
import { entryActions } from "../entry/store"
|
||||
import { subscriptionActions } from "../subscription"
|
||||
import { uiActions } from "../ui"
|
||||
import { unreadActions } from "../unread"
|
||||
|
||||
Reference in New Issue
Block a user