Skip to content

Commit 9066758

Browse files
authored
feat: reset feed (#1419)
1 parent dccfaaf commit 9066758

File tree

5 files changed

+62
-1
lines changed

5 files changed

+62
-1
lines changed

apps/renderer/src/hooks/biz/useFeedActions.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
useAddFeedToFeedList,
2222
useFeedById,
2323
useRemoveFeedFromFeedList,
24+
useResetFeed,
2425
} from "~/store/feed"
2526
import { useInboxById } from "~/store/inbox"
2627
import { useListById, useOwnedListByView } from "~/store/list"
@@ -83,6 +84,7 @@ export const useFeedActions = ({
8384

8485
const { mutateAsync: addFeedToListMutation } = useAddFeedToFeedList()
8586
const { mutateAsync: removeFeedFromListMutation } = useRemoveFeedFromFeedList()
87+
const { mutateAsync: resetFeed } = useResetFeed()
8688
const openBoostModal = useBoostModal()
8789

8890
const listByView = useOwnedListByView(view!)
@@ -93,6 +95,8 @@ export const useFeedActions = ({
9395
const related = feed || inbox
9496
if (!related) return []
9597

98+
const isFeedOwner = related.ownerUserId === whoami()?.id
99+
96100
const items: MenuItemInput[] = [
97101
{
98102
type: "text" as const,
@@ -117,12 +121,19 @@ export const useFeedActions = ({
117121
claimFeed()
118122
},
119123
},
120-
...(related.ownerUserId === whoami()?.id
124+
...(isFeedOwner
121125
? [
122126
{
123127
type: "text" as const,
124128
label: t("sidebar.feed_actions.feed_owned_by_you"),
125129
},
130+
{
131+
type: "text" as const,
132+
label: t("sidebar.feed_actions.reset_feed"),
133+
click: () => {
134+
resetFeed(feedId)
135+
},
136+
},
126137
]
127138
: []),
128139
{

apps/renderer/src/store/feed/hooks.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
import { views } from "@follow/constants"
22
import type { FeedModel, FeedOrListRespModel, InboxModel, ListModel } from "@follow/models/types"
33
import { useMutation } from "@tanstack/react-query"
4+
import { useRef } from "react"
45
import { useTranslation } from "react-i18next"
56
import { toast } from "sonner"
67
import { useShallow } from "zustand/react/shallow"
78

89
import { FEED_COLLECTION_LIST, ROUTE_FEED_IN_FOLDER, ROUTE_FEED_PENDING } from "~/constants"
910
import { useRouteParams } from "~/hooks/biz/useRouteParams"
1011
import { apiClient } from "~/lib/api-fetch"
12+
import { entries } from "~/queries/entries"
1113

1214
import { useInboxStore } from "../inbox"
1315
import { listActions, useListStore } from "../list"
@@ -137,3 +139,28 @@ export const useRemoveFeedFromFeedList = (options?: {
137139
},
138140
})
139141
}
142+
143+
export const useResetFeed = () => {
144+
const { t } = useTranslation()
145+
const toastIDRef = useRef<string | number | null>(null)
146+
147+
return useMutation({
148+
mutationFn: async (feedId: string) => {
149+
toastIDRef.current = toast.loading(t("sidebar.feed_actions.resetting_feed"))
150+
await apiClient.feeds.reset.$get({ query: { id: feedId } })
151+
},
152+
onSuccess: (_, feedId) => {
153+
entries.entries({ feedId }).invalidateRoot()
154+
toast.success(
155+
t("sidebar.feed_actions.reset_feed_success"),
156+
toastIDRef.current ? { id: toastIDRef.current } : undefined,
157+
)
158+
},
159+
onError: () => {
160+
toast.error(
161+
t("sidebar.feed_actions.reset_feed_error"),
162+
toastIDRef.current ? { id: toastIDRef.current } : undefined,
163+
)
164+
},
165+
})
166+
}

changelog/next.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## New Features
44

5+
- Feed owners can now reset their feeds.
6+
57
## Improvements
68

79
## Bug Fixes

locales/app/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@
295295
"sidebar.feed_actions.open_feed_in_browser": "Open Feed in {{which}}",
296296
"sidebar.feed_actions.open_list_in_browser": "Open List in {{which}}",
297297
"sidebar.feed_actions.open_site_in_browser": "Open Site in {{which}}",
298+
"sidebar.feed_actions.reset_feed": "Reset Feed",
299+
"sidebar.feed_actions.reset_feed_error": "Failed to reset feed.",
300+
"sidebar.feed_actions.reset_feed_success": "Feed reset successfully.",
301+
"sidebar.feed_actions.resetting_feed": "Resetting feed...",
298302
"sidebar.feed_actions.unfollow": "Unfollow",
299303
"sidebar.feed_actions.unfollow_feed": "Unfollow Feed",
300304
"sidebar.feed_actions.unfollow_feed_many": "Unfollow all selected feeds",

packages/shared/src/hono.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6424,6 +6424,20 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
64246424
status: 200;
64256425
};
64266426
};
6427+
"/feeds/reset": {
6428+
$get: {
6429+
input: {
6430+
query: {
6431+
id: string | string[];
6432+
};
6433+
};
6434+
output: {
6435+
code: 0;
6436+
};
6437+
outputFormat: "json" | "text";
6438+
status: 200;
6439+
};
6440+
};
64276441
} & {
64286442
"/entries/inbox": {
64296443
$post: {
@@ -7034,7 +7048,9 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
70347048
input: {
70357049
query: {
70367050
category?: string | string[] | undefined;
7051+
categories?: string | string[] | undefined;
70377052
namespace?: string | string[] | undefined;
7053+
lang?: string | string[] | undefined;
70387054
};
70397055
};
70407056
output: {
@@ -7043,6 +7059,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
70437059
description: string;
70447060
name: string;
70457061
url: string;
7062+
lang: string;
70467063
routes: {
70477064
[x: string]: {
70487065
description: string;

0 commit comments

Comments
 (0)