Skip to content

Commit

Permalink
Support sending reparse request (#643)
Browse files Browse the repository at this point in the history
  • Loading branch information
harryzcy authored Nov 19, 2023
1 parent 45ef2f2 commit 27a78ab
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
37 changes: 37 additions & 0 deletions web/src/pages/EmailRawView.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<div className="w-full px-2 py-2 md:px-8 md:py-5">
<h1 className="text-lg font-light tracking-wider dark:text-white md:px-1 md:pb-4">
Expand All @@ -27,6 +55,13 @@ export default function EmailRawView() {
</pre>

<div className="absolute right-0 top-2 space-x-3 p-3 dark:text-neutral-400">
<span
role="button"
className="cursor-pointer rounded-md bg-blue-100 p-2 dark:bg-neutral-700"
onClick={reparse}
>
<span>Re-Parse</span>
</span>
<span
role="button"
className="cursor-pointer rounded-md bg-blue-100 p-2 dark:bg-neutral-700"
Expand Down Expand Up @@ -56,6 +91,8 @@ export default function EmailRawView() {
</Await>
</React.Suspense>
</div>

<Toaster />
</div>
)
}
8 changes: 4 additions & 4 deletions web/src/preflight.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -336,7 +336,7 @@ textarea::placeholder {
Set the default cursor for buttons.
*/

button:not(.email-sandbox *),
button,
[role="button"] {
cursor: pointer;
}
Expand Down
6 changes: 6 additions & 0 deletions web/src/services/emails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ export async function unreadEmail(messageID: string): Promise<void> {
})
}

export async function reparseEmail(messageID: string): Promise<void> {
await fetch(`/web/emails/${messageID}/reparse`, {
method: 'POST'
})
}

export function generateLocalDraftID(): string {
return `local-${Date.now().toString()}`
}
Expand Down

0 comments on commit 27a78ab

Please sign in to comment.