Add mailbox to location hash.

Now we can preserve what mailbox we're looking at.
This commit is contained in:
Eli Ribble 2024-08-28 01:03:15 -07:00
parent ee872f6985
commit 5c7e67a2bd
1 changed files with 17 additions and 3 deletions

View File

@ -9,6 +9,7 @@ import React from "react";
interface ILocation { interface ILocation {
accountId: string; accountId: string;
mailboxId: string;
} }
type AppState = { type AppState = {
@ -25,22 +26,33 @@ class App extends React.Component<AppProps, AppState> {
account(): IAccount | null { account(): IAccount | null {
return this.client.account(this.state.location.accountId); return this.client.account(this.state.location.accountId);
} }
mailbox(): IMailbox | null {
return this.client.mailbox(
this.state.location.accountId,
this.state.location.mailboxId,
);
}
client: Client = new Client(); client: Client = new Client();
state: AppState = { state: AppState = {
account: null, account: null,
accounts: {}, accounts: {},
auth: { email: "", password: "" }, auth: { email: "", password: "" },
location: { accountId: "" }, location: { accountId: "", mailboxId: "" },
mailbox: null, mailbox: null,
}; };
onHashChange() { onHashChange() {
console.log(window.location.hash);
const hash = window.location.hash.substring(1); const hash = window.location.hash.substring(1);
const parts = hash.split("/");
const accountId = parts[0];
const mailboxId = parts[1];
this.setState({ this.setState({
...this.state, ...this.state,
account: this.account(), account: this.account(),
location: { accountId: hash }, location: {
accountId: accountId,
mailboxId: mailboxId,
},
}); });
} }
@ -65,6 +77,7 @@ class App extends React.Component<AppProps, AppState> {
...this.state, ...this.state,
mailbox: this.client.mailbox(this.state.account.id, mailboxId), 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
@ -96,6 +109,7 @@ class App extends React.Component<AppProps, AppState> {
accounts: this.client.state.session accounts: this.client.state.session
? this.client.state.session.accounts ? this.client.state.session.accounts
: {}, : {},
mailbox: this.mailbox(),
}); });
}); });
} }