mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-23 08:48:01 +00:00
Save pin state (#5554)
Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
parent
d1e0790d08
commit
1075751fda
@ -1,6 +1,6 @@
|
|||||||
import { getResource } from '@hcengineering/platform'
|
import { getResource } from '@hcengineering/platform'
|
||||||
import { type ComponentType } from 'svelte'
|
import { type ComponentType } from 'svelte'
|
||||||
import { derived, writable } from 'svelte/store'
|
import { derived, get, writable } from 'svelte/store'
|
||||||
import type {
|
import type {
|
||||||
AnyComponent,
|
AnyComponent,
|
||||||
AnySvelteComponent,
|
AnySvelteComponent,
|
||||||
@ -63,6 +63,17 @@ function addPopup (props: CompAndProps): void {
|
|||||||
return popups
|
return popups
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function checkDockPosition (refId: string | undefined): boolean {
|
||||||
|
if (refId !== undefined && localStorage.getItem('dock-popup') === refId) {
|
||||||
|
const docked = get(dockStore)
|
||||||
|
if (docked === undefined) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
let popupId: number = 0
|
let popupId: number = 0
|
||||||
export function showPopup (
|
export function showPopup (
|
||||||
component: AnySvelteComponent | AnyComponent | ComponentType,
|
component: AnySvelteComponent | AnyComponent | ComponentType,
|
||||||
@ -91,17 +102,29 @@ export function showPopup (
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
const _element = element instanceof HTMLElement ? getPopupPositionElement(element) : element
|
const _element = element instanceof HTMLElement ? getPopupPositionElement(element) : element
|
||||||
|
const data: Omit<CompAndProps, 'is'> = {
|
||||||
|
id,
|
||||||
|
props,
|
||||||
|
element: _element,
|
||||||
|
onClose,
|
||||||
|
onUpdate,
|
||||||
|
close: closePopupOp,
|
||||||
|
options
|
||||||
|
}
|
||||||
|
if (checkDockPosition(options.refId)) {
|
||||||
|
data.dock = true
|
||||||
|
}
|
||||||
if (typeof component === 'string') {
|
if (typeof component === 'string') {
|
||||||
getResource(component)
|
getResource(component)
|
||||||
.then((resolved) => {
|
.then((resolved) => {
|
||||||
addPopup({ id, is: resolved, props, element: _element, onClose, onUpdate, close: closePopupOp, options })
|
addPopup({ ...data, is: resolved })
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
Analytics.handleError(err)
|
Analytics.handleError(err)
|
||||||
console.error(err)
|
console.error(err)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
addPopup({ id, is: component, props, element: _element, onClose, onUpdate, close: closePopupOp, options })
|
addPopup({ ...data, is: component })
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
id,
|
id,
|
||||||
@ -426,7 +449,11 @@ export function getEventPositionElement (evt: MouseEvent): PopupAlignment | unde
|
|||||||
|
|
||||||
export function pin (id: string): void {
|
export function pin (id: string): void {
|
||||||
popupstore.update((popups) => {
|
popupstore.update((popups) => {
|
||||||
|
const current = popups.find((p) => p.id === id)
|
||||||
popups.forEach((p) => (p.dock = p.id === id))
|
popups.forEach((p) => (p.dock = p.id === id))
|
||||||
|
if (current?.options.refId !== undefined) {
|
||||||
|
localStorage.setItem('dock-popup', current.options.refId)
|
||||||
|
}
|
||||||
return popups
|
return popups
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -436,4 +463,5 @@ export function unpin (): void {
|
|||||||
popups.forEach((p) => (p.dock = false))
|
popups.forEach((p) => (p.dock = false))
|
||||||
return popups
|
return popups
|
||||||
})
|
})
|
||||||
|
localStorage.removeItem('dock-popup')
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user