diff --git a/src/App.tsx b/src/App.tsx index ee36fdc..297f4df 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -2,13 +2,14 @@ import "./App.css"; import "./style.scss"; 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 AuthModal from "./AuthModal"; import React from "react"; interface ILocation { accountId: string; + emailId: string; mailboxId: string; } @@ -16,6 +17,7 @@ type AppState = { auth: IAuth; account: IAccount | null; accounts: AccountIdMap; + email: IEmail | null; location: ILocation; mailbox: IMailbox | null; }; @@ -37,7 +39,8 @@ class App extends React.Component { account: null, accounts: {}, auth: { email: "", password: "" }, - location: { accountId: "", mailboxId: "" }, + email: null, + location: { accountId: "", emailId: "", mailboxId: "" }, mailbox: null, }; @@ -46,14 +49,19 @@ class App extends React.Component { const parts = hash.split("/"); const accountId = parts[0]; const mailboxId = parts[1]; + const emailId = parts[2]; this.setState({ ...this.state, account: this.account(), location: { accountId: accountId, + emailId: emailId, mailboxId: mailboxId, }, + mailbox: this.client.mailbox(accountId, mailboxId), }); + if (!this.state.account) return; + this.client.ensureEmailList(accountId, mailboxId); } // When the user provides credentials @@ -70,16 +78,6 @@ class App extends React.Component { 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 loadAuth() { const data = localStorage.getItem("auth"); @@ -131,10 +129,8 @@ class App extends React.Component { account={this.state.account} accounts={this.state.accounts} client={this.client} + email={this.state.email} mailbox={this.state.mailbox} - onMailboxSelect={(m) => { - this.onMailboxSelect(m); - }} /> void; }; const AppLayout: React.FC = (props) => { @@ -29,11 +29,7 @@ const AppLayout: React.FC = (props) => { - + = ({ accountId, id, name }) => { + const href = "#" + accountId + "/" + id; -function Mailbox() { return ( - - Inbox - Spam - + + {name} + ); -} +}; export default Mailbox; diff --git a/src/MailboxList.tsx b/src/MailboxList.tsx index f42a241..3bbe6a6 100644 --- a/src/MailboxList.tsx +++ b/src/MailboxList.tsx @@ -1,14 +1,13 @@ import React from "react"; -import Button from "react-bootstrap/Button"; import Stack from "react-bootstrap/Stack"; import Client from "./client/Client"; import { IAccount } from "./client/types"; +import Mailbox from "./Mailbox"; type MailboxListProps = { account: IAccount | null; client: Client | null; - onMailboxSelect: (mailboxId: string) => void; }; type MailboxListState = {}; @@ -20,10 +19,6 @@ class MailboxList extends React.Component { this.props.client.mailboxList(this.props.account.id, []); } - onMailboxClick(id: string) { - this.props.onMailboxSelect(id); - } - render() { return this.props.account == null || this.props.account.mailboxes == null ? ( @@ -31,15 +26,12 @@ class MailboxList extends React.Component { ) : ( {this.props.account.mailboxes.map((m) => ( - + name={m.name} + /> ))} );