Move to TanStack Start from Next.js (#184)

This commit is contained in:
Aslam
2024-10-07 16:44:17 +07:00
committed by GitHub
parent 3a89a1c07f
commit 950ebc3dad
514 changed files with 20021 additions and 15508 deletions

View File

@@ -0,0 +1,35 @@
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,
}
}