From 27a78ab7011e0e94ddc9f679a61e8ab066da38c2 Mon Sep 17 00:00:00 2001 From: Chongyi Zheng Date: Sun, 19 Nov 2023 16:44:51 -0500 Subject: [PATCH] Support sending reparse request (#643) --- web/src/pages/EmailRawView.tsx | 37 ++++++++++++++++++++++++++++++++++ web/src/preflight.css | 8 ++++---- web/src/services/emails.ts | 6 ++++++ 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/web/src/pages/EmailRawView.tsx b/web/src/pages/EmailRawView.tsx index d0ba3148cb..346927a002 100644 --- a/web/src/pages/EmailRawView.tsx +++ b/web/src/pages/EmailRawView.tsx @@ -1,9 +1,37 @@ import React from 'react' import { Await, useLoaderData } from 'react-router-dom' +import { Toaster } from '@ui/toaster' +import { toast } from '@ui/use-toast' + +import { reparseEmail } from 'services/emails' + export default function EmailRawView() { const data = useLoaderData() as { messageID: string; raw: string } + const [isRequesting, setIsRequesting] = React.useState(false) + + const reparse = async () => { + if (isRequesting) return + setIsRequesting(true) + + try { + await reparseEmail(data.messageID) + toast({ + title: 'Re-parsed email', + duration: 5000 + }) + } catch (e) { + toast({ + title: 'Failed to re-parse email', + duration: 5000, + variant: 'destructive' + }) + } + + setIsRequesting(false) + } + return (

@@ -27,6 +55,13 @@ export default function EmailRawView() {
+ + Re-Parse +
+ +

) } diff --git a/web/src/preflight.css b/web/src/preflight.css index fbef106f58..0ad5808680 100644 --- a/web/src/preflight.css +++ b/web/src/preflight.css @@ -301,9 +301,9 @@ legend:not(.email-sandbox *) { padding: 0; } -ol:not(.email-sandbox *), -ul:not(.email-sandbox *), -menu:not(.email-sandbox *) { +ol, +ul, +menu { list-style: none; margin: 0; padding: 0; @@ -336,7 +336,7 @@ textarea::placeholder { Set the default cursor for buttons. */ -button:not(.email-sandbox *), +button, [role="button"] { cursor: pointer; } diff --git a/web/src/services/emails.ts b/web/src/services/emails.ts index d8354fa14a..4312d179a6 100644 --- a/web/src/services/emails.ts +++ b/web/src/services/emails.ts @@ -192,6 +192,12 @@ export async function unreadEmail(messageID: string): Promise { }) } +export async function reparseEmail(messageID: string): Promise { + await fetch(`/web/emails/${messageID}/reparse`, { + method: 'POST' + }) +} + export function generateLocalDraftID(): string { return `local-${Date.now().toString()}` }