Skip to content

Commit

Permalink
feat: reset feed (RSSNext#1419)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyoban authored Nov 5, 2024
1 parent dccfaaf commit 9066758
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 1 deletion.
13 changes: 12 additions & 1 deletion apps/renderer/src/hooks/biz/useFeedActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
useAddFeedToFeedList,
useFeedById,
useRemoveFeedFromFeedList,
useResetFeed,
} from "~/store/feed"
import { useInboxById } from "~/store/inbox"
import { useListById, useOwnedListByView } from "~/store/list"
Expand Down Expand Up @@ -83,6 +84,7 @@ export const useFeedActions = ({

const { mutateAsync: addFeedToListMutation } = useAddFeedToFeedList()
const { mutateAsync: removeFeedFromListMutation } = useRemoveFeedFromFeedList()
const { mutateAsync: resetFeed } = useResetFeed()
const openBoostModal = useBoostModal()

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

const isFeedOwner = related.ownerUserId === whoami()?.id

const items: MenuItemInput[] = [
{
type: "text" as const,
Expand All @@ -117,12 +121,19 @@ export const useFeedActions = ({
claimFeed()
},
},
...(related.ownerUserId === whoami()?.id
...(isFeedOwner
? [
{
type: "text" as const,
label: t("sidebar.feed_actions.feed_owned_by_you"),
},
{
type: "text" as const,
label: t("sidebar.feed_actions.reset_feed"),
click: () => {
resetFeed(feedId)
},
},
]
: []),
{
Expand Down
27 changes: 27 additions & 0 deletions apps/renderer/src/store/feed/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { views } from "@follow/constants"
import type { FeedModel, FeedOrListRespModel, InboxModel, ListModel } from "@follow/models/types"
import { useMutation } from "@tanstack/react-query"
import { useRef } from "react"
import { useTranslation } from "react-i18next"
import { toast } from "sonner"
import { useShallow } from "zustand/react/shallow"

import { FEED_COLLECTION_LIST, ROUTE_FEED_IN_FOLDER, ROUTE_FEED_PENDING } from "~/constants"
import { useRouteParams } from "~/hooks/biz/useRouteParams"
import { apiClient } from "~/lib/api-fetch"
import { entries } from "~/queries/entries"

import { useInboxStore } from "../inbox"
import { listActions, useListStore } from "../list"
Expand Down Expand Up @@ -137,3 +139,28 @@ export const useRemoveFeedFromFeedList = (options?: {
},
})
}

export const useResetFeed = () => {
const { t } = useTranslation()
const toastIDRef = useRef<string | number | null>(null)

return useMutation({
mutationFn: async (feedId: string) => {
toastIDRef.current = toast.loading(t("sidebar.feed_actions.resetting_feed"))
await apiClient.feeds.reset.$get({ query: { id: feedId } })
},
onSuccess: (_, feedId) => {
entries.entries({ feedId }).invalidateRoot()
toast.success(
t("sidebar.feed_actions.reset_feed_success"),
toastIDRef.current ? { id: toastIDRef.current } : undefined,
)
},
onError: () => {
toast.error(
t("sidebar.feed_actions.reset_feed_error"),
toastIDRef.current ? { id: toastIDRef.current } : undefined,
)
},
})
}
2 changes: 2 additions & 0 deletions changelog/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## New Features

- Feed owners can now reset their feeds.

## Improvements

## Bug Fixes
4 changes: 4 additions & 0 deletions locales/app/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,10 @@
"sidebar.feed_actions.open_feed_in_browser": "Open Feed in {{which}}",
"sidebar.feed_actions.open_list_in_browser": "Open List in {{which}}",
"sidebar.feed_actions.open_site_in_browser": "Open Site in {{which}}",
"sidebar.feed_actions.reset_feed": "Reset Feed",
"sidebar.feed_actions.reset_feed_error": "Failed to reset feed.",
"sidebar.feed_actions.reset_feed_success": "Feed reset successfully.",
"sidebar.feed_actions.resetting_feed": "Resetting feed...",
"sidebar.feed_actions.unfollow": "Unfollow",
"sidebar.feed_actions.unfollow_feed": "Unfollow Feed",
"sidebar.feed_actions.unfollow_feed_many": "Unfollow all selected feeds",
Expand Down
17 changes: 17 additions & 0 deletions packages/shared/src/hono.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6424,6 +6424,20 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
status: 200;
};
};
"/feeds/reset": {
$get: {
input: {
query: {
id: string | string[];
};
};
output: {
code: 0;
};
outputFormat: "json" | "text";
status: 200;
};
};
} & {
"/entries/inbox": {
$post: {
Expand Down Expand Up @@ -7034,7 +7048,9 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
input: {
query: {
category?: string | string[] | undefined;
categories?: string | string[] | undefined;
namespace?: string | string[] | undefined;
lang?: string | string[] | undefined;
};
};
output: {
Expand All @@ -7043,6 +7059,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
description: string;
name: string;
url: string;
lang: string;
routes: {
[x: string]: {
description: string;
Expand Down

0 comments on commit 9066758

Please sign in to comment.