chore: fix test

This commit is contained in:
Stephen Zhou
2024-10-10 10:15:07 +08:00
parent c881d799e2
commit b5cfd8255b
2 changed files with 22 additions and 32 deletions
@@ -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 (
<section className="mt-4">
+1 -30
View File
@@ -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<string>): ListModel | null =>
useListStore((state) => (listId ? state.lists[listId] : null))
@@ -15,26 +9,3 @@ export const useListById = (listId: Nullable<string>): 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?.()
},
})
}