diff --git a/src/EmailContent.tsx b/src/EmailContent.tsx index 9dc3f3b..445f552 100644 --- a/src/EmailContent.tsx +++ b/src/EmailContent.tsx @@ -1,8 +1,12 @@ +import Button from "react-bootstrap/Button"; +import Container from "react-bootstrap/Container"; import Placeholder from "react-bootstrap/Placeholder"; import React from "react"; -import Stack from "react-bootstrap/Stack"; +import Row from "react-bootstrap/Row"; import Client from "./client/Client"; +import EmailContentHTML from "./EmailContentHTML"; +import EmailContentText from "./EmailContentText"; import { IAccount, IEmail } from "./client/types"; type EmailContentProps = { @@ -12,12 +16,18 @@ type EmailContentProps = { emailId: string; }; -type EmailContentState = {}; +type EmailContentState = { + showHTML: boolean; +}; class EmailContent extends React.Component< EmailContentProps, EmailContentState > { + state = { + showHTML: false, + }; + componentDidMount() { this.ensureData(); } @@ -38,41 +48,46 @@ class EmailContent extends React.Component< const email = this.props.email; if (email == null || email.bodyValues == null) { return ; - } else if (email.textBody != null) { - return ( - -
  • {email.receivedAt}
  • - {email.textBody.map((t) => - t.partId === undefined ? ( - - ) : ( -
    - ), - )} - - ); - } else if (email.htmlBody != null) { - return ( - - {email.htmlBody.map((h) => - h.partId === undefined ? ( - - ) : ( -
    - ), - )} - - ); + } + let content; + if (this.state.showHTML) { + if (email.htmlBody != null) { + content = ; + } else { + return

    No HTML content

    ; + } } else { - return

    Nothing to display :/

    ; + if (email.textBody != null) { + content = ; + } else { + return

    No text content/

    ; + } + } + return ( + + + + + {content} + + ); + } + + switchDisplay() { + if (this.state.showHTML) { + this.setState({ + showHTML: false, + }); + } else { + this.setState({ + showHTML: true, + }); } } } diff --git a/src/EmailContentHTML.tsx b/src/EmailContentHTML.tsx new file mode 100644 index 0000000..533716f --- /dev/null +++ b/src/EmailContentHTML.tsx @@ -0,0 +1,36 @@ +import Placeholder from "react-bootstrap/Placeholder"; +import React from "react"; +import Stack from "react-bootstrap/Stack"; + +import { IAccount, IEmail, IMailbox } from "./client/types"; +import Client from "./client/Client"; +import EmailContent from "./EmailContent"; +import EmailList from "./EmailList"; + +type EmailContentHTMLProps = { + email: IEmail; +}; + +const EmailContentHTML: React.FC = (props) => { + const email = props.email; + if (email.htmlBody == null) { + return ; + } + return ( + + {email.htmlBody.map((h) => + h.partId === undefined ? ( + + ) : ( +
    + ), + )} + + ); +}; +export default EmailContentHTML; diff --git a/src/EmailContentText.tsx b/src/EmailContentText.tsx new file mode 100644 index 0000000..e8b60a3 --- /dev/null +++ b/src/EmailContentText.tsx @@ -0,0 +1,39 @@ +import Placeholder from "react-bootstrap/Placeholder"; +import React from "react"; +import Stack from "react-bootstrap/Stack"; + +import { IAccount, IEmail, IMailbox } from "./client/types"; +import Client from "./client/Client"; +import EmailContent from "./EmailContent"; +import EmailList from "./EmailList"; + +type EmailContentTextProps = { + email: IEmail; +}; + +const EmailContentText: React.FC = (props) => { + const email = props.email; + if (email.textBody == null) { + return ; + } + return ( + +
  • {email.receivedAt}
  • +
    +				{email.textBody.map((t) =>
    +					t.partId === undefined ? (
    +						
    +					) : (
    +						
    + ), + )} +
    +
    + ); +}; +export default EmailContentText;