From 8819ca1d05aa98ce5e21a94f2dec21d3d5451bab Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Mon, 29 Jul 2024 19:45:10 +0800 Subject: [PATCH] Fix moveToFolder response handling --- .../templates/library/LibraryContainer.tsx | 12 ++++++++---- .../library_items/useLibraryItems.tsx | 17 +++++++++++++---- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/packages/web/components/templates/library/LibraryContainer.tsx b/packages/web/components/templates/library/LibraryContainer.tsx index b8931d36b..223d60ad9 100644 --- a/packages/web/components/templates/library/LibraryContainer.tsx +++ b/packages/web/components/templates/library/LibraryContainer.tsx @@ -401,7 +401,8 @@ export function LibraryContainer(props: LibraryContainerProps): JSX.Element { linkId: item.node.id, archived: action == 'archive', }) - } catch { + } catch (err) { + console.log('Error setting archive state: ', err) showErrorToast(`Error ${action}ing item`, { position: 'bottom-right', }) @@ -414,7 +415,8 @@ export function LibraryContainer(props: LibraryContainerProps): JSX.Element { case 'delete': try { await deleteItem.mutateAsync(item.node.id) - } catch { + } catch (err) { + console.log('Error deleting item: ', err) showErrorToast(`Error deleting item`, { position: 'bottom-right', }) @@ -445,7 +447,8 @@ export function LibraryContainer(props: LibraryContainerProps): JSX.Element { force: true, ...values, }) - } catch { + } catch (err) { + console.log('Error marking item: ', err) showErrorToast(`Error marking as ${desc}`, { position: 'bottom-right', }) @@ -458,7 +461,8 @@ export function LibraryContainer(props: LibraryContainerProps): JSX.Element { itemId: item.node.id, folder: 'inbox', }) - } catch { + } catch (err) { + console.log('Error moving item: ', err) showErrorToast(`Error moving item`, { position: 'bottom-right', }) diff --git a/packages/web/lib/networking/library_items/useLibraryItems.tsx b/packages/web/lib/networking/library_items/useLibraryItems.tsx index 07370acc5..fa0ba67ae 100644 --- a/packages/web/lib/networking/library_items/useLibraryItems.tsx +++ b/packages/web/lib/networking/library_items/useLibraryItems.tsx @@ -275,11 +275,11 @@ export const useMoveItemToFolder = () => { const result = (await gqlFetcher(GQL_MOVE_ITEM_TO_FOLDER, { id: variables.itemId, folder: variables.folder, - })) as UpdateLibraryItemData - if (result.updatePage.errorCodes?.length) { - throw new Error(result.updatePage.errorCodes[0]) + })) as MoveToFolderData + if (result.moveToFolder.errorCodes?.length) { + throw new Error(result.moveToFolder.errorCodes[0]) } - return result.updatePage + return result.moveToFolder } return useMutation({ mutationFn: restoreItem, @@ -402,6 +402,15 @@ export type ArticleAttributes = { recommendations?: Recommendation[] } +type MoveToFolderData = { + moveToFolder: MoveToFolderResult +} + +type MoveToFolderResult = { + success?: boolean + errorCodes?: string[] +} + type ArticleResult = { article?: ArticleAttributes errorCodes?: string[]