Skip to content

Commit

Permalink
feat: refresh feed (#94)
Browse files Browse the repository at this point in the history
* feat: refresh feed

Signed-off-by: Innei <[email protected]>

* feat: refresh owned feed

Signed-off-by: Innei <[email protected]>

---------

Signed-off-by: Innei <[email protected]>
  • Loading branch information
Innei authored Jun 27, 2024
1 parent 5cc7898 commit bbde62f
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 6 deletions.
1 change: 1 addition & 0 deletions icons/mgc/refresh_2_cute_re.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions src/renderer/src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
33 changes: 29 additions & 4 deletions src/renderer/src/modules/entry-column/index.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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}
Expand All @@ -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
Expand All @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/src/queries/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -27,7 +27,7 @@ export const entries = {
pageParam: pageParam as string,
}),
{
rootKey: ["entries"],
rootKey: ["entries", id],
},
),
byId: (id: string) =>
Expand Down
17 changes: 17 additions & 0 deletions src/renderer/src/queries/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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))
},
})

0 comments on commit bbde62f

Please sign in to comment.