drishti/src/EmailSummary.tsx

63 lines
1.2 KiB
TypeScript
Raw Normal View History

import Placeholder from "react-bootstrap/Placeholder";
import React from "react";
import Client from "./client/Client";
import DateTime from "./components/DateTime";
import { IAccount, IEmailStub, IMailbox } from "./client/types";
type EmailSummaryProps = {
account: IAccount;
client: Client;
emailId: string;
emailStub: IEmailStub | null;
mailbox: IMailbox;
};
type EmailSummaryState = {};
class EmailSummary extends React.Component<
EmailSummaryProps,
EmailSummaryState
> {
componentDidMount() {
this.ensureData();
}
componentDidUpdate() {
this.ensureData();
}
ensureData() {
this.props.client.ensureEmailStub(
this.props.account.id,
this.props.emailId,
);
}
render() {
const href =
"#" +
this.props.account.id +
"/" +
this.props.mailbox.id +
"/" +
this.props.emailId;
const stub = this.props.emailStub;
if (stub === null) {
return <Placeholder />;
}
return (
<div className="p-2 border" key={this.props.emailId}>
<a className="btn" href={href}>
<DateTime d={stub.receivedAt} />
<span>
{" - " +
(stub.from == null ? "?" : stub.from[0].name) +
" - " +
stub.subject}
</span>
</a>
</div>
);
}
}
export default EmailSummary;