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