Add button to move an email to trash.
This is the first time I'm modifying data instead of just displaying it.
And this commit is a mess, it's all over the place with duplicating
types and breaking my class layers.
But it works, technically, so, whatever, checkpoint!
I need to totally start reworking the base client library as I'm not
happy with it at all. Also, it turns out that we have very little type
protection on the "set" methods. I had a totally improper signature for
about an hour that led to useless debugging. Reading the standard, which
is excellent, helped me get sorted out, but they type checker should be
helping me.
Additionally, I should be creating this Account class type within the
client.
2024-09-03 12:03:04 -07:00
|
|
|
import { Trash } from "react-bootstrap-icons";
|
|
|
|
import Button from "react-bootstrap/Button";
|
|
|
|
import ButtonGroup from "react-bootstrap/ButtonGroup";
|
|
|
|
import ButtonToolbar from "react-bootstrap/ButtonToolbar";
|
2024-08-28 10:16:11 -07:00
|
|
|
import Placeholder from "react-bootstrap/Placeholder";
|
2024-08-30 07:40:40 -07:00
|
|
|
import React from "react";
|
2024-08-28 10:16:11 -07:00
|
|
|
|
2024-08-28 09:21:31 -07:00
|
|
|
import Client from "./client/Client";
|
2024-08-30 07:40:40 -07:00
|
|
|
import DateTime from "./components/DateTime";
|
2024-08-28 19:25:20 -07:00
|
|
|
import { IAccount, IEmailStub, IMailbox } from "./client/types";
|
2024-08-28 09:21:31 -07:00
|
|
|
|
|
|
|
type EmailSummaryProps = {
|
2024-08-30 07:40:40 -07:00
|
|
|
account: IAccount;
|
|
|
|
client: Client;
|
2024-08-28 09:21:31 -07:00
|
|
|
emailId: string;
|
2024-08-28 19:25:20 -07:00
|
|
|
emailStub: IEmailStub | null;
|
2024-08-30 07:40:40 -07:00
|
|
|
mailbox: IMailbox;
|
2024-08-28 09:21:31 -07:00
|
|
|
};
|
|
|
|
type EmailSummaryState = {};
|
|
|
|
|
|
|
|
class EmailSummary extends React.Component<
|
|
|
|
EmailSummaryProps,
|
|
|
|
EmailSummaryState
|
|
|
|
> {
|
|
|
|
componentDidMount() {
|
|
|
|
this.ensureData();
|
|
|
|
}
|
|
|
|
componentDidUpdate() {
|
|
|
|
this.ensureData();
|
|
|
|
}
|
|
|
|
|
|
|
|
ensureData() {
|
2024-08-28 19:25:20 -07:00
|
|
|
this.props.client.ensureEmailStub(
|
|
|
|
this.props.account.id,
|
|
|
|
this.props.emailId,
|
|
|
|
);
|
2024-08-28 09:21:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2024-08-28 10:16:11 -07:00
|
|
|
const href =
|
|
|
|
"#" +
|
|
|
|
this.props.account.id +
|
|
|
|
"/" +
|
|
|
|
this.props.mailbox.id +
|
|
|
|
"/" +
|
|
|
|
this.props.emailId;
|
2024-08-29 10:47:09 -07:00
|
|
|
const stub = this.props.emailStub;
|
2024-08-30 07:40:40 -07:00
|
|
|
if (stub === null) {
|
|
|
|
return <Placeholder />;
|
|
|
|
}
|
2024-08-28 09:21:31 -07:00
|
|
|
return (
|
2024-08-28 09:38:50 -07:00
|
|
|
<div className="p-2 border" key={this.props.emailId}>
|
2024-08-28 10:16:11 -07:00
|
|
|
<a className="btn" href={href}>
|
2024-08-30 07:40:40 -07:00
|
|
|
<DateTime d={stub.receivedAt} />
|
|
|
|
<span>
|
|
|
|
{" - " +
|
2024-08-29 10:47:09 -07:00
|
|
|
(stub.from == null ? "?" : stub.from[0].name) +
|
|
|
|
" - " +
|
2024-08-30 07:40:40 -07:00
|
|
|
stub.subject}
|
|
|
|
</span>
|
2024-08-28 10:16:11 -07:00
|
|
|
</a>
|
Add button to move an email to trash.
This is the first time I'm modifying data instead of just displaying it.
And this commit is a mess, it's all over the place with duplicating
types and breaking my class layers.
But it works, technically, so, whatever, checkpoint!
I need to totally start reworking the base client library as I'm not
happy with it at all. Also, it turns out that we have very little type
protection on the "set" methods. I had a totally improper signature for
about an hour that led to useless debugging. Reading the standard, which
is excellent, helped me get sorted out, but they type checker should be
helping me.
Additionally, I should be creating this Account class type within the
client.
2024-09-03 12:03:04 -07:00
|
|
|
<ButtonToolbar>
|
|
|
|
<ButtonGroup className="me-2">
|
|
|
|
<Button
|
|
|
|
onClick={() => {
|
|
|
|
this.props.client.emailMoveTrash(
|
|
|
|
this.props.account,
|
|
|
|
this.props.emailId,
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Trash />
|
|
|
|
</Button>
|
|
|
|
<Button>2</Button>
|
|
|
|
</ButtonGroup>
|
|
|
|
</ButtonToolbar>
|
2024-08-28 09:21:31 -07:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
export default EmailSummary;
|