mirror of
https://github.com/hcengineering/platform.git
synced 2025-05-11 18:01:59 +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.
|
// 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>
|
||||||
|
Loading…
Reference in New Issue
Block a user