chore: improve tag delete
This commit is contained in:
@@ -227,7 +227,18 @@ func (a *App) handleDeleteMailLabel(w http.ResponseWriter, r *http.Request) {
|
|||||||
badRequest(w, fmt.Errorf("label id is required"))
|
badRequest(w, fmt.Errorf("label id is required"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
result, err := a.db.ExecContext(r.Context(), `DELETE FROM mail_labels WHERE id=? AND mailbox_id=?`, labelID, mb.ID)
|
ctx := r.Context()
|
||||||
|
tx, err := a.db.BeginTx(ctx, nil)
|
||||||
|
if err != nil {
|
||||||
|
respondError(w, http.StatusInternalServerError, "failed to begin transaction")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer tx.Rollback()
|
||||||
|
if _, err := tx.ExecContext(ctx, `DELETE FROM message_labels WHERE label_id=?`, labelID); err != nil {
|
||||||
|
respondError(w, http.StatusInternalServerError, "failed to remove label associations")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
result, err := tx.ExecContext(ctx, `DELETE FROM mail_labels WHERE id=? AND mailbox_id=?`, labelID, mb.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
respondError(w, http.StatusInternalServerError, "failed to delete label")
|
respondError(w, http.StatusInternalServerError, "failed to delete label")
|
||||||
return
|
return
|
||||||
@@ -236,7 +247,11 @@ func (a *App) handleDeleteMailLabel(w http.ResponseWriter, r *http.Request) {
|
|||||||
respondError(w, http.StatusNotFound, "label not found")
|
respondError(w, http.StatusNotFound, "label not found")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
labels, err := a.labelsForMailbox(r.Context(), mb.ID)
|
if err := tx.Commit(); err != nil {
|
||||||
|
respondError(w, http.StatusInternalServerError, "failed to commit transaction")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
labels, err := a.labelsForMailbox(ctx, mb.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
respondError(w, http.StatusInternalServerError, "failed to load labels")
|
respondError(w, http.StatusInternalServerError, "failed to load labels")
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -243,6 +243,14 @@ export function MailPage() {
|
|||||||
qc.setQueryData<ListResponse<MailLabel>>(["labels", activeMailboxId], (current) => current ? { ...current, items: current.items.filter((l) => l.id !== id) } : current)
|
qc.setQueryData<ListResponse<MailLabel>>(["labels", activeMailboxId], (current) => current ? { ...current, items: current.items.filter((l) => l.id !== id) } : current)
|
||||||
return { prevLabels }
|
return { prevLabels }
|
||||||
},
|
},
|
||||||
|
onSuccess: (_data, id) => {
|
||||||
|
if (mailView === "label" && selectedLabelId === id) {
|
||||||
|
setMailView("folder")
|
||||||
|
setFolder("Inbox")
|
||||||
|
setSelectedLabelId("")
|
||||||
|
setSelectedId(null)
|
||||||
|
}
|
||||||
|
},
|
||||||
onError: (_error, _id, context) => {
|
onError: (_error, _id, context) => {
|
||||||
if (context?.prevLabels) qc.setQueryData(["labels", activeMailboxId], context.prevLabels)
|
if (context?.prevLabels) qc.setQueryData(["labels", activeMailboxId], context.prevLabels)
|
||||||
toast({ title: "删除标签失败" })
|
toast({ title: "删除标签失败" })
|
||||||
|
|||||||
Reference in New Issue
Block a user