switching networks works, established server functions
This commit is contained in:
@@ -8,8 +8,8 @@ class Home extends Shadow {
|
||||
ZStack(() => {
|
||||
|
||||
ZStack(() => {
|
||||
console.log(window.currentApp)
|
||||
switch(window.currentApp) {
|
||||
console.log(global.currentApp)
|
||||
switch(global.currentApp) {
|
||||
case "Dashboard":
|
||||
Dashboard()
|
||||
break;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class Dashboard extends Shadow {
|
||||
render() {
|
||||
VStack(() => {
|
||||
console.log(window.currentNetwork)
|
||||
console.log(global.currentNetwork)
|
||||
})
|
||||
.width(100, pct)
|
||||
.height(100, pct)
|
||||
|
||||
@@ -4,45 +4,45 @@ import "./Home.js"
|
||||
import util from "./util.js"
|
||||
window.util = util
|
||||
|
||||
window.Socket = new Socket()
|
||||
global.Socket = new Socket()
|
||||
|
||||
window.currentNetwork = ""
|
||||
window.currentApp = ""
|
||||
global.currentNetwork = ""
|
||||
global.currentApp = ""
|
||||
|
||||
async function openNetworkAndApp() {
|
||||
// console.log("currentApp: ", currentApp, "currentnet: ", currentNetwork, "nfrompath: ", networkFromPath(), "afrompath", appFromPath())
|
||||
|
||||
if(window.currentNetwork !== networkFromPath()) {
|
||||
window.currentNetwork = networkFromPath()
|
||||
const event = new CustomEvent('networkchanged', {
|
||||
if(global.currentNetwork !== networkFromPath()) {
|
||||
global.currentNetwork = networkFromPath()
|
||||
const event = new CustomEvent('networkchange', {
|
||||
detail: { name: currentNetwork }
|
||||
});
|
||||
window.dispatchEvent(event)
|
||||
}
|
||||
|
||||
if(!window.currentNetwork.data) {
|
||||
let appData = await fetch("/app/orgdata/" + window.profile.networks[0].id, {method: "GET"})
|
||||
if(!global.currentNetwork.data) {
|
||||
let appData = await fetch("/app/orgdata/" + global.profile.networks[0].id, {method: "GET"})
|
||||
let json = await appData.json()
|
||||
window.currentNetwork.data = json
|
||||
global.currentNetwork.data = json
|
||||
}
|
||||
|
||||
console.log("current: ", window.currentApp, "afrompath: ", appFromPath())
|
||||
if(window.currentApp !== appFromPath()) {
|
||||
window.currentApp = appFromPath()
|
||||
console.log("current: ", global.currentApp, "afrompath: ", appFromPath())
|
||||
if(global.currentApp !== appFromPath()) {
|
||||
global.currentApp = appFromPath()
|
||||
const event = new CustomEvent('appchange', {
|
||||
detail: { name: window.currentApp }
|
||||
detail: { name: global.currentApp }
|
||||
});
|
||||
window.dispatchEvent(event)
|
||||
}
|
||||
|
||||
if(window.currentNetwork) { // 2 navigates fire on load: 1 initial, and one after the org redirect
|
||||
document.title = `${window.currentNetwork.abbreviation} | Parchment`
|
||||
if(global.currentNetwork) { // 2 navigates fire on load: 1 initial, and one after the org redirect
|
||||
document.title = `${global.currentNetwork.abbreviation} | Parchment`
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("navigate", openNetworkAndApp)
|
||||
|
||||
window.openApp = function(appName) {
|
||||
global.currentApp = function(appName) {
|
||||
const appUrl = appName.charAt(0).toLowerCase() + appName.slice(1);
|
||||
let parts = window.location.pathname.split('/').filter(Boolean);
|
||||
let newPath = "/" + parts[0] + "/" + appUrl
|
||||
@@ -56,7 +56,7 @@ window.openApp = function(appName) {
|
||||
window.networkFromPath = function () {
|
||||
const pathname = window.location.pathname;
|
||||
const firstSegment = pathname.split('/').filter(Boolean)[0] || '';
|
||||
let networks = window.profile?.networks
|
||||
let networks = global.profile?.networks
|
||||
for(let i = 0; i < networks.length; i++) {
|
||||
let network = networks[i]
|
||||
if(network.abbreviation === firstSegment) {
|
||||
@@ -87,7 +87,7 @@ async function getProfile() {
|
||||
|
||||
const profile = await res.json();
|
||||
console.log("getProfile: ", profile);
|
||||
window.profile = profile
|
||||
global.profile = profile
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
@@ -95,7 +95,7 @@ async function getProfile() {
|
||||
|
||||
function getInitialNetworkPath() {
|
||||
let path = ""
|
||||
let defaultNetwork = window.profile.networks[0]
|
||||
let defaultNetwork = global.profile.networks[0]
|
||||
|
||||
if(!networkFromPath()) {
|
||||
path += (defaultNetwork.abbreviation + "/")
|
||||
@@ -111,7 +111,7 @@ function getInitialNetworkPath() {
|
||||
|
||||
getProfile().then(async () => {
|
||||
|
||||
if(window.profile.networks.length > 0) {
|
||||
if(global.profile.networks.length > 0) {
|
||||
let path = getInitialNetworkPath()
|
||||
window.navigateTo(path)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user