various fixes

This commit is contained in:
MathMan05 2024-09-10 13:50:53 -05:00
parent baa224ab91
commit 72ac3a14ed
8 changed files with 50 additions and 3 deletions

View file

@ -930,6 +930,10 @@ class Channel extends SnowFlake {
if (this.localuser.channelfocus !== this) { if (this.localuser.channelfocus !== this) {
return; return;
} }
for (const elm of messages.getElementsByClassName("scroller")) {
elm.remove();
console.warn("rouge element detected and removed");
}
messages.append(await this.infinite.getDiv(id)); messages.append(await this.infinite.getDiv(id));
this.infinite.updatestuff(); this.infinite.updatestuff();
this.infinite.watchForChange().then(async (_) => { this.infinite.watchForChange().then(async (_) => {

View file

@ -46,7 +46,7 @@ class Guild extends SnowFlake {
}); });
Guild.contextmenu.addbutton("Create invite", function () { Guild.contextmenu.addbutton("Create invite", function () {
}, null, _ => true, _ => false); }, null, _ => true, _ => false);
Guild.contextmenu.addbutton("Settings[temp]", function () { Guild.contextmenu.addbutton("Settings", function () {
this.generateSettings(); this.generateSettings();
}); });
/* -----things left for later----- /* -----things left for later-----
@ -62,6 +62,16 @@ class Guild extends SnowFlake {
} }
generateSettings() { generateSettings() {
const settings = new Settings("Settings for " + this.properties.name); const settings = new Settings("Settings for " + this.properties.name);
{
const overview = settings.addButton("Overview");
const form = overview.addForm("", _ => { }, {
headers: this.headers,
traditionalSubmit: true,
fetchURL: this.info.api + "/guilds/" + this.id,
method: "PATCH"
});
form.addTextInput("Name:", "name", { initText: this.properties.name });
}
const s1 = settings.addButton("roles"); const s1 = settings.addButton("roles");
const permlist = []; const permlist = [];
for (const thing of this.roles) { for (const thing of this.roles) {

View file

@ -17,6 +17,9 @@ class InfiniteScroller {
timeout; timeout;
async getDiv(initialId, bottom = true) { async getDiv(initialId, bottom = true) {
//div.classList.add("flexttb") //div.classList.add("flexttb")
if (this.div) {
throw new Error("Div already exists, exiting.");
}
const scroll = document.createElement("div"); const scroll = document.createElement("div");
scroll.classList.add("flexttb", "scroller"); scroll.classList.add("flexttb", "scroller");
this.beenloaded = false; this.beenloaded = false;
@ -63,6 +66,7 @@ class InfiniteScroller {
averageheight = 60; averageheight = 60;
checkscroll() { checkscroll() {
if (this.beenloaded && this.div && !document.body.contains(this.div)) { if (this.beenloaded && this.div && !document.body.contains(this.div)) {
console.warn("not in document");
this.div = null; this.div = null;
} }
} }

View file

@ -544,6 +544,12 @@ class Options {
this.generate(text); this.generate(text);
return text; return text;
} }
addForm(name, onSubmit, { ltr = false, submitText = "Submit", fetchURL = "", headers = {}, method = "POST", traditionalSubmit = false } = {}) {
const options = new Form(name, this, onSubmit, { ltr, submitText, fetchURL, headers, method, traditionalSubmit });
this.options.push(options);
this.generate(options);
return options;
}
generate(elm) { generate(elm) {
const container = this.container.deref(); const container = this.container.deref();
if (container) { if (container) {

View file

@ -935,6 +935,10 @@ class Channel extends SnowFlake{
if(this.localuser.channelfocus!==this){ if(this.localuser.channelfocus!==this){
return; return;
} }
for(const elm of messages.getElementsByClassName("scroller")){
elm.remove();
console.warn("rouge element detected and removed")
}
messages.append(await this.infinite.getDiv(id)); messages.append(await this.infinite.getDiv(id));
this.infinite.updatestuff(); this.infinite.updatestuff();
this.infinite.watchForChange().then(async _=>{ this.infinite.watchForChange().then(async _=>{

View file

@ -55,7 +55,7 @@ class Guild extends SnowFlake{
Guild.contextmenu.addbutton("Create invite",function(this:Guild){ Guild.contextmenu.addbutton("Create invite",function(this:Guild){
},null,_=>true,_=>false); },null,_=>true,_=>false);
Guild.contextmenu.addbutton("Settings[temp]",function(this:Guild){ Guild.contextmenu.addbutton("Settings",function(this:Guild){
this.generateSettings(); this.generateSettings();
}); });
/* -----things left for later----- /* -----things left for later-----
@ -71,7 +71,16 @@ class Guild extends SnowFlake{
} }
generateSettings(){ generateSettings(){
const settings=new Settings("Settings for "+this.properties.name); const settings=new Settings("Settings for "+this.properties.name);
{
const overview=settings.addButton("Overview");
const form=overview.addForm("",_=>{},{
headers:this.headers,
traditionalSubmit:true,
fetchURL:this.info.api+"/guilds/"+this.id,
method:"PATCH"
})
form.addTextInput("Name:","name",{initText:this.properties.name})
}
const s1=settings.addButton("roles"); const s1=settings.addButton("roles");
const permlist:[Role,Permissions][]=[]; const permlist:[Role,Permissions][]=[];
for(const thing of this.roles){ for(const thing of this.roles){

View file

@ -17,6 +17,9 @@ class InfiniteScroller{
timeout:NodeJS.Timeout|null; timeout:NodeJS.Timeout|null;
async getDiv(initialId:string,bottom=true):Promise<HTMLDivElement>{ async getDiv(initialId:string,bottom=true):Promise<HTMLDivElement>{
//div.classList.add("flexttb") //div.classList.add("flexttb")
if(this.div){
throw new Error("Div already exists, exiting.")
}
const scroll=document.createElement("div"); const scroll=document.createElement("div");
scroll.classList.add("flexttb","scroller"); scroll.classList.add("flexttb","scroller");
this.beenloaded=false; this.beenloaded=false;
@ -66,6 +69,7 @@ class InfiniteScroller{
averageheight:number=60; averageheight:number=60;
checkscroll(){ checkscroll(){
if(this.beenloaded&&this.div&&!document.body.contains(this.div)){ if(this.beenloaded&&this.div&&!document.body.contains(this.div)){
console.warn("not in document");
this.div=null; this.div=null;
} }
} }

View file

@ -556,6 +556,12 @@ class Options implements OptionsElement<void>{
this.generate(text); this.generate(text);
return text; return text;
} }
addForm(name:string,onSubmit:((arg1:object)=>void),{ltr=false,submitText="Submit",fetchURL="",headers={},method="POST",traditionalSubmit=false}={}){
const options=new Form(name,this,onSubmit,{ltr,submitText,fetchURL,headers,method,traditionalSubmit});
this.options.push(options);
this.generate(options);
return options;
}
generate(elm:OptionsElement<any>){ generate(elm:OptionsElement<any>){
const container=this.container.deref(); const container=this.container.deref();
if(container){ if(container){