From b872c33ba91cc8b4c41cc472a613d1183de803f9 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Wed, 25 Jan 2023 19:29:19 +0800 Subject: [PATCH] Allow marking recent emails as library items --- .../mutations/markEmailAsItemMutation.ts | 35 +++++++++++++++++++ packages/web/pages/settings/emails/index.tsx | 1 - packages/web/pages/settings/emails/recent.tsx | 13 ++++++- 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 packages/web/lib/networking/mutations/markEmailAsItemMutation.ts diff --git a/packages/web/lib/networking/mutations/markEmailAsItemMutation.ts b/packages/web/lib/networking/mutations/markEmailAsItemMutation.ts new file mode 100644 index 000000000..9f8fb8d9b --- /dev/null +++ b/packages/web/lib/networking/mutations/markEmailAsItemMutation.ts @@ -0,0 +1,35 @@ +import { gqlFetcher } from '../networkHelpers' + +type MarkEmailAsItemDataResponseData = { + markEmailAsItem?: MarkEmailAsItemData +} + +type MarkEmailAsItemData = { + success: Boolean + errorCodes?: unknown[] +} + +export async function markEmailAsItemMutation( + recentEmailId: String +): Promise { + const mutation = ` + mutation MarkRecentEmailAsItem($recentEmailId: ID!) { + markEmailAsItem(recentEmailId:$recentEmailId) { + ... on MarkEmailAsItemError { + errorCodes + } + ... on MarkEmailAsItemSuccess { + success + } + } + }` + + const data = await gqlFetcher(mutation, { recentEmailId }) + console.log('recentEmailId: ', data) + const output = data as MarkEmailAsItemDataResponseData | undefined + const error = output?.markEmailAsItem?.errorCodes?.find(() => true) + console.log('error: ', error) + if (error) { + throw error + } +} diff --git a/packages/web/pages/settings/emails/index.tsx b/packages/web/pages/settings/emails/index.tsx index 4f064d53e..c6381f007 100644 --- a/packages/web/pages/settings/emails/index.tsx +++ b/packages/web/pages/settings/emails/index.tsx @@ -118,7 +118,6 @@ export default function EmailsPage(): JSX.Element { <> { + action={async () => { console.log('marking as email', recentEmail) + showSuccessToast('Marking email as article') + try { + await markEmailAsItemMutation(recentEmail.id) + } catch (err) { + console.log('error marking as article: ', err) + showErrorToast('Error marking item as article') + return + } + showSuccessToast('Email added to library') }} />