@@ -71,16 +71,15 @@ export const actions = {
7171 error : 'Failed to add bookmark'
7272 } ;
7373 }
74- const { id : mainImageId } = await storage . storeImage (
75- mainImageUrl ,
76- title ,
77- ownerId ,
78- bookmark . id
79- ) ;
80- const { id : iconId } = await storage . storeImage ( iconUrl , title , ownerId , bookmark . id ) ;
74+ const mainImage = mainImageUrl
75+ ? await storage . storeImage ( mainImageUrl , title , ownerId , bookmark . id )
76+ : undefined ;
77+ const icon = iconUrl
78+ ? await storage . storeImage ( iconUrl , title , ownerId , bookmark . id )
79+ : undefined ;
8180 const updatedBookmark = await updateBookmark ( bookmark . id , ownerId , {
82- mainImageId,
83- iconId
81+ ... ( mainImage ? { mainImageId : mainImage . id } : { } ) ,
82+ ... ( icon ? { iconId : icon . id } : { } )
8483 } ) ;
8584
8685 await upsertTagsForBookmark ( bookmark . id , ownerId , tagNames ) ;
@@ -149,8 +148,10 @@ export const actions = {
149148
150149 const tagNames = tags . map ( ( tag : any ) => tag . label ) ;
151150
152- const { id : mainImageId } = await storage . storeImage ( mainImageUrl , title , ownerId , id ) ;
153- const { id : iconId } = await storage . storeImage ( iconUrl , title , ownerId , id ) ;
151+ const mainImage = mainImageUrl
152+ ? await storage . storeImage ( mainImageUrl , title , ownerId , id )
153+ : undefined ;
154+ const icon = iconUrl ? await storage . storeImage ( iconUrl , title , ownerId , id ) : undefined ;
154155
155156 const bookmarkData = {
156157 author,
@@ -169,8 +170,8 @@ export const actions = {
169170 title,
170171 url,
171172 read,
172- ...( mainImageId ? { mainImageId } : { } ) ,
173- ...( iconId ? { iconId } : { } )
173+ ...( mainImage ? { mainImageId : mainImage . id } : { } ) ,
174+ ...( icon ? { iconId : icon . id } : { } )
174175 } ;
175176
176177 const bookmark = await updateBookmark ( id , ownerId , bookmarkData ) ;
@@ -290,7 +291,7 @@ export const actions = {
290291 const description = data . get ( 'description' ) as string ;
291292 const icon = data . get ( 'icon' ) as string ;
292293 const color = data . get ( 'color' ) as string ;
293- const parent = JSON . parse ( data . get ( 'parent' ) as string ) ;
294+ const parent = data . get ( 'parent' ) ? JSON . parse ( data . get ( 'parent' ) as string ) : null ;
294295 const parentValue = parent ?. value ? parent . value : parent ;
295296 const archived = data . get ( 'archived' ) === 'on' ? new Date ( ) : null ;
296297 const setPublic = data . get ( 'public' ) === 'on' ? new Date ( ) : null ;
@@ -301,7 +302,7 @@ export const actions = {
301302 description,
302303 icon,
303304 color,
304- parentId : parentValue === 'null' ? null : parentValue ,
305+ parentId : parentValue ,
305306 archived,
306307 public : setPublic ,
307308 ownerId,
@@ -332,7 +333,7 @@ export const actions = {
332333 const description = data . get ( 'description' ) as string ;
333334 const icon = data . get ( 'icon' ) as string ;
334335 const color = data . get ( 'color' ) as string ;
335- const parent = JSON . parse ( data . get ( 'parent' ) as string ) ;
336+ const parent = data . get ( 'parent' ) ? JSON . parse ( data . get ( 'parent' ) as string ) : null ;
336337 const parentValue = parent ?. value ? parent . value : parent ;
337338 const archived = data . get ( 'archived' ) === 'on' ? new Date ( ) : null ;
338339 const setPublic = data . get ( 'public' ) === 'on' ? new Date ( ) : null ;
@@ -343,7 +344,7 @@ export const actions = {
343344 description,
344345 icon,
345346 color,
346- parentId : parentValue === 'null' ? null : parentValue ,
347+ parentId : parentValue ,
347348 archived,
348349 public : setPublic
349350 } ;
0 commit comments