move connections + dev portal to user settings

This commit is contained in:
TomatoCake 2024-08-12 21:00:12 +02:00
parent 8c39561906
commit f8b4d12476
4 changed files with 44 additions and 77 deletions

View file

@ -46,14 +46,12 @@
<div id="user-actions"> <div id="user-actions">
<h2 id="settings"></h2> <h2 id="settings"></h2>
<h2 id="connections">🔗</h2>
<h2 id="dev-portal">🤖</h2>
</div> </div>
</div> </div>
</div> </div>
<div class="flexttb messageflex"> <div class="flexttb messageflex">
<div class="servertd servernamediv"> <div class="servertd channelnamediv">
<span id="mobileback" hidden=true></span><span id="channelname">Channel</span> <span id="mobileback" hidden></span><span id="channelname">Channel</span>
</div> </div>
<div id="channelw"> <div id="channelw">
<div id="messagecontainer"> <div id="messagecontainer">

View file

@ -194,14 +194,6 @@ function userSettings(){
thisuser.showusersettings(); thisuser.showusersettings();
} }
document.getElementById("settings").onclick=userSettings; document.getElementById("settings").onclick=userSettings;
function userConnections(){
thisuser.userConnections.show();
}
document.getElementById("connections").onclick=userConnections;
function devPortal(){
thisuser.devPortal.show();
}
document.getElementById("dev-portal").onclick=devPortal;
if(mobile){ if(mobile){
document.getElementById("channelw").onclick=function(){ document.getElementById("channelw").onclick=function(){

View file

@ -254,7 +254,6 @@ class Localuser{
break; break;
case "READY": case "READY":
this.gottenReady(temp as readyjson); this.gottenReady(temp as readyjson);
this.genusersettings();
break; break;
case "MESSAGE_UPDATE": case "MESSAGE_UPDATE":
const message=SnowFlake.getSnowFlakeFromID(temp.d.id,Message).getObject(); const message=SnowFlake.getSnowFlakeFromID(temp.d.id,Message).getObject();
@ -825,26 +824,14 @@ class Localuser{
}) })
} }
} }
settings.show(); {
} const connections=settings.addButton("Connections");
/** const connectionContainer=document.createElement("div");
@deprecated connectionContainer.id="connection-container";
This should be made to not be used anymore
**/
genusersettings():void{
const connectionContainer=document.createElement("div");
connectionContainer.id="connection-container";
this.userConnections=new Dialog(
["html",
connectionContainer
], () => {}, async () => {
connectionContainer.innerHTML="";
const res=await fetch(this.info.api+"/connections", {
headers: this.headers
});
const json=await res.json();
fetch(this.info.api+"/connections", {
headers: this.headers
}).then(r => r.json()).then(json => {
Object.keys(json).sort(key => json[key].enabled ? -1 : 1).forEach(key => { Object.keys(json).sort(key => json[key].enabled ? -1 : 1).forEach(key => {
const connection=json[key]; const connection=json[key];
@ -853,68 +840,57 @@ class Localuser{
if (connection.enabled) { if (connection.enabled) {
container.addEventListener("click", async () => { container.addEventListener("click", async () => {
const connectionRes=await fetch(this.info.api+"/connections/" + key + "/authorize", { const connectionRes=await fetch(this.info.api+"/connections/"+key+"/authorize", {
headers: this.headers headers: this.headers
}); });
const connectionJSON=await connectionRes.json(); const connectionJSON=await connectionRes.json();
window.open(connectionJSON.url, "_blank", "noopener noreferrer"); window.open(connectionJSON.url, "_blank", "noopener noreferrer");
}) })
} else { } else {
container.classList.add("disabled") container.classList.add("disabled");
container.title="This connection has been disabled server-side." container.title="This connection has been disabled server-side.";
} }
connectionContainer.appendChild(container); connectionContainer.appendChild(container);
}) })
} })
); connections.addHTMLArea(connectionContainer);
}
{
const devPortal=settings.addButton("Developer Portal");
let appName=""; let appName="";
const appListContainer=document.createElement("div"); devPortal.addTextInput("Name:", value => {
appListContainer.id="app-list-container"; appName=value
this.devPortal=new Dialog( });
["vdiv", devPortal.addButtonInput("", "Create application", async () => {
["hdiv", if (appName.trim().length == 0) {
["textbox", "Name:", appName, event => { return alert("Please enter a name for the application.");
appName=event.target.value; }
}],
["button",
"",
"Create application",
async () => {
if (appName.trim().length == 0) return alert("Please enter a name for the application.");
const res=await fetch(this.info.api+"/applications", {
method: "POST",
headers: this.headers,
body: JSON.stringify({
name: appName
})
});
const json=await res.json();
this.manageApplication(json.id);
this.devPortal.hide();
}
]
],
["html",
appListContainer
]
], () => {}, async () => {
appListContainer.innerHTML="";
const res=await fetch(this.info.api+"/applications", { const res=await fetch(this.info.api+"/applications", {
headers: this.headers method: "POST",
headers: this.headers,
body: JSON.stringify({
name: appName
})
}); });
const json=await res.json(); const json=await res.json();
this.manageApplication(json.id);
})
const appListContainer=document.createElement("div");
appListContainer.id="app-list-container";
fetch(this.info.api+"/applications", {
headers: this.headers
}).then(r => r.json()).then(json => {
json.forEach(application => { json.forEach(application => {
const container=document.createElement("div"); const container=document.createElement("div");
if (application.cover_image) { if (application.cover_image) {
const cover=document.createElement("img"); const cover=document.createElement("img");
cover.crossOrigin="anonymous"; cover.crossOrigin="anonymous";
cover.src=this.info.cdn+"/app-icons/" + application.id + "/" + application.cover_image + ".png?size=256"; cover.src=this.info.cdn+"/app-icons/"+application.id+"/"+application.cover_image+".png?size=256";
cover.alt=""; cover.alt="";
cover.loading="lazy"; cover.loading="lazy";
container.appendChild(cover); container.appendChild(cover);
@ -925,13 +901,14 @@ class Localuser{
container.appendChild(name); container.appendChild(name);
container.addEventListener("click", async () => { container.addEventListener("click", async () => {
this.devPortal.hide();
this.manageApplication(application.id); this.manageApplication(application.id);
}); });
appListContainer.appendChild(container); appListContainer.appendChild(container);
}) })
} })
) devPortal.addHTMLArea(appListContainer);
}
settings.show();
} }
async manageApplication(appId="") { async manageApplication(appId="") {
const res=await fetch(this.info.api+"/applications/" + appId, { const res=await fetch(this.info.api+"/applications/" + appId, {

View file

@ -800,7 +800,7 @@ textarea:focus-visible,
padding: .03in; padding: .03in;
} }
.servernamediv { .channelnamediv {
width: 100%; width: 100%;
/* max-width: 100%; */ /* max-width: 100%; */
border-left: solid .01in var(--black); border-left: solid .01in var(--black);