feat: refresh feed (#94)
* feat: refresh feed Signed-off-by: Innei <i@innei.in> * feat: refresh owned feed Signed-off-by: Innei <i@innei.in> --------- Signed-off-by: Innei <i@innei.in>
This commit is contained in:
parent
5cc7898e1e
commit
bbde62f630
|
|
@ -0,0 +1 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none"><path fill="#fff" fill-opacity=".01" d="M24 0v24H0V0z"/><path fill="#10161F" d="m14.33 3.307-.26.966zM2.9 7.85a1 1 0 1 0 1.821.828zm16.886 3.537a1 1 0 1 0 .428-1.954zM9.67 20.693l.26-.966zm11.43-4.542a1 1 0 0 0-1.821-.828zM4.213 12.613a1 1 0 1 0-.428 1.954zm1.616 1.18.558-.828zm-.078.181-.214.977zm12.418-3.767.56-.83zm.078-.181.214-.977zm1.987 1.572-.56.829zm.731-.408-.996.09zm-.172-.422-2.065-1.39-1.117 1.658 2.064 1.39zM4.72 8.678a8.002 8.002 0 0 1 9.35-4.405l.517-1.932c-4.79-1.284-9.7 1.138-11.687 5.509zm13.312 2.325 1.753.384.428-1.954-1.752-.384zm-14.826 2.23 2.064 1.39 1.117-1.658-2.064-1.391zm16.072 2.09a8.002 8.002 0 0 1-9.35 4.404l-.517 1.932c4.79 1.284 9.7-1.138 11.687-5.508zM5.967 12.998l-1.753-.385-.428 1.954 1.752.384zm8.104-8.725a8.004 8.004 0 0 1 5.9 7.007l1.991-.18c-.367-4.056-3.208-7.643-7.374-8.759zM9.929 19.728a8.004 8.004 0 0 1-5.9-7.008l-1.991.18c.367 4.056 3.208 7.643 7.374 8.76zm-4.658-5.105c-.823-.555-.274-1.838.696-1.625l-.429 1.953c1.185.26 1.857-1.309.85-1.987zm13.458-5.246c.823.555.274 1.838-.696 1.626l.429-1.954c-1.185-.26-1.857 1.309-.85 1.987zM4.324 11.574c-.943-.636-2.407-.009-2.286 1.326l1.992-.18a.56.56 0 0 1-.287.532.52.52 0 0 1-.536-.02zm15.352.853c.943.635 2.407.008 2.286-1.327l-1.992.18a.56.56 0 0 1 .287-.531.52.52 0 0 1 .537.02z"/></svg>
|
||||
|
After Width: | Height: | Size: 1.3 KiB |
|
|
@ -67,3 +67,22 @@ export function getOS(): OS {
|
|||
|
||||
// eslint-disable-next-line no-control-regex
|
||||
export const isASCII = (str) => /^[\u0000-\u007F]*$/.test(str)
|
||||
|
||||
export const isBizId = (id) => {
|
||||
if (!id) return false
|
||||
|
||||
// id is uuid or snowflake
|
||||
|
||||
// 0. check is uuid
|
||||
if (id.length === 36 && id[8] === "-" && id[13] === "-" && id[18] === "-" && id[23] === "-") {
|
||||
return true
|
||||
}
|
||||
|
||||
// 1. check is snowflake
|
||||
// snowflake ep 1712546615000
|
||||
if (id.length > 16 && id.length < 20 && !Number.isNaN(id)) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { useMainContainerElement } from "@renderer/atoms"
|
||||
import { useUser } from "@renderer/atoms/user"
|
||||
import { ActionButton, StyledButton } from "@renderer/components/ui/button"
|
||||
import {
|
||||
Popover,
|
||||
|
|
@ -17,11 +18,13 @@ import { apiClient } from "@renderer/lib/api-fetch"
|
|||
import { views } from "@renderer/lib/constants"
|
||||
import { buildStorageNS } from "@renderer/lib/ns"
|
||||
import { shortcuts } from "@renderer/lib/shortcuts"
|
||||
import { cn, getEntriesParams, getOS } from "@renderer/lib/utils"
|
||||
import { cn, getEntriesParams, getOS, isBizId } from "@renderer/lib/utils"
|
||||
import { useEntries } from "@renderer/queries/entries"
|
||||
import { useRefreshFeedMutation } from "@renderer/queries/feed"
|
||||
import {
|
||||
entryActions,
|
||||
subscriptionActions,
|
||||
useFeedById,
|
||||
useFeedHeaderTitle,
|
||||
} from "@renderer/store"
|
||||
import {
|
||||
|
|
@ -276,9 +279,7 @@ const ListHeader: FC<{
|
|||
|
||||
const titleAtBottom = window.electron && os === "macOS"
|
||||
const titleInfo = (
|
||||
<div
|
||||
className={!titleAtBottom ? "min-w-0 translate-y-1" : void 0}
|
||||
>
|
||||
<div className={!titleAtBottom ? "min-w-0 translate-y-1" : void 0}>
|
||||
<div className="min-w-0 break-all text-lg font-bold leading-none">
|
||||
<EllipsisHorizontalTextWithTooltip className="inline-block !w-auto max-w-full">
|
||||
{headerTitle}
|
||||
|
|
@ -293,6 +294,13 @@ const ListHeader: FC<{
|
|||
</div>
|
||||
</div>
|
||||
)
|
||||
const { mutateAsync: refreshFeed, isPending } = useRefreshFeedMutation(
|
||||
routerParams.feedId,
|
||||
)
|
||||
|
||||
const user = useUser()
|
||||
|
||||
const feed = useFeedById(routerParams.feedId)
|
||||
return (
|
||||
<div className="mb-5 flex w-full flex-col pl-11 pr-4 pt-2.5">
|
||||
<div
|
||||
|
|
@ -303,6 +311,23 @@ const ListHeader: FC<{
|
|||
>
|
||||
{!titleAtBottom && titleInfo}
|
||||
<div className="relative z-[1] flex items-center gap-1 self-baseline text-zinc-500">
|
||||
{feed?.ownerUserId === user?.id &&
|
||||
isBizId(routerParams.feedId) && (
|
||||
<ActionButton
|
||||
tooltip="Refresh"
|
||||
// shortcut={shortcuts.entries.toggleUnreadOnly.key}
|
||||
onClick={() => {
|
||||
refreshFeed()
|
||||
}}
|
||||
>
|
||||
<i
|
||||
className={cn(
|
||||
"i-mgc-refresh-2-cute-re",
|
||||
isPending && "animate-spin",
|
||||
)}
|
||||
/>
|
||||
</ActionButton>
|
||||
)}
|
||||
<ActionButton
|
||||
tooltip={`${unreadOnly ? "Unread Only" : "All"}`}
|
||||
shortcut={shortcuts.entries.toggleUnreadOnly.key}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ export const entries = {
|
|||
read?: boolean
|
||||
}) =>
|
||||
defineQuery(
|
||||
["entries", level, id, view, read],
|
||||
["entries", id, level, view, read],
|
||||
async ({ pageParam }) =>
|
||||
entryActions.fetchEntries({
|
||||
level,
|
||||
|
|
@ -27,7 +27,7 @@ export const entries = {
|
|||
pageParam: pageParam as string,
|
||||
}),
|
||||
{
|
||||
rootKey: ["entries"],
|
||||
rootKey: ["entries", id],
|
||||
},
|
||||
),
|
||||
byId: (id: string) =>
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import { feedActions } from "@renderer/store"
|
|||
import { useMutation } from "@tanstack/react-query"
|
||||
import { toast } from "sonner"
|
||||
|
||||
import { Queries } from "."
|
||||
|
||||
export const feed = {
|
||||
byId: ({ id, url }: { id?: string, url?: string }) =>
|
||||
defineQuery(
|
||||
|
|
@ -58,3 +60,18 @@ export const useClaimFeedMutation = (feedId: string) => useMutation({
|
|||
})
|
||||
},
|
||||
})
|
||||
|
||||
export const useRefreshFeedMutation = (feedId?: string) => useMutation({
|
||||
mutationKey: ["refreshFeed", feedId],
|
||||
mutationFn: () => apiClient.feeds.refresh.$get({ query: { id: feedId! } }),
|
||||
|
||||
onSuccess() {
|
||||
if (!feedId) return
|
||||
Queries.entries.entries({
|
||||
id: feedId!,
|
||||
}).invalidateRoot()
|
||||
},
|
||||
async onError(err) {
|
||||
toast.error(await getFetchErrorMessage(err))
|
||||
},
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue