diff --git a/packages/ui/src/location.ts b/packages/ui/src/location.ts index fdda0db464..dc9232fdb8 100644 --- a/packages/ui/src/location.ts +++ b/packages/ui/src/location.ts @@ -114,7 +114,7 @@ declare global { } } const embeddedPlatform = window.embeddedPlatform ?? false -const locationWritable = writable(embeddedPlatform ? { path: [] } : getRawCurrentLocation()) +const locationWritable = writable(getRawCurrentLocation()) console.log('embeddedPlatform', window.embeddedPlatform) @@ -124,7 +124,15 @@ if (!embeddedPlatform) { }) } -export const location = embeddedPlatform ? locationWritable : derived(locationWritable, (loc) => loc) +export const location = derived(locationWritable, (loc) => justClone(loc)) + +/** + * @public + */ +export function getLocation (): PlatformLocation { + return justClone(get(location)) +} + export const resolvedLocationStore = writable(getRawCurrentLocation()) let resolvedLocation = getRawCurrentLocation() diff --git a/packages/ui/src/panelup.ts b/packages/ui/src/panelup.ts index 6b7a7e491c..df6a6b3f61 100644 --- a/packages/ui/src/panelup.ts +++ b/packages/ui/src/panelup.ts @@ -1,5 +1,5 @@ -import { get, writable } from 'svelte/store' -import { location, navigate } from './location' +import { writable } from 'svelte/store' +import { getLocation, navigate } from './location' import { AnyComponent, PopupAlignment } from './types' export interface PanelProps { @@ -29,7 +29,7 @@ export function showPanel ( rightSection?: AnyComponent ): void { openPanel(component, _id, _class, element, rightSection) - const loc = get(location) + const loc = getLocation() if (loc.fragment !== currentLocation) { loc.fragment = currentLocation navigate(loc) @@ -58,7 +58,7 @@ export function closePanel (shoulRedirect: boolean = true): void { return { panel: undefined } }) if (shoulRedirect) { - const loc = get(location) + const loc = getLocation() loc.fragment = undefined currentLocation = undefined navigate(loc) diff --git a/plugins/attachment-resources/src/components/FileBrowser.svelte b/plugins/attachment-resources/src/components/FileBrowser.svelte index 9b68a033c7..591e5ae841 100644 --- a/plugins/attachment-resources/src/components/FileBrowser.svelte +++ b/plugins/attachment-resources/src/components/FileBrowser.svelte @@ -17,9 +17,8 @@ import contact, { Employee, EmployeeAccount } from '@hcengineering/contact' import core, { Class, getCurrentAccount, Ref, Space } from '@hcengineering/core' import { getClient } from '@hcengineering/presentation' - import { Label, Loading, location, navigate, TabList, SearchEdit } from '@hcengineering/ui' + import { Label, Loading, navigate, TabList, SearchEdit, getLocation } from '@hcengineering/ui' import view from '@hcengineering/view' - import { get } from 'svelte/store' import { dateFileBrowserFilters, FileBrowserSortMode, fileTypeFileBrowserFilters, sortModeToOptionObject } from '..' import attachment from '../plugin' import AttachmentsGalleryView from './AttachmentsGalleryView.svelte' @@ -30,11 +29,11 @@ export let withHeader: boolean = true const client = getClient() - const loc = get(location) + const loc = getLocation() const spaceId: Ref | undefined = loc.query?.spaceId as Ref | undefined $: if (spaceId !== undefined) { - const loc = get(location) + const loc = getLocation() loc.query = undefined navigate(loc) } diff --git a/plugins/chunter-resources/src/components/ChannelView.svelte b/plugins/chunter-resources/src/components/ChannelView.svelte index 950442ba19..1c5403fd46 100644 --- a/plugins/chunter-resources/src/components/ChannelView.svelte +++ b/plugins/chunter-resources/src/components/ChannelView.svelte @@ -18,8 +18,7 @@ import { ChunterMessage, ChunterSpace, Message } from '@hcengineering/chunter' import { Ref, Space, generateId, getCurrentAccount } from '@hcengineering/core' import { createQuery, getClient } from '@hcengineering/presentation' - import { location, navigate } from '@hcengineering/ui' - import { get } from 'svelte/store' + import { getLocation, navigate } from '@hcengineering/ui' import { createBacklinks } from '../backlinks' import chunter from '../plugin' import Channel from './Channel.svelte' @@ -59,7 +58,7 @@ } function openThread (_id: Ref) { - const loc = get(location) + const loc = getLocation() loc.path[4] = _id navigate(loc) } diff --git a/plugins/chunter-resources/src/index.ts b/plugins/chunter-resources/src/index.ts index 04604108e7..7b83b5eae5 100644 --- a/plugins/chunter-resources/src/index.ts +++ b/plugins/chunter-resources/src/index.ts @@ -28,7 +28,7 @@ import { NotificationClientImpl } from '@hcengineering/notification-resources' import { IntlString, Resources, translate } from '@hcengineering/platform' import preference from '@hcengineering/preference' import { MessageBox, getClient } from '@hcengineering/presentation' -import { location, navigate, showPopup } from '@hcengineering/ui' +import { getLocation, navigate, showPopup } from '@hcengineering/ui' import ChannelHeader from './components/ChannelHeader.svelte' import ChannelPresenter from './components/ChannelPresenter.svelte' import ChannelView from './components/ChannelView.svelte' @@ -57,7 +57,7 @@ import TxCommentCreate from './components/activity/TxCommentCreate.svelte' import TxMessageCreate from './components/activity/TxMessageCreate.svelte' import notification from '@hcengineering/notification' -import { get, writable } from 'svelte/store' +import { writable } from 'svelte/store' import { updateBacklinksList } from './backlinks' import { getDmName, getLink, getTitle, resolveLocation } from './utils' @@ -179,7 +179,7 @@ export async function ArchiveChannel (channel: Channel, evt: any, afterArchive?: client.update(channel, { archived: true }) if (afterArchive != null) afterArchive() - const loc = get(location) + const loc = getLocation() if (loc.path[3] === channel._id) { loc.path.length = 3 navigate(loc) diff --git a/plugins/chunter-resources/src/utils.ts b/plugins/chunter-resources/src/utils.ts index 625ad86700..1c13c7d347 100644 --- a/plugins/chunter-resources/src/utils.ts +++ b/plugins/chunter-resources/src/utils.ts @@ -6,7 +6,7 @@ import { Asset } from '@hcengineering/platform' import { getClient } from '@hcengineering/presentation' import { getPanelURI, - location, + getLocation, Location, navigate, ResolvedLocation, @@ -89,7 +89,7 @@ export function getDay (time: Timestamp): Timestamp { } export function openMessageFromSpecial (message: ChunterMessage): void { - const loc = get(location) + const loc = getLocation() if (message.attachedToClass === chunter.class.ChunterSpace) { loc.path.length = 4 @@ -103,7 +103,7 @@ export function openMessageFromSpecial (message: ChunterMessage): void { } export function navigateToSpecial (specialId: string): void { - const loc = get(location) + const loc = getLocation() loc.path[2] = chunterId loc.path[3] = specialId navigate(loc) diff --git a/plugins/setting-resources/src/components/ClassSetting.svelte b/plugins/setting-resources/src/components/ClassSetting.svelte index cf17be64c5..607031421b 100644 --- a/plugins/setting-resources/src/components/ClassSetting.svelte +++ b/plugins/setting-resources/src/components/ClassSetting.svelte @@ -16,8 +16,7 @@ import core, { Class, Doc, Obj, Ref } from '@hcengineering/core' import { IntlString } from '@hcengineering/platform' import { createQuery, getClient } from '@hcengineering/presentation' - import { AnySvelteComponent, location, Icon, Label, navigate } from '@hcengineering/ui' - import { get } from 'svelte/store' + import { AnySvelteComponent, getLocation, Icon, Label, navigate } from '@hcengineering/ui' import setting from '../plugin' import { filterDescendants } from '../utils' import ClassAttributes from './ClassAttributes.svelte' @@ -33,14 +32,14 @@ | undefined export let withoutHeader = false - const loc = get(location) + const loc = getLocation() const client = getClient() const hierarchy = client.getHierarchy() let _class: Ref> | undefined = ofClass ?? (loc.query?._class as Ref> | undefined) $: if (_class !== undefined && ofClass === undefined) { - const loc = get(location) + const loc = getLocation() loc.query = undefined navigate(loc) } diff --git a/plugins/workbench-resources/src/components/Workbench.svelte b/plugins/workbench-resources/src/components/Workbench.svelte index 614e2a5de8..a3c82eea6b 100644 --- a/plugins/workbench-resources/src/components/Workbench.svelte +++ b/plugins/workbench-resources/src/components/Workbench.svelte @@ -41,6 +41,7 @@ deviceOptionsStore as deviceInfo, getCurrentLocation, location, + getLocation, navigate, openPanel, popupstore, @@ -59,7 +60,6 @@ } from '@hcengineering/view-resources' import type { Application, NavigatorModel, SpecialNavModel, ViewConfiguration } from '@hcengineering/workbench' import { getContext, onDestroy, onMount, tick } from 'svelte' - import { get } from 'svelte/store' import { subscribeMobile } from '../mobile' import workbench from '../plugin' import { workspacesStore } from '../utils' @@ -423,7 +423,7 @@ } function closeAside (): void { - const loc = get(location) + const loc = getLocation() loc.path.length = 4 checkOnHide() navigate(loc)