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 {
|
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(),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue