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.
-->
<script lang="ts">
import { generateId } from '@hcengineering/core'
import { Doc, generateId, Ref } from '@hcengineering/core'
import { ViewContext } from '@hcengineering/view'
import { onDestroy } from 'svelte'
import { ContextStore, contextStore } from '../context'
interface ViewContextWithId extends ViewContext {
id?: Ref<Doc>
}
export let context: ViewContext
const id = generateId()
$: len = $contextStore.contexts.findIndex((it) => (it as any).id === id)
onDestroy(() => {
contextStore.update((t) => {
return new ContextStore(t.contexts.slice(0, len ?? 0))
contextStore.update((cur) => {
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) => {
const pos = cur.contexts.findIndex((it) => (it as any).id === id)
const newCur = {
const contexts = cur.contexts as ViewContextWithId[]
const pos = contexts.findIndex((it) => it.id === id)
const newCur: ViewContextWithId = {
id,
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) {
len = cur.contexts.length
return new ContextStore([...cur.contexts, newCur])
return new ContextStore([...contexts, newCur])
}
len = pos
return new ContextStore([...cur.contexts.slice(0, pos), newCur])
return new ContextStore(contexts.map((it) => (it.id === id ? newCur : it)))
})
}
</script>