prevent multiple attempts to update (#5958)

This commit is contained in:
Vyacheslav Tumanov 2024-07-02 07:26:56 +05:00 committed by GitHub
parent 8003611c37
commit 02f965d8cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -15,7 +15,7 @@
<script lang="ts"> <script lang="ts">
import contact from '@hcengineering/contact' import contact from '@hcengineering/contact'
import { AccountArrayEditor } from '@hcengineering/contact-resources' import { AccountArrayEditor } from '@hcengineering/contact-resources'
import core, { Account, Ref, type SpaceType, type SpaceTypeDescriptor } from '@hcengineering/core' import core, { Account, reduceCalls, Ref, type SpaceType, type SpaceTypeDescriptor } from '@hcengineering/core'
import { createQuery, getClient } from '@hcengineering/presentation' import { createQuery, getClient } from '@hcengineering/presentation'
import { ButtonIcon, IconSquareExpand, Label, ModernButton, ModernEditbox, TextArea, Toggle } from '@hcengineering/ui' import { ButtonIcon, IconSquareExpand, Label, ModernButton, ModernEditbox, TextArea, Toggle } from '@hcengineering/ui'
@ -53,14 +53,14 @@
await client.update(type, { [field]: value }) await client.update(type, { [field]: value })
} }
async function changeMembers (members: Ref<Account>[]): Promise<void> { const changeMembers = reduceCalls(async function changeMembers (members: Ref<Account>[]): Promise<void> {
if (disabled || type === undefined) { if (disabled || type === undefined) {
return return
} }
const push = new Set<Ref<Account>>(members) const push = new Set<Ref<Account>>(members)
const pull = new Set<Ref<Account>>() const pull = new Set<Ref<Account>>()
for (const member of type.members ?? []) { for (const member of (type.members ?? []).filter((it, idx, arr) => arr.indexOf(it) === idx)) {
if (!push.has(member)) { if (!push.has(member)) {
pull.add(member) pull.add(member)
} else { } else {
@ -78,7 +78,7 @@
ops.update(type, { $pull: { members: pullMem } }) ops.update(type, { $pull: { members: pullMem } })
} }
await ops.commit() await ops.commit()
} })
</script> </script>
{#if descriptor !== undefined} {#if descriptor !== undefined}