|
1 | 1 | import { views } from "@follow/constants"
|
2 | 2 | import type { FeedModel, FeedOrListRespModel, InboxModel, ListModel } from "@follow/models/types"
|
3 | 3 | import { useMutation } from "@tanstack/react-query"
|
| 4 | +import { useRef } from "react" |
4 | 5 | import { useTranslation } from "react-i18next"
|
5 | 6 | import { toast } from "sonner"
|
6 | 7 | import { useShallow } from "zustand/react/shallow"
|
7 | 8 |
|
8 | 9 | import { FEED_COLLECTION_LIST, ROUTE_FEED_IN_FOLDER, ROUTE_FEED_PENDING } from "~/constants"
|
9 | 10 | import { useRouteParams } from "~/hooks/biz/useRouteParams"
|
10 | 11 | import { apiClient } from "~/lib/api-fetch"
|
| 12 | +import { entries } from "~/queries/entries" |
11 | 13 |
|
12 | 14 | import { useInboxStore } from "../inbox"
|
13 | 15 | import { listActions, useListStore } from "../list"
|
@@ -137,3 +139,28 @@ export const useRemoveFeedFromFeedList = (options?: {
|
137 | 139 | },
|
138 | 140 | })
|
139 | 141 | }
|
| 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 | +} |
0 commit comments