From 14e6d89c2b7694796b9c1753cf576c97f50aa10f Mon Sep 17 00:00:00 2001 From: Xu Han Date: Fri, 2 Feb 2024 16:08:00 +0800 Subject: [PATCH] implemented commitDraftComponents --- app/frontend/src/state/annotate/annotation.ts | 15 +++++++++++---- app/frontend/src/sync/update.ts | 5 +---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/frontend/src/state/annotate/annotation.ts b/app/frontend/src/state/annotate/annotation.ts index b51a7c0..446535e 100644 --- a/app/frontend/src/state/annotate/annotation.ts +++ b/app/frontend/src/state/annotate/annotation.ts @@ -26,8 +26,6 @@ export type State = { annotation: Annotation; setAnnotation: (annotation: Annotation | undefined) => void; - commitDraftComponents: () => void; - // general addComponent: (input: AddComponentInput, opts?: Options) => void; addComponents: (input: AddComponentsInput, opts?: Options) => void; @@ -55,6 +53,7 @@ export type State = { // other paste: (input: PasteInput, opts?: Options) => void; + commitDraftComponents: (opts?: Options) => void; }; export type SetEntityCategoryInput = { @@ -356,12 +355,20 @@ export const useStore = create()( }); }, - commitDraftComponents: () => { + commitDraftComponents: (opts = {}) => { set(s => { Object.values(s.annotation.entities).forEach(entity => { - Object.values(entity.geometry.slices).forEach(sliceComponents => { + Object.entries(entity.geometry.slices).forEach(([sidx, sliceComponents]) => { Object.values(sliceComponents).forEach(component => { delete component.draft; + + if (opts.broadcast) { + syncAnnotation.addComponent({ + sliceIndex: parseInt(sidx), + entityId: entity.id, + component, + }); + } }); }); }); diff --git a/app/frontend/src/sync/update.ts b/app/frontend/src/sync/update.ts index e4df7d9..2d96596 100644 --- a/app/frontend/src/sync/update.ts +++ b/app/frontend/src/sync/update.ts @@ -23,7 +23,7 @@ import {ComponentDetail, ComponentId, MaskComponent, PolychainComponent, Rectang import {initialVertexBezier} from 'common/annotation'; import {newComponentAdapter} from 'common/adapter'; -export const syncAnnotation: Omit = { +export const syncAnnotation: Omit = { setEntityCategory: (input: SetEntityCategoryInput) => { const {sliceIndex, entityId, category, entries} = input; let key = `${entityId}:${category}`; @@ -194,9 +194,6 @@ export const syncAnnotation: Omit = { break; } }, - commitDraftComponents: () => { - console.error('not implemented'); - }, updatePolychainVertices: (input: UpdatePolychainVerticesInput) => { const {componentId: cid, vertices} = input; const verts = annoDoc.polychainVerticesMap();