work on reply jumping and fixed account fixer
This commit is contained in:
parent
7a745a5286
commit
6cea53dabd
12 changed files with 350 additions and 62 deletions
|
@ -1,6 +1,6 @@
|
|||
class InfiniteScroller{
|
||||
readonly getIDFromOffset:(ID:string,offset:number)=>Promise<string>;
|
||||
readonly getHTMLFromID:(ID:string)=>HTMLElement;
|
||||
readonly getHTMLFromID:(ID:string)=>Promise<HTMLElement>;
|
||||
readonly destroyFromID:(ID:string)=>Promise<boolean>;
|
||||
readonly reachesBottom:()=>void;
|
||||
private readonly minDist=3000;
|
||||
|
@ -15,7 +15,7 @@ class InfiniteScroller{
|
|||
this.reachesBottom=reachesBottom;
|
||||
}
|
||||
interval:NodeJS.Timeout;
|
||||
getDiv(initialId:string,bottom=true):HTMLDivElement{
|
||||
async getDiv(initialId:string,bottom=true):Promise<HTMLDivElement>{
|
||||
const div=document.createElement("div");
|
||||
div.classList.add("messagecontainer");
|
||||
//div.classList.add("flexttb")
|
||||
|
@ -30,10 +30,10 @@ class InfiniteScroller{
|
|||
new ResizeObserver(this.watchForChange.bind(this)).observe(div);
|
||||
new ResizeObserver(this.watchForChange.bind(this)).observe(scroll);
|
||||
|
||||
this.firstElement(initialId);
|
||||
await this.firstElement(initialId)
|
||||
this.updatestuff();
|
||||
this.watchForChange().then(_=>{
|
||||
this.scroll.scrollTop=this.scroll.scrollHeight;
|
||||
await this.watchForChange().then(_=>{
|
||||
this.updatestuff();
|
||||
})
|
||||
return div;
|
||||
}
|
||||
|
@ -47,8 +47,8 @@ class InfiniteScroller{
|
|||
}
|
||||
//this.watchForChange();
|
||||
}
|
||||
firstElement(id:string){
|
||||
const html=this.getHTMLFromID(id);
|
||||
async firstElement(id:string){
|
||||
const html=await this.getHTMLFromID(id);
|
||||
this.scroll.append(html);
|
||||
this.HTMLElements.push([html,id]);
|
||||
}
|
||||
|
@ -79,15 +79,13 @@ class InfiniteScroller{
|
|||
this.scroll.scrollTop=1;
|
||||
}
|
||||
if(this.scrollTop<this.minDist){
|
||||
|
||||
|
||||
const previd=this.HTMLElements.at(0)[1];
|
||||
const nextid=await this.getIDFromOffset(previd,1);
|
||||
if(!nextid){
|
||||
|
||||
}else{
|
||||
again=true;
|
||||
const html=this.getHTMLFromID(nextid);
|
||||
const html=await this.getHTMLFromID(nextid);
|
||||
this.scroll.prepend(html);
|
||||
this.HTMLElements.unshift([html,nextid]);
|
||||
this.scrollTop+=60;
|
||||
|
@ -109,7 +107,7 @@ class InfiniteScroller{
|
|||
if(!nextid){
|
||||
}else{
|
||||
again=true;
|
||||
const html=this.getHTMLFromID(nextid);
|
||||
const html=await this.getHTMLFromID(nextid);
|
||||
this.scroll.append(html);
|
||||
this.HTMLElements.push([html,nextid]);
|
||||
this.scrollBottom+=60;
|
||||
|
@ -132,6 +130,33 @@ class InfiniteScroller{
|
|||
}
|
||||
this.currrunning=false;
|
||||
}
|
||||
async focus(id:string,flash=true){
|
||||
let element:HTMLElement;
|
||||
for(const thing of this.HTMLElements){
|
||||
if(thing[1]===id){
|
||||
element=thing[0];
|
||||
}
|
||||
}
|
||||
console.log(element,id,":3");
|
||||
if(element){
|
||||
element.scrollIntoView();
|
||||
if(flash){
|
||||
element.classList.remove("jumped");
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
element.classList.add("jumped");
|
||||
}
|
||||
}else{
|
||||
for(const thing of this.HTMLElements){
|
||||
await this.destroyFromID(thing[1]);
|
||||
}
|
||||
this.HTMLElements=[];
|
||||
await this.firstElement(id);
|
||||
this.updatestuff();
|
||||
await this.watchForChange();
|
||||
await new Promise(resolve => setTimeout(resolve, 100));
|
||||
await this.focus(id,true);
|
||||
}
|
||||
}
|
||||
async delete():Promise<void>{
|
||||
for(const thing of this.HTMLElements){
|
||||
await this.destroyFromID(thing[1]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue