Add mailbox to location hash.
Now we can preserve what mailbox we're looking at.
This commit is contained in:
parent
ee872f6985
commit
5c7e67a2bd
20
src/App.tsx
20
src/App.tsx
|
@ -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(),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue