[BUG] fix double click to open app
This commit is contained in:
38
src/index.js
38
src/index.js
@@ -6,7 +6,15 @@ let Global = class {
|
||||
Socket = new Socket()
|
||||
profile = null
|
||||
currentNetwork = ""
|
||||
currentApp = ""
|
||||
lastApp = ""
|
||||
|
||||
currentApp() {
|
||||
const pathname = window.location.pathname;
|
||||
const segments = pathname.split('/').filter(Boolean);
|
||||
const secondSegment = segments[1] || ""
|
||||
const capitalized = secondSegment.charAt(0).toUpperCase() + secondSegment.slice(1);
|
||||
return capitalized
|
||||
}
|
||||
|
||||
openApp = function(appName) {
|
||||
const appUrl = appName.charAt(0).toLowerCase() + appName.slice(1);
|
||||
@@ -30,17 +38,13 @@ let Global = class {
|
||||
onNavigate = async () => {
|
||||
|
||||
let selectedNetwork = this.networkFromPath()
|
||||
let selectedApp = this.appFromPath()
|
||||
|
||||
if(!selectedNetwork) {
|
||||
if (!this.currentNetwork || this.currentNetwork === this.profile) {
|
||||
let path = `/${this.getDefaultNetworkName()}/${this.getDefaultAppName()}`
|
||||
history.replaceState({}, '', path)
|
||||
} else {
|
||||
let path = `/${this.currentNetwork.abbreviation}${window.location.pathname}`
|
||||
history.replaceState({}, '', path)
|
||||
}
|
||||
} else if(!selectedApp) {
|
||||
} else if(!this.currentApp()) {
|
||||
if(this.currentNetwork === window.profile) {
|
||||
history.replaceState({}, '', `${window.location.pathname}/${window.profile.apps[0]}`)
|
||||
} else {
|
||||
@@ -49,14 +53,14 @@ let Global = class {
|
||||
}
|
||||
|
||||
selectedNetwork = this.networkFromPath()
|
||||
selectedApp = this.appFromPath()
|
||||
|
||||
let networkChanged = this.currentNetwork !== selectedNetwork
|
||||
let appChanged = this.currentApp !== selectedApp
|
||||
let appChanged = this.currentApp() !== this.lastApp
|
||||
if(appChanged) {
|
||||
this.lastApp = this.currentApp()
|
||||
}
|
||||
|
||||
if(networkChanged) {
|
||||
console.log("onNavigate: network changed ->", selectedNetwork?.abbreviation)
|
||||
this.currentNetwork = selectedNetwork
|
||||
this.currentApp = selectedApp
|
||||
const event = new CustomEvent('networkchange', {
|
||||
detail: { name: this.currentNetwork }
|
||||
});
|
||||
@@ -68,10 +72,8 @@ let Global = class {
|
||||
}
|
||||
|
||||
if(appChanged && !networkChanged) {
|
||||
console.log("onNavigate: app changed ->", selectedApp, "\n")
|
||||
this.currentApp = selectedApp
|
||||
const event = new CustomEvent('appchange', {
|
||||
detail: { name: this.currentApp }
|
||||
detail: { name: this.currentApp() }
|
||||
});
|
||||
window.dispatchEvent(event)
|
||||
}
|
||||
@@ -112,14 +114,6 @@ let Global = class {
|
||||
}
|
||||
}
|
||||
|
||||
appFromPath = function() {
|
||||
const pathname = window.location.pathname;
|
||||
const segments = pathname.split('/').filter(Boolean);
|
||||
const secondSegment = segments[1] || ""
|
||||
const capitalized = secondSegment.charAt(0).toUpperCase() + secondSegment.slice(1);
|
||||
return capitalized
|
||||
}
|
||||
|
||||
async getProfile() {
|
||||
try {
|
||||
const res = await fetch("/profile", {
|
||||
|
||||
Reference in New Issue
Block a user