From 906f4a51d65f758768ca4fd6f2c9336dd05b9042 Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Mon, 25 Nov 2024 15:29:01 -0600 Subject: [PATCH] add history state navigation --- src/webpage/channel.ts | 7 ++++--- src/webpage/direct.ts | 2 +- src/webpage/guild.ts | 8 ++++---- src/webpage/index.ts | 7 ++++++- src/webpage/localuser.ts | 4 ++-- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/webpage/channel.ts b/src/webpage/channel.ts index 95b6f05..aee41a7 100644 --- a/src/webpage/channel.ts +++ b/src/webpage/channel.ts @@ -801,7 +801,7 @@ class Channel extends SnowFlake{ } } static genid: number = 0; - async getHTML(){ + async getHTML(addstate=true){ const id = ++Channel.genid; if(this.localuser.channelfocus){ this.localuser.channelfocus.infinite.delete(); @@ -820,8 +820,9 @@ class Channel extends SnowFlake{ this.localuser.userinfo.updateLocal(); this.localuser.channelfocus = this; const prom = this.infinite.delete(); - history.pushState(null, "", "/channels/" + this.guild_id + "/" + this.id); - + if(addstate){ + history.pushState([this.guild_id,this.id], "", "/channels/" + this.guild_id + "/" + this.id); + } this.localuser.pageTitle("#" + this.name); const channelTopic = document.getElementById("channelTopic") as HTMLSpanElement; if(this.topic){ diff --git a/src/webpage/direct.ts b/src/webpage/direct.ts index 15dbed0..f3c99a6 100644 --- a/src/webpage/direct.ts +++ b/src/webpage/direct.ts @@ -180,7 +180,7 @@ class Group extends Channel{ this.guild.prevchannel = this; this.localuser.channelfocus = this; const prom = this.infinite.delete(); - history.pushState(null, "", "/channels/" + this.guild_id + "/" + this.id); + history.pushState([this.guild_id,this.id], "", "/channels/" + this.guild_id + "/" + this.id); this.localuser.pageTitle("@" + this.name); (document.getElementById("channelTopic") as HTMLElement).setAttribute("hidden",""); diff --git a/src/webpage/guild.ts b/src/webpage/guild.ts index bf72d7d..688a4af 100644 --- a/src/webpage/guild.ts +++ b/src/webpage/guild.ts @@ -584,22 +584,22 @@ class Guild extends SnowFlake{ } return this.member.hasRole(r); } - loadChannel(ID?: string | undefined){ + loadChannel(ID?: string | undefined,addstate=true){ if(ID){ const channel = this.localuser.channelids.get(ID); if(channel){ - channel.getHTML(); + channel.getHTML(addstate); return; } } if(this.prevchannel){ console.log(this.prevchannel); - this.prevchannel.getHTML(); + this.prevchannel.getHTML(addstate); return; } for(const thing of this.channels){ if(thing.children.length === 0){ - thing.getHTML(); + thing.getHTML(addstate); return; } } diff --git a/src/webpage/index.ts b/src/webpage/index.ts index 4ab27cf..40e2fa6 100644 --- a/src/webpage/index.ts +++ b/src/webpage/index.ts @@ -148,7 +148,12 @@ import { I18n } from "./i18n.js"; const pasteImageElement = document.getElementById("pasteimage") as HTMLDivElement; let replyingTo: Message | null = null; - + window.addEventListener("popstate",(e)=>{ + if(e.state instanceof Object){ + thisUser.goToChannel(e.state[1],false); + } + //console.log(e.state,"state:3") + }) async function handleEnter(event: KeyboardEvent): Promise{ if(thisUser.keyup(event)){return} const channel = thisUser.channelfocus; diff --git a/src/webpage/localuser.ts b/src/webpage/localuser.ts index 14637fc..26863ac 100644 --- a/src/webpage/localuser.ts +++ b/src/webpage/localuser.ts @@ -726,12 +726,12 @@ class Localuser{ } } gotoid: string | undefined; - async goToChannel(id: string){ + async goToChannel(id: string,addstate=true){ const channel = this.channelids.get(id); if(channel){ const guild = channel.guild; guild.loadGuild(); - guild.loadChannel(id); + guild.loadChannel(id,addstate); }else{ this.gotoid = id; }