Show text content, and if unavailable, the HTML content.

This required actually requesting all the body values, and mapping from
the body values to to body parts for display.
This commit is contained in:
Eli Ribble 2024-08-29 10:27:00 -07:00
parent 4e1922c5fa
commit d71f18cce1
2 changed files with 39 additions and 3 deletions

View File

@ -1,5 +1,6 @@
import React from "react";
import Placeholder from "react-bootstrap/Placeholder";
import React from "react";
import Stack from "react-bootstrap/Stack";
import Client from "./client/Client";
import { IAccount, IEmail } from "./client/types";
@ -34,10 +35,44 @@ class EmailContent extends React.Component<
}
render() {
if (this.props.email == null) {
const email = this.props.email;
if (email == null || email.bodyValues == null) {
return <Placeholder />;
} else if (email.textBody != null) {
return (
<Stack>
<li>{email.receivedAt}</li>
{email.textBody.map((t) =>
t.partId === undefined ? (
<Placeholder />
) : (
<div
dangerouslySetInnerHTML={{
__html: email.bodyValues![t.partId].value,
}}
/>
),
)}
</Stack>
);
} else if (email.htmlBody != null) {
return (
<Stack>
{email.htmlBody.map((h) =>
h.partId === undefined ? (
<Placeholder />
) : (
<div
dangerouslySetInnerHTML={{
__html: email.bodyValues![h.partId].value,
}}
/>
),
)}
</Stack>
);
} else {
return <p>{this.props.email.preview}</p>;
return <p>Nothing to display :/</p>;
}
}
}

View File

@ -112,6 +112,7 @@ export default class Client {
.email_get({
accountId: accountId,
ids: [emailId],
fetchAllBodyValues: true,
})
.then((response) => {
console.log(msg, "response", response);