feat: delete inbox entry

This commit is contained in:
Stephen Zhou 2024-10-21 20:54:14 +08:00
parent 41e090d529
commit a9e1f581b2
No known key found for this signature in database
6 changed files with 69 additions and 1 deletions

View File

@ -127,6 +127,21 @@ export const useUnread = () =>
}),
})
export const useDeleteInboxEntry = () => {
const { t } = useTranslation()
return useMutation({
mutationFn: async (entryId: string) => {
await entryActions.deleteInboxEntry(entryId)
},
onSuccess: () => {
toast.success(t("entry_actions.deleted"))
},
onError: () => {
toast.error(t("entry_actions.failed_to_delete"))
},
})
}
export const useEntryActions = ({
view,
entry,
@ -216,6 +231,8 @@ export const useEntryActions = ({
refetchOnWindowFocus: false,
})
const deleteInboxEntry = useDeleteInboxEntry()
const items = useMemo(() => {
if (!populatedEntry || view === undefined) return []
const items: {
@ -456,6 +473,14 @@ export const useEntryActions = ({
uncollect.mutate()
},
},
{
key: "delete",
name: t("entry_actions.delete"),
hide: !isInbox,
onClick: () => {
deleteInboxEntry.mutate(populatedEntry.entries.id)
},
},
{
key: "copyLink",
name: t("entry_actions.copy_link"),

View File

@ -138,6 +138,7 @@ export const useFeedActions = ({
type: "text" as const,
label: isEntryList ? t("sidebar.feed_actions.edit_feed") : t("sidebar.feed_actions.edit"),
shortcut: "E",
disabled: isInbox,
click: () => {
present({
title: t("sidebar.feed_actions.edit_feed"),

View File

@ -442,6 +442,31 @@ class EntryActions {
},
}))
}
async deleteInboxEntry(entryId: string) {
const entry = get().flatMapEntries[entryId]
if (!entry) return
set((state) =>
produce(state, (draft) => {
delete draft.flatMapEntries[entryId]
for (const feedId in draft.entries) {
const index = draft.entries[feedId].indexOf(entryId)
if (index !== -1) {
draft.entries[feedId].splice(index, 1)
}
}
}),
)
await doMutationAndTransaction(
async () => {
await apiClient.entries.inbox.$delete({ json: { entryId } })
},
async () => {
await EntryService.deleteEntries([entryId])
},
)
}
}
export const entryActions = new EntryActions()

View File

@ -57,6 +57,9 @@
"entry_actions.copied_notify": "{{which}} copied to clipboard.",
"entry_actions.copy_link": "Copy Link",
"entry_actions.copy_title": "Copy Title",
"entry_actions.delete": "Delete",
"entry_actions.deleted": "Deleted.",
"entry_actions.failed_to_delete": "Failed to delete.",
"entry_actions.failed_to_save_to_eagle": "Failed to save to Eagle.",
"entry_actions.failed_to_save_to_instapaper": "Failed to save to Instapaper.",
"entry_actions.failed_to_save_to_obsidian": "Failed to save to Obsidian",

View File

@ -41,5 +41,6 @@
"9001": "Achievement already received",
"10000": "Inbox not found",
"10001": "Inbox already exists",
"10002": "Inbox limit exceeded"
"10002": "Inbox limit exceeded",
"10003": "Inbox permission denied"
}

View File

@ -5927,6 +5927,18 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
outputFormat: "json" | "text";
status: 200;
};
$delete: {
input: {
json: {
entryId: string;
};
};
output: {
code: 0;
};
outputFormat: "json" | "text";
status: 200;
};
};
"/entries/read-histories/:id": {
$get: {
@ -6360,6 +6372,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
$get: {
input: {
query: {
route?: string | string[] | undefined;
category?: string | string[] | undefined;
namespace?: string | string[] | undefined;
};