mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-27 03:54:57 +02:00
UBER-477: Uberflow dependencies (#3440)
Signed-off-by: Andrey Sobolev <haiodo@gmail.com>
This commit is contained in:
@@ -39,9 +39,16 @@
|
||||
if (last === null) {
|
||||
last = localStorage.getItem('platform_last_loc')
|
||||
}
|
||||
let useDefault = true
|
||||
if (last !== null) {
|
||||
navigate(JSON.parse(last))
|
||||
} else {
|
||||
const storedLoc = JSON.parse(last)
|
||||
const key = storedLoc.path?.[0]
|
||||
if (Array.from(routes.values()).includes(key) || Array.from(routes.keys()).includes(key)) {
|
||||
useDefault = false
|
||||
navigate(storedLoc)
|
||||
}
|
||||
}
|
||||
if (useDefault) {
|
||||
application = getMetadata(uiPlugin.metadata.DefaultApplication)
|
||||
if (application !== undefined) {
|
||||
const loc = getCurrentLocation()
|
||||
@@ -187,6 +194,7 @@
|
||||
// height: var(--app-height);
|
||||
|
||||
.antiStatusBar {
|
||||
-webkit-app-region: drag;
|
||||
min-height: var(--status-bar-height);
|
||||
height: var(--status-bar-height);
|
||||
// min-width: 600px;
|
||||
@@ -214,6 +222,7 @@
|
||||
user-select: none;
|
||||
}
|
||||
.widget {
|
||||
-webkit-app-region: no-drag;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
font-size: 14px;
|
||||
|
||||
+32
-11
@@ -13,7 +13,7 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import { derived, writable } from 'svelte/store'
|
||||
import { derived, get, writable } from 'svelte/store'
|
||||
import { closePopup } from './popups'
|
||||
import justClone from 'just-clone'
|
||||
import { Location as PlatformLocation } from './types'
|
||||
@@ -100,7 +100,7 @@ function parseHash (hash: string): string {
|
||||
|
||||
// ------------------------
|
||||
|
||||
export function getCurrentLocation (): PlatformLocation {
|
||||
export function getRawCurrentLocation (): PlatformLocation {
|
||||
return parseLocation(window.location)
|
||||
}
|
||||
|
||||
@@ -108,26 +108,47 @@ export function getCurrentResolvedLocation (): PlatformLocation {
|
||||
return justClone(resolvedLocation)
|
||||
}
|
||||
|
||||
const locationWritable = writable(getCurrentLocation())
|
||||
window.addEventListener('popstate', () => {
|
||||
locationWritable.set(getCurrentLocation())
|
||||
})
|
||||
declare global {
|
||||
interface Window {
|
||||
embeddedPlatform?: boolean
|
||||
}
|
||||
}
|
||||
const embeddedPlatform = window.embeddedPlatform ?? false
|
||||
const locationWritable = writable(embeddedPlatform ? { path: [] } : getRawCurrentLocation())
|
||||
|
||||
export const location = derived(locationWritable, (loc) => loc)
|
||||
export const resolvedLocationStore = writable(getCurrentLocation())
|
||||
let resolvedLocation = getCurrentLocation()
|
||||
console.log('embeddedPlatform', window.embeddedPlatform)
|
||||
|
||||
if (!embeddedPlatform) {
|
||||
window.addEventListener('popstate', () => {
|
||||
locationWritable.set(getRawCurrentLocation())
|
||||
})
|
||||
}
|
||||
|
||||
export const location = embeddedPlatform ? locationWritable : derived(locationWritable, (loc) => loc)
|
||||
export const resolvedLocationStore = writable(getRawCurrentLocation())
|
||||
let resolvedLocation = getRawCurrentLocation()
|
||||
|
||||
export function setResolvedLocation (location: PlatformLocation): void {
|
||||
resolvedLocation = location
|
||||
resolvedLocationStore.set(justClone(location))
|
||||
}
|
||||
|
||||
export function getCurrentLocation (): PlatformLocation {
|
||||
if (embeddedPlatform) {
|
||||
return justClone(get(locationWritable))
|
||||
}
|
||||
return getRawCurrentLocation()
|
||||
}
|
||||
|
||||
export function navigate (location: PlatformLocation, store = true): boolean {
|
||||
closePopup()
|
||||
const cur = locationToUrl(getCurrentLocation())
|
||||
const url = locationToUrl(location)
|
||||
if (locationToUrl(getCurrentLocation()) !== url) {
|
||||
if (cur !== url) {
|
||||
if (store) {
|
||||
history.pushState(null, '', url)
|
||||
if (!embeddedPlatform) {
|
||||
history.pushState(null, '', url)
|
||||
}
|
||||
localStorage.setItem('platform_last_loc', JSON.stringify(location))
|
||||
if (location.path[1] !== undefined) {
|
||||
localStorage.setItem(`platform_last_loc_${location.path[1]}`, JSON.stringify(location))
|
||||
|
||||
Reference in New Issue
Block a user