mirror of
https://github.com/linsa-io/linsa.git
synced 2026-01-12 12:20:23 +01:00
fix(link): delete link should disabled all key outside confirm
This commit is contained in:
30
web/components/routes/link/hooks/use-link-actions.ts
Normal file
30
web/components/routes/link/hooks/use-link-actions.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import * as React from "react"
|
||||
import { toast } from "sonner"
|
||||
import { LaAccount, PersonalLink } from "@/lib/schema"
|
||||
|
||||
export const useLinkActions = () => {
|
||||
const deleteLink = React.useCallback((me: LaAccount, link: PersonalLink) => {
|
||||
if (!me.root?.personalLinks) return
|
||||
|
||||
try {
|
||||
const index = me.root.personalLinks.findIndex(item => item?.id === link.id)
|
||||
if (index === -1) {
|
||||
console.error("Delete operation fail", { index, link })
|
||||
return
|
||||
}
|
||||
|
||||
toast.success("Link deleted.", {
|
||||
position: "bottom-right",
|
||||
description: `${link.title} has been deleted.`
|
||||
})
|
||||
|
||||
me.root.personalLinks.splice(index, 1)
|
||||
} catch (error) {
|
||||
toast.error("Failed to delete link")
|
||||
}
|
||||
}, [])
|
||||
|
||||
return {
|
||||
deleteLink
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user