| 292 | } |
| 293 | |
| 294 | export async function deleteBookmark( |
| 295 | prevState: ActionState | null, |
| 296 | formData: { |
| 297 | id: string; |
| 298 | url: string; |
| 299 | }, |
| 300 | ): Promise<ActionState> { |
| 301 | try { |
| 302 | if (!formData) { |
| 303 | return { error: "No form data provided" }; |
| 304 | } |
| 305 | |
| 306 | const id = formData.id; |
| 307 | if (!id) { |
| 308 | return { error: "No bookmark ID provided" }; |
| 309 | } |
| 310 | |
| 311 | const url = formData.url; |
| 312 | |
| 313 | await db.delete(bookmarks).where(eq(bookmarks.id, Number(id))); |
| 314 | |
| 315 | revalidatePath("/admin"); |
| 316 | revalidatePath("/"); |
| 317 | revalidatePath(`/${encodeURIComponent(url)}`); |
| 318 | |
| 319 | return { success: true }; |
| 320 | } catch (err) { |
| 321 | console.error("Error deleting bookmark:", err); |
| 322 | return { error: "Failed to delete bookmark" }; |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | // Helper function to handle errors |
| 327 | type ErrorResponse = { |