Showing members, allowing window resize

This commit is contained in:
metacryst
2026-01-14 17:47:59 -06:00
parent 0f400fe300
commit d57ab2bf7a
19 changed files with 94 additions and 87 deletions

View File

@@ -9,17 +9,24 @@ window.Socket = new Socket()
window.currentNetwork = ""
window.currentApp = ""
window.addEventListener("navigate", () => {
if(window.currentNetwork !== selectedNetwork()) {
window.currentNetwork = selectedNetwork()
async function openNetworkAndApp() {
if(window.currentNetwork !== networkFromPath()) {
window.currentNetwork = networkFromPath()
const event = new CustomEvent('networkchanged', {
detail: { name: currentNetwork }
});
window.dispatchEvent(event)
}
if(window.currentApp !== selectedApp()) {
window.currentApp = selectedApp()
if(!window.currentNetwork.data) {
let appData = await fetch("/app/orgdata/" + window.profile.networks[0].id, {method: "GET"})
let json = await appData.json()
window.currentNetwork.data = json
}
if(window.currentApp !== appFromPath()) {
window.currentApp = appFromPath()
const event = new CustomEvent('appchange', {
detail: { name: window.currentApp }
});
@@ -29,9 +36,22 @@ window.addEventListener("navigate", () => {
if(window.currentNetwork) { // 2 navigates fire on load: 1 initial, and one after the org redirect
document.title = `${window.currentNetwork.abbreviation} | Parchment`
}
})
}
window.selectedNetwork = function () {
window.addEventListener("navigate", openNetworkAndApp)
window.openApp = function(appName) {
const appUrl = appName.charAt(0).toLowerCase() + appName.slice(1);
let parts = window.location.pathname.split('/').filter(Boolean);
let newPath = "/" + parts[0] + "/" + appUrl
window.navigateTo(newPath)
const event = new CustomEvent('appchange', {
detail: { name: appName }
});
window.dispatchEvent(event)
}
window.networkFromPath = function () {
const pathname = window.location.pathname;
const firstSegment = pathname.split('/').filter(Boolean)[0] || '';
let networks = window.profile?.networks
@@ -43,7 +63,7 @@ window.selectedNetwork = function () {
}
}
window.selectedApp = function() {
window.appFromPath = function() {
const pathname = window.location.pathname;
const segments = pathname.split('/').filter(Boolean);
const secondSegment = segments[1] || "";
@@ -51,19 +71,6 @@ window.selectedApp = function() {
return capitalized
}
window.openApp = function(appName) {
const appUrl = appName.charAt(0).toLowerCase() + appName.slice(1);
let parts = window.location.pathname.split('/').filter(Boolean);
let newPath = "/" + parts[0] + "/" + appUrl
console.log(newPath)
window.navigateTo(newPath)
// window.history.replaceState({}, '', newPath);
const event = new CustomEvent('appchange', {
detail: { name: appName }
});
window.dispatchEvent(event)
}
async function getProfile() {
try {
const res = await fetch("/profile", {
@@ -77,38 +84,33 @@ async function getProfile() {
if (!res.ok) throw new Error("Failed to fetch profile");
const profile = await res.json();
console.log(profile);
console.log("getProfile: ", profile);
window.profile = profile
} catch (err) {
console.error(err);
}
}
async function setCurrentNetwork() {
function getInitialNetworkPath() {
let path = ""
let defaultNetwork = window.profile.networks[0]
if(!selectedNetwork()) {
if(!networkFromPath()) {
path += (defaultNetwork.abbreviation + "/")
}
if(!selectedApp()) {
if(!appFromPath()) {
let defaultApp = defaultNetwork.apps[0]
path += defaultApp.toLowerCase()
}
let appData = await fetch("/app/orgdata/" + defaultNetwork.id, {method: "GET"})
let json = await appData.json()
console.log(json)
window.comalData = json
return path
}
getProfile().then(async () => {
if(window.profile.networks.length > 0) {
let path = await setCurrentNetwork()
let path = getInitialNetworkPath()
window.navigateTo(path)
}