(
prevState: ActionState | null,
formData: {
id: string;
title: string;
description: string;
url: string;
slug: string;
overview: string;
favicon: string;
ogImage: string;
search_results: string;
categoryId: string;
isFavorite: string;
isArchived: string;
},
)
| 221 | } |
| 222 | |
| 223 | export async function updateBookmark( |
| 224 | prevState: ActionState | null, |
| 225 | formData: { |
| 226 | id: string; |
| 227 | title: string; |
| 228 | description: string; |
| 229 | url: string; |
| 230 | slug: string; |
| 231 | overview: string; |
| 232 | favicon: string; |
| 233 | ogImage: string; |
| 234 | search_results: string; |
| 235 | categoryId: string; |
| 236 | isFavorite: string; |
| 237 | isArchived: string; |
| 238 | }, |
| 239 | ): Promise<ActionState> { |
| 240 | try { |
| 241 | if (!formData) { |
| 242 | return { error: "No form data provided" }; |
| 243 | } |
| 244 | |
| 245 | const id = formData.id; |
| 246 | if (!id) { |
| 247 | return { error: "No bookmark ID provided" }; |
| 248 | } |
| 249 | |
| 250 | const title = formData.title; |
| 251 | const description = formData.description; |
| 252 | const url = formData.url; |
| 253 | let slug = formData.slug; |
| 254 | const overview = formData.overview; |
| 255 | const favicon = formData.favicon; |
| 256 | const ogImage = formData.ogImage; |
| 257 | const search_results = formData.search_results; |
| 258 | const categoryId = formData.categoryId; |
| 259 | const isFavorite = formData.isFavorite === "true"; |
| 260 | const isArchived = formData.isArchived === "true"; |
| 261 | |
| 262 | // Generate slug if not provided |
| 263 | if (!slug) { |
| 264 | slug = generateSlug(title); |
| 265 | } |
| 266 | |
| 267 | await db |
| 268 | .update(bookmarks) |
| 269 | .set({ |
| 270 | title, |
| 271 | slug, |
| 272 | url, |
| 273 | description, |
| 274 | categoryId: categoryId === "none" ? null : categoryId, |
| 275 | search_results: search_results || null, |
| 276 | overview, |
| 277 | favicon, |
| 278 | ogImage, |
| 279 | isFavorite, |
| 280 | isArchived, |
no test coverage detected