From 5c7e67a2bdf348b203645dc6cba86f4143d6be56 Mon Sep 17 00:00:00 2001 From: Eli Ribble Date: Wed, 28 Aug 2024 01:03:15 -0700 Subject: [PATCH] Add mailbox to location hash. Now we can preserve what mailbox we're looking at. --- src/App.tsx | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 25ca753..a76caf9 100644 --- a/src/App.tsx +++ b/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 { 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 { ...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 { accounts: this.client.state.session ? this.client.state.session.accounts : {}, + mailbox: this.mailbox(), }); }); }