mirror of
https://github.com/hcengineering/platform.git
synced 2025-05-10 09:22:23 +00:00
UBERF-9334: fixed ActionContext managment (#8047)
Signed-off-by: Victor Ilyushchenko <alt13ri@gmail.com>
This commit is contained in:
parent
4af5dfdd78
commit
c2d8a31534
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user