From b5cfd8255b3e2610e8bfe2fc110241946f895d3d Mon Sep 17 00:00:00 2001 From: Stephen Zhou <38493346+hyoban@users.noreply.github.com> Date: Thu, 10 Oct 2024 10:15:07 +0800 Subject: [PATCH] chore: fix test --- .../src/modules/settings/tabs/lists/index.tsx | 23 ++++++++++++-- apps/renderer/src/store/list/hooks.ts | 31 +------------------ 2 files changed, 22 insertions(+), 32 deletions(-) diff --git a/apps/renderer/src/modules/settings/tabs/lists/index.tsx b/apps/renderer/src/modules/settings/tabs/lists/index.tsx index 00da05db1..115c6765d 100644 --- a/apps/renderer/src/modules/settings/tabs/lists/index.tsx +++ b/apps/renderer/src/modules/settings/tabs/lists/index.tsx @@ -1,4 +1,6 @@ import { WEB_URL } from "@follow/shared/constants" +import { useMutation } from "@tanstack/react-query" +import { toast } from "sonner" import { Avatar, AvatarImage } from "~/components/ui/avatar" import { Button } from "~/components/ui/button" @@ -17,10 +19,11 @@ import { import { Tooltip, TooltipContent, TooltipPortal, TooltipTrigger } from "~/components/ui/tooltip" import { views } from "~/constants" import { useAuthQuery, useI18n } from "~/hooks/common" +import { apiClient } from "~/lib/api-fetch" import { cn } from "~/lib/utils" import { Balance } from "~/modules/wallet/balance" import { Queries } from "~/queries" -import { useDeleteFeedList } from "~/store/list" +import { listActions } from "~/store/list" import { ListCreationModalContent, ListFeedsModalContent } from "./modals" @@ -30,7 +33,23 @@ export const SettingLists = () => { const { present } = useModalStack() - const deleteFeedList = useDeleteFeedList() + const deleteFeedList = useMutation({ + mutationFn: async (payload: { listId: string }) => { + listActions.deleteList(payload.listId) + await apiClient.lists.$delete({ + json: { + listId: payload.listId, + }, + }) + }, + onSuccess: () => { + toast.success(t.settings("lists.delete.success")) + Queries.lists.list().invalidate() + }, + async onError() { + toast.error(t.settings("lists.delete.error")) + }, + }) return (
diff --git a/apps/renderer/src/store/list/hooks.ts b/apps/renderer/src/store/list/hooks.ts index e9bffbe44..05e75e90d 100644 --- a/apps/renderer/src/store/list/hooks.ts +++ b/apps/renderer/src/store/list/hooks.ts @@ -1,13 +1,7 @@ -import { useMutation } from "@tanstack/react-query" -import { useTranslation } from "react-i18next" -import { toast } from "sonner" - -import { apiClient } from "~/lib/api-fetch" import type { FeedViewType } from "~/lib/enum" import type { ListModel } from "~/models" -import { Queries } from "~/queries" -import { listActions, useListStore } from "./store" +import { useListStore } from "./store" export const useListById = (listId: Nullable): ListModel | null => useListStore((state) => (listId ? state.lists[listId] : null)) @@ -15,26 +9,3 @@ export const useListById = (listId: Nullable): ListModel | null => export const useListByView = (view: FeedViewType) => { return useListStore((state) => Object.values(state.lists).filter((list) => list.view === view)) } - -export const useDeleteFeedList = (options?: { onSuccess: () => void; onError: () => void }) => { - const { t } = useTranslation("settings") - return useMutation({ - mutationFn: async (payload: { listId: string }) => { - listActions.deleteList(payload.listId) - await apiClient.lists.$delete({ - json: { - listId: payload.listId, - }, - }) - }, - onSuccess: () => { - toast.success(t("lists.delete.success")) - Queries.lists.list().invalidate() - options?.onSuccess?.() - }, - async onError() { - toast.error(t("lists.delete.error")) - options?.onError?.() - }, - }) -}