add history state navigation

This commit is contained in:
MathMan05 2024-11-25 15:29:01 -06:00
parent 04f634a708
commit 906f4a51d6
5 changed files with 17 additions and 11 deletions

View file

@ -801,7 +801,7 @@ class Channel extends SnowFlake{
} }
} }
static genid: number = 0; static genid: number = 0;
async getHTML(){ async getHTML(addstate=true){
const id = ++Channel.genid; const id = ++Channel.genid;
if(this.localuser.channelfocus){ if(this.localuser.channelfocus){
this.localuser.channelfocus.infinite.delete(); this.localuser.channelfocus.infinite.delete();
@ -820,8 +820,9 @@ class Channel extends SnowFlake{
this.localuser.userinfo.updateLocal(); this.localuser.userinfo.updateLocal();
this.localuser.channelfocus = this; this.localuser.channelfocus = this;
const prom = this.infinite.delete(); 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); this.localuser.pageTitle("#" + this.name);
const channelTopic = document.getElementById("channelTopic") as HTMLSpanElement; const channelTopic = document.getElementById("channelTopic") as HTMLSpanElement;
if(this.topic){ if(this.topic){

View file

@ -180,7 +180,7 @@ class Group extends Channel{
this.guild.prevchannel = this; this.guild.prevchannel = this;
this.localuser.channelfocus = this; this.localuser.channelfocus = this;
const prom = this.infinite.delete(); 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); this.localuser.pageTitle("@" + this.name);
(document.getElementById("channelTopic") as HTMLElement).setAttribute("hidden",""); (document.getElementById("channelTopic") as HTMLElement).setAttribute("hidden","");

View file

@ -584,22 +584,22 @@ class Guild extends SnowFlake{
} }
return this.member.hasRole(r); return this.member.hasRole(r);
} }
loadChannel(ID?: string | undefined){ loadChannel(ID?: string | undefined,addstate=true){
if(ID){ if(ID){
const channel = this.localuser.channelids.get(ID); const channel = this.localuser.channelids.get(ID);
if(channel){ if(channel){
channel.getHTML(); channel.getHTML(addstate);
return; return;
} }
} }
if(this.prevchannel){ if(this.prevchannel){
console.log(this.prevchannel); console.log(this.prevchannel);
this.prevchannel.getHTML(); this.prevchannel.getHTML(addstate);
return; return;
} }
for(const thing of this.channels){ for(const thing of this.channels){
if(thing.children.length === 0){ if(thing.children.length === 0){
thing.getHTML(); thing.getHTML(addstate);
return; return;
} }
} }

View file

@ -148,7 +148,12 @@ import { I18n } from "./i18n.js";
const pasteImageElement = document.getElementById("pasteimage") as HTMLDivElement; const pasteImageElement = document.getElementById("pasteimage") as HTMLDivElement;
let replyingTo: Message | null = null; 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<void>{ async function handleEnter(event: KeyboardEvent): Promise<void>{
if(thisUser.keyup(event)){return} if(thisUser.keyup(event)){return}
const channel = thisUser.channelfocus; const channel = thisUser.channelfocus;

View file

@ -726,12 +726,12 @@ class Localuser{
} }
} }
gotoid: string | undefined; gotoid: string | undefined;
async goToChannel(id: string){ async goToChannel(id: string,addstate=true){
const channel = this.channelids.get(id); const channel = this.channelids.get(id);
if(channel){ if(channel){
const guild = channel.guild; const guild = channel.guild;
guild.loadGuild(); guild.loadGuild();
guild.loadChannel(id); guild.loadChannel(id,addstate);
}else{ }else{
this.gotoid = id; this.gotoid = id;
} }