mirror of
https://github.com/linsa-io/linsa.git
synced 2026-03-29 13:21:59 +02:00
* chore: expose scrollActiveElementIntoView * feat(utils): editable element * fix: memoize exceptionRefs, use animation frame and check editable element * fix: improve btn on mobile * chore(drps): bump framer motion version * fix(link): big fix * chore: remove comment code * feat: touch device
33 lines
858 B
TypeScript
33 lines
858 B
TypeScript
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) {
|
|
throw new Error(`Link with id ${link.id} not found`)
|
|
}
|
|
|
|
me.root.personalLinks.splice(index, 1)
|
|
|
|
toast.success("Link deleted.", {
|
|
position: "bottom-right",
|
|
description: `${link.title} has been deleted.`
|
|
})
|
|
} catch (error) {
|
|
console.error("Failed to delete link:", error)
|
|
toast.error("Failed to delete link", {
|
|
description: error instanceof Error ? error.message : "An unknown error occurred"
|
|
})
|
|
}
|
|
}, [])
|
|
|
|
return {
|
|
deleteLink
|
|
}
|
|
}
|