UBERF-9334: fixed ActionContext managment (#8047)

Signed-off-by: Victor Ilyushchenko <alt13ri@gmail.com>
This commit is contained in:
Victor Ilyushchenko 2025-02-18 19:01:28 +03:00 committed by GitHub
parent 4af5dfdd78
commit c2d8a31534
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -13,37 +13,43 @@
// limitations under the License. // limitations under the License.
--> -->
<script lang="ts"> <script lang="ts">
import { generateId } from '@hcengineering/core' import { Doc, generateId, Ref } from '@hcengineering/core'
import { ViewContext } from '@hcengineering/view' import { ViewContext } from '@hcengineering/view'
import { onDestroy } from 'svelte' import { onDestroy } from 'svelte'
import { ContextStore, contextStore } from '../context' import { ContextStore, contextStore } from '../context'
interface ViewContextWithId extends ViewContext {
id?: Ref<Doc>
}
export let context: ViewContext export let context: ViewContext
const id = generateId() const id = generateId()
$: len = $contextStore.contexts.findIndex((it) => (it as any).id === id)
onDestroy(() => { onDestroy(() => {
contextStore.update((t) => { contextStore.update((cur) => {
return new ContextStore(t.contexts.slice(0, len ?? 0)) const contexts = cur.contexts as ViewContextWithId[]
const pos = contexts.findIndex((it) => it.id === id)
if (pos === -1) {
return cur
}
return new ContextStore(contexts.slice(0, pos))
}) })
}) })
$: { $: {
contextStore.update((cur) => { contextStore.update((cur) => {
const pos = cur.contexts.findIndex((it) => (it as any).id === id) const contexts = cur.contexts as ViewContextWithId[]
const newCur = { const pos = contexts.findIndex((it) => it.id === id)
const newCur: ViewContextWithId = {
id, id,
mode: context.mode, mode: context.mode,
application: context.application ?? cur.contexts[(pos !== -1 ? pos : cur.contexts.length) - 1]?.application application: context.application ?? contexts[(pos !== -1 ? pos : contexts.length) - 1]?.application
} }
if (pos === -1) { if (pos === -1) {
len = cur.contexts.length return new ContextStore([...contexts, newCur])
return new ContextStore([...cur.contexts, newCur])
} }
len = pos return new ContextStore(contexts.map((it) => (it.id === id ? newCur : it)))
return new ContextStore([...cur.contexts.slice(0, pos), newCur])
}) })
} }
</script> </script>