fix snapping to new messages
This commit is contained in:
parent
7dd6082f24
commit
7cf4e40a5f
3 changed files with 22 additions and 28 deletions
|
@ -89,7 +89,6 @@ class InfiniteScroller {
|
||||||
this.div.appendChild(html);
|
this.div.appendChild(html);
|
||||||
this.HTMLElements.push([html, id]);
|
this.HTMLElements.push([html, id]);
|
||||||
}
|
}
|
||||||
currrunning = false;
|
|
||||||
async addedBottom() {
|
async addedBottom() {
|
||||||
await this.updatestuff();
|
await this.updatestuff();
|
||||||
const func = this.snapBottom();
|
const func = this.snapBottom();
|
||||||
|
@ -98,9 +97,11 @@ class InfiniteScroller {
|
||||||
}
|
}
|
||||||
snapBottom() {
|
snapBottom() {
|
||||||
const scrollBottom = this.scrollBottom;
|
const scrollBottom = this.scrollBottom;
|
||||||
|
console.log(scrollBottom);
|
||||||
return () => {
|
return () => {
|
||||||
if (this.div && scrollBottom < 4) {
|
if (this.div && scrollBottom < 4) {
|
||||||
this.div.scrollTop = this.div.scrollHeight + 20;
|
console.log("snap");
|
||||||
|
this.div.scrollTop = this.div.scrollHeight;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -154,6 +155,9 @@ class InfiniteScroller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async watchForBottom(already = false, fragement = new DocumentFragment()) {
|
async watchForBottom(already = false, fragement = new DocumentFragment()) {
|
||||||
|
let func;
|
||||||
|
if (!already)
|
||||||
|
func = this.snapBottom();
|
||||||
if (!this.div)
|
if (!this.div)
|
||||||
return false;
|
return false;
|
||||||
try {
|
try {
|
||||||
|
@ -192,8 +196,8 @@ class InfiniteScroller {
|
||||||
finally {
|
finally {
|
||||||
if (!already) {
|
if (!already) {
|
||||||
this.div.append(fragement);
|
this.div.append(fragement);
|
||||||
if (this.scrollBottom < 30) {
|
if (func) {
|
||||||
this.div.scrollTop = this.div.scrollHeight;
|
func();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -201,18 +205,12 @@ class InfiniteScroller {
|
||||||
watchtime = false;
|
watchtime = false;
|
||||||
changePromise;
|
changePromise;
|
||||||
async watchForChange() {
|
async watchForChange() {
|
||||||
if (this.currrunning) {
|
|
||||||
this.watchtime = true;
|
|
||||||
if (this.changePromise) {
|
if (this.changePromise) {
|
||||||
|
this.watchtime = true;
|
||||||
return await this.changePromise;
|
return await this.changePromise;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
this.watchtime = false;
|
this.watchtime = false;
|
||||||
this.currrunning = true;
|
|
||||||
}
|
}
|
||||||
this.changePromise = new Promise(async (res) => {
|
this.changePromise = new Promise(async (res) => {
|
||||||
try {
|
try {
|
||||||
|
@ -226,7 +224,7 @@ class InfiniteScroller {
|
||||||
if (this.timeout === null && changed) {
|
if (this.timeout === null && changed) {
|
||||||
this.timeout = setTimeout(this.updatestuff.bind(this), 300);
|
this.timeout = setTimeout(this.updatestuff.bind(this), 300);
|
||||||
}
|
}
|
||||||
if (!this.currrunning) {
|
if (!this.changePromise) {
|
||||||
console.error("something really bad happened");
|
console.error("something really bad happened");
|
||||||
}
|
}
|
||||||
res(Boolean(changed));
|
res(Boolean(changed));
|
||||||
|
@ -244,7 +242,6 @@ class InfiniteScroller {
|
||||||
finally {
|
finally {
|
||||||
setTimeout(_ => {
|
setTimeout(_ => {
|
||||||
this.changePromise = undefined;
|
this.changePromise = undefined;
|
||||||
this.currrunning = false;
|
|
||||||
if (this.watchtime) {
|
if (this.watchtime) {
|
||||||
this.watchForChange();
|
this.watchForChange();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1099,7 +1099,7 @@ class Channel extends SnowFlake{
|
||||||
if(!this.infinitefocus){
|
if(!this.infinitefocus){
|
||||||
this.tryfocusinfinate();
|
this.tryfocusinfinate();
|
||||||
}
|
}
|
||||||
this.infinite.addedBottom();
|
this.infinite.addedBottom()
|
||||||
}
|
}
|
||||||
if(messagez.author===this.localuser.user){
|
if(messagez.author===this.localuser.user){
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -90,7 +90,6 @@ class InfiniteScroller{
|
||||||
this.div.appendChild(html);
|
this.div.appendChild(html);
|
||||||
this.HTMLElements.push([html,id]);
|
this.HTMLElements.push([html,id]);
|
||||||
}
|
}
|
||||||
currrunning:boolean=false;
|
|
||||||
async addedBottom(){
|
async addedBottom(){
|
||||||
await this.updatestuff();
|
await this.updatestuff();
|
||||||
const func=this.snapBottom();
|
const func=this.snapBottom();
|
||||||
|
@ -99,9 +98,11 @@ class InfiniteScroller{
|
||||||
}
|
}
|
||||||
snapBottom(){
|
snapBottom(){
|
||||||
const scrollBottom=this.scrollBottom;
|
const scrollBottom=this.scrollBottom;
|
||||||
|
console.log(scrollBottom);
|
||||||
return()=>{
|
return()=>{
|
||||||
if(this.div&&scrollBottom<4){
|
if(this.div&&scrollBottom<4){
|
||||||
this.div.scrollTop=this.div.scrollHeight+20;
|
console.log("snap");
|
||||||
|
this.div.scrollTop=this.div.scrollHeight;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -155,6 +156,8 @@ class InfiniteScroller{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async watchForBottom(already=false,fragement=new DocumentFragment()):Promise<boolean>{
|
async watchForBottom(already=false,fragement=new DocumentFragment()):Promise<boolean>{
|
||||||
|
let func:Function|undefined;
|
||||||
|
if(!already) func=this.snapBottom();
|
||||||
if(!this.div)return false;
|
if(!this.div)return false;
|
||||||
try{
|
try{
|
||||||
let again=false;
|
let again=false;
|
||||||
|
@ -190,8 +193,8 @@ class InfiniteScroller{
|
||||||
}finally{
|
}finally{
|
||||||
if(!already){
|
if(!already){
|
||||||
this.div.append(fragement);
|
this.div.append(fragement);
|
||||||
if(this.scrollBottom<30){
|
if(func){
|
||||||
this.div.scrollTop=this.div.scrollHeight;
|
func();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -199,16 +202,11 @@ class InfiniteScroller{
|
||||||
watchtime:boolean=false;
|
watchtime:boolean=false;
|
||||||
changePromise:Promise<boolean>|undefined;
|
changePromise:Promise<boolean>|undefined;
|
||||||
async watchForChange():Promise<boolean>{
|
async watchForChange():Promise<boolean>{
|
||||||
if(this.currrunning){
|
|
||||||
this.watchtime=true;
|
|
||||||
if(this.changePromise){
|
if(this.changePromise){
|
||||||
|
this.watchtime=true;
|
||||||
return await this.changePromise;
|
return await this.changePromise;
|
||||||
}else{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}else{
|
}else{
|
||||||
this.watchtime=false;
|
this.watchtime=false;
|
||||||
this.currrunning=true;
|
|
||||||
}
|
}
|
||||||
this.changePromise=new Promise<boolean>(async res=>{
|
this.changePromise=new Promise<boolean>(async res=>{
|
||||||
try{
|
try{
|
||||||
|
@ -221,7 +219,7 @@ class InfiniteScroller{
|
||||||
if(this.timeout===null&&changed){
|
if(this.timeout===null&&changed){
|
||||||
this.timeout=setTimeout(this.updatestuff.bind(this),300);
|
this.timeout=setTimeout(this.updatestuff.bind(this),300);
|
||||||
}
|
}
|
||||||
if(!this.currrunning){
|
if(!this.changePromise){
|
||||||
console.error("something really bad happened");
|
console.error("something really bad happened");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,7 +235,6 @@ class InfiniteScroller{
|
||||||
}finally{
|
}finally{
|
||||||
setTimeout(_=>{
|
setTimeout(_=>{
|
||||||
this.changePromise=undefined;
|
this.changePromise=undefined;
|
||||||
this.currrunning=false;
|
|
||||||
if(this.watchtime){
|
if(this.watchtime){
|
||||||
this.watchForChange();
|
this.watchForChange();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue