feat: native delete dialog
This commit is contained in:
parent
9c662c1516
commit
6c105afde2
|
|
@ -1,19 +1,15 @@
|
|||
import { tipc } from "@egoist/tipc/main"
|
||||
import { Menu } from "electron"
|
||||
import { Menu, MessageBoxOptions, dialog } from "electron"
|
||||
|
||||
const t = tipc.create()
|
||||
|
||||
export const router = {
|
||||
sum: t.procedure
|
||||
.input<{ a: number; b: number }>()
|
||||
.action(async ({ input }) => {
|
||||
return input.a + input.b
|
||||
}),
|
||||
inspectElement: t.procedure
|
||||
.input<{ x: number; y: number }>()
|
||||
.action(async ({ input, context }) => {
|
||||
context.sender.inspectElement(input.x, input.y)
|
||||
}),
|
||||
|
||||
showContextMenu: t.procedure
|
||||
.input<{
|
||||
items: Array<{ type: "text"; label: string } | { type: "separator" }>
|
||||
|
|
@ -41,6 +37,22 @@ export const router = {
|
|||
},
|
||||
})
|
||||
}),
|
||||
|
||||
showConfirmDialog: t.procedure
|
||||
.input<{
|
||||
title: string
|
||||
message: string
|
||||
options?: Partial<MessageBoxOptions>
|
||||
}>()
|
||||
.action(async ({ input }) => {
|
||||
const result = await dialog.showMessageBox({
|
||||
message: input.title,
|
||||
detail: input.message,
|
||||
buttons: ["Confirm", "Cancel"],
|
||||
...input.options,
|
||||
})
|
||||
return result.response === 0
|
||||
}),
|
||||
}
|
||||
|
||||
export type Router = typeof router
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@ import {
|
|||
import { FeedIcon } from "@renderer/components/feed-icon"
|
||||
import dayjs from "@renderer/lib/dayjs"
|
||||
import { showNativeMenu } from "@renderer/lib/native-menu"
|
||||
import { client } from "@renderer/lib/client"
|
||||
import { useMutation, useQueryClient } from "@tanstack/react-query"
|
||||
import { apiFetch } from "@renderer/lib/queries/api-fetch"
|
||||
|
||||
export function FeedList({
|
||||
className,
|
||||
|
|
@ -90,6 +93,23 @@ function FeedCategory({
|
|||
}) {
|
||||
const [open, setOpen] = useState(!data.name)
|
||||
|
||||
const queryClient = useQueryClient()
|
||||
const deleteMutation = useMutation({
|
||||
mutationFn: async () =>
|
||||
apiFetch("/categories", {
|
||||
method: "DELETE",
|
||||
body: {
|
||||
feedIdList: data.list.map((feed) => feed.feedId),
|
||||
deleteSubscriptions: false,
|
||||
},
|
||||
}),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ["subscriptions", view],
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
const setFeedActive = (feed: SubscriptionResponse[number]) => {
|
||||
view !== undefined &&
|
||||
setActivedList?.({
|
||||
|
|
@ -145,7 +165,19 @@ function FeedCategory({
|
|||
{
|
||||
type: "text",
|
||||
label: "Delete Category",
|
||||
click: async () => {},
|
||||
click: async () => {
|
||||
if (
|
||||
await client.showConfirmDialog({
|
||||
title: `Delete Category ${data.name}?`,
|
||||
message: `This operation will delete your category, but the feeds it contains will be retained and grouped by website.`,
|
||||
options: {
|
||||
buttons: ["Delete", "Cancel"],
|
||||
},
|
||||
})
|
||||
) {
|
||||
deleteMutation.mutate()
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
e,
|
||||
|
|
|
|||
Loading…
Reference in New Issue