Standardize on links for refresh.
Turns out I was doubling-up unnecessarily and had an event handler _and_ a hash change detection. This just made things complex. Now I use the hash for both the mailbox and the email navigation. I don't yet do anything with the email part.
This commit is contained in:
parent
bf1ad0326d
commit
fb53a7506f
26
src/App.tsx
26
src/App.tsx
|
@ -2,13 +2,14 @@ import "./App.css";
|
||||||
import "./style.scss";
|
import "./style.scss";
|
||||||
|
|
||||||
import Client, { IAuth } from "./client/Client";
|
import Client, { IAuth } from "./client/Client";
|
||||||
import { AccountIdMap, IAccount, IMailbox } from "./client/types";
|
import { AccountIdMap, IAccount, IEmail, IMailbox } from "./client/types";
|
||||||
import AppLayout from "./AppLayout";
|
import AppLayout from "./AppLayout";
|
||||||
import AuthModal from "./AuthModal";
|
import AuthModal from "./AuthModal";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
interface ILocation {
|
interface ILocation {
|
||||||
accountId: string;
|
accountId: string;
|
||||||
|
emailId: string;
|
||||||
mailboxId: string;
|
mailboxId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +17,7 @@ type AppState = {
|
||||||
auth: IAuth;
|
auth: IAuth;
|
||||||
account: IAccount | null;
|
account: IAccount | null;
|
||||||
accounts: AccountIdMap;
|
accounts: AccountIdMap;
|
||||||
|
email: IEmail | null;
|
||||||
location: ILocation;
|
location: ILocation;
|
||||||
mailbox: IMailbox | null;
|
mailbox: IMailbox | null;
|
||||||
};
|
};
|
||||||
|
@ -37,7 +39,8 @@ class App extends React.Component<AppProps, AppState> {
|
||||||
account: null,
|
account: null,
|
||||||
accounts: {},
|
accounts: {},
|
||||||
auth: { email: "", password: "" },
|
auth: { email: "", password: "" },
|
||||||
location: { accountId: "", mailboxId: "" },
|
email: null,
|
||||||
|
location: { accountId: "", emailId: "", mailboxId: "" },
|
||||||
mailbox: null,
|
mailbox: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -46,14 +49,19 @@ class App extends React.Component<AppProps, AppState> {
|
||||||
const parts = hash.split("/");
|
const parts = hash.split("/");
|
||||||
const accountId = parts[0];
|
const accountId = parts[0];
|
||||||
const mailboxId = parts[1];
|
const mailboxId = parts[1];
|
||||||
|
const emailId = parts[2];
|
||||||
this.setState({
|
this.setState({
|
||||||
...this.state,
|
...this.state,
|
||||||
account: this.account(),
|
account: this.account(),
|
||||||
location: {
|
location: {
|
||||||
accountId: accountId,
|
accountId: accountId,
|
||||||
|
emailId: emailId,
|
||||||
mailboxId: mailboxId,
|
mailboxId: mailboxId,
|
||||||
},
|
},
|
||||||
|
mailbox: this.client.mailbox(accountId, mailboxId),
|
||||||
});
|
});
|
||||||
|
if (!this.state.account) return;
|
||||||
|
this.client.ensureEmailList(accountId, mailboxId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// When the user provides credentials
|
// When the user provides credentials
|
||||||
|
@ -70,16 +78,6 @@ class App extends React.Component<AppProps, AppState> {
|
||||||
this.client.doLogin({ email, password });
|
this.client.doLogin({ email, password });
|
||||||
}
|
}
|
||||||
|
|
||||||
onMailboxSelect(mailboxId: string) {
|
|
||||||
if (!this.state.account) return;
|
|
||||||
this.client.emailList(this.state.account.id, mailboxId, []);
|
|
||||||
this.setState({
|
|
||||||
...this.state,
|
|
||||||
mailbox: this.client.mailbox(this.state.account.id, mailboxId),
|
|
||||||
});
|
|
||||||
window.location.hash = this.state.location.accountId + "/" + mailboxId;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load up auth credentials from the local store
|
// Load up auth credentials from the local store
|
||||||
loadAuth() {
|
loadAuth() {
|
||||||
const data = localStorage.getItem("auth");
|
const data = localStorage.getItem("auth");
|
||||||
|
@ -131,10 +129,8 @@ class App extends React.Component<AppProps, AppState> {
|
||||||
account={this.state.account}
|
account={this.state.account}
|
||||||
accounts={this.state.accounts}
|
accounts={this.state.accounts}
|
||||||
client={this.client}
|
client={this.client}
|
||||||
|
email={this.state.email}
|
||||||
mailbox={this.state.mailbox}
|
mailbox={this.state.mailbox}
|
||||||
onMailboxSelect={(m) => {
|
|
||||||
this.onMailboxSelect(m);
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
<AuthModal
|
<AuthModal
|
||||||
show={this.client.state.session == null}
|
show={this.client.state.session == null}
|
||||||
|
|
|
@ -7,14 +7,14 @@ import AccountList from "./AccountList";
|
||||||
import EmailList from "./EmailList";
|
import EmailList from "./EmailList";
|
||||||
import MailboxList from "./MailboxList";
|
import MailboxList from "./MailboxList";
|
||||||
import Client from "./client/Client";
|
import Client from "./client/Client";
|
||||||
import { AccountIdMap, IAccount, IMailbox } from "./client/types";
|
import { AccountIdMap, IAccount, IEmail, IMailbox } from "./client/types";
|
||||||
|
|
||||||
type TopProps = {
|
type TopProps = {
|
||||||
account: IAccount | null;
|
account: IAccount | null;
|
||||||
accounts: AccountIdMap;
|
accounts: AccountIdMap;
|
||||||
client: Client;
|
client: Client;
|
||||||
|
email: IEmail | null;
|
||||||
mailbox: IMailbox | null;
|
mailbox: IMailbox | null;
|
||||||
onMailboxSelect: (mailboxId: string) => void;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const AppLayout: React.FC<TopProps> = (props) => {
|
const AppLayout: React.FC<TopProps> = (props) => {
|
||||||
|
@ -29,11 +29,7 @@ const AppLayout: React.FC<TopProps> = (props) => {
|
||||||
</Row>
|
</Row>
|
||||||
<Row>
|
<Row>
|
||||||
<Col lg="1">
|
<Col lg="1">
|
||||||
<MailboxList
|
<MailboxList account={props.account} client={props.client} />
|
||||||
account={props.account}
|
|
||||||
client={props.client}
|
|
||||||
onMailboxSelect={props.onMailboxSelect}
|
|
||||||
/>
|
|
||||||
</Col>
|
</Col>
|
||||||
<Col lg="11">
|
<Col lg="11">
|
||||||
<EmailList
|
<EmailList
|
||||||
|
|
|
@ -1,12 +1,19 @@
|
||||||
import ListGroup from "react-bootstrap/ListGroup";
|
import React from "react";
|
||||||
|
|
||||||
|
type MailboxProps = {
|
||||||
|
accountId: string;
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const Mailbox: React.FC<MailboxProps> = ({ accountId, id, name }) => {
|
||||||
|
const href = "#" + accountId + "/" + id;
|
||||||
|
|
||||||
function Mailbox() {
|
|
||||||
return (
|
return (
|
||||||
<ListGroup>
|
<a href={href} className="p-2" key={id}>
|
||||||
<ListGroup.Item>Inbox</ListGroup.Item>
|
{name}
|
||||||
<ListGroup.Item>Spam</ListGroup.Item>
|
</a>
|
||||||
</ListGroup>
|
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
export default Mailbox;
|
export default Mailbox;
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import Button from "react-bootstrap/Button";
|
|
||||||
import Stack from "react-bootstrap/Stack";
|
import Stack from "react-bootstrap/Stack";
|
||||||
|
|
||||||
import Client from "./client/Client";
|
import Client from "./client/Client";
|
||||||
import { IAccount } from "./client/types";
|
import { IAccount } from "./client/types";
|
||||||
|
import Mailbox from "./Mailbox";
|
||||||
|
|
||||||
type MailboxListProps = {
|
type MailboxListProps = {
|
||||||
account: IAccount | null;
|
account: IAccount | null;
|
||||||
client: Client | null;
|
client: Client | null;
|
||||||
onMailboxSelect: (mailboxId: string) => void;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
type MailboxListState = {};
|
type MailboxListState = {};
|
||||||
|
@ -20,10 +19,6 @@ class MailboxList extends React.Component<MailboxListProps, MailboxListState> {
|
||||||
this.props.client.mailboxList(this.props.account.id, []);
|
this.props.client.mailboxList(this.props.account.id, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
onMailboxClick(id: string) {
|
|
||||||
this.props.onMailboxSelect(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return this.props.account == null ||
|
return this.props.account == null ||
|
||||||
this.props.account.mailboxes == null ? (
|
this.props.account.mailboxes == null ? (
|
||||||
|
@ -31,15 +26,12 @@ class MailboxList extends React.Component<MailboxListProps, MailboxListState> {
|
||||||
) : (
|
) : (
|
||||||
<Stack>
|
<Stack>
|
||||||
{this.props.account.mailboxes.map((m) => (
|
{this.props.account.mailboxes.map((m) => (
|
||||||
<Button
|
<Mailbox
|
||||||
className="p-2"
|
accountId={this.props.account!.id}
|
||||||
|
id={m.id}
|
||||||
key={m.id}
|
key={m.id}
|
||||||
onClick={() => {
|
name={m.name}
|
||||||
this.onMailboxClick(m.id);
|
/>
|
||||||
}}
|
|
||||||
>
|
|
||||||
{m.name}
|
|
||||||
</Button>
|
|
||||||
))}
|
))}
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue