Skip to content

Commit

Permalink
implemented commitDraftComponents
Browse files Browse the repository at this point in the history
  • Loading branch information
hxhxhx88 committed Feb 2, 2024
1 parent 036e55a commit 14e6d89
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
15 changes: 11 additions & 4 deletions app/frontend/src/state/annotate/annotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,6 +53,7 @@ export type State = {

// other
paste: (input: PasteInput, opts?: Options) => void;
commitDraftComponents: (opts?: Options) => void;
};

export type SetEntityCategoryInput = {
Expand Down Expand Up @@ -356,12 +355,20 @@ export const useStore = create<State>()(
});
},

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,
});
}
});
});
});
Expand Down
5 changes: 1 addition & 4 deletions app/frontend/src/sync/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {ComponentDetail, ComponentId, MaskComponent, PolychainComponent, Rectang
import {initialVertexBezier} from 'common/annotation';
import {newComponentAdapter} from 'common/adapter';

export const syncAnnotation: Omit<State, 'annotation' | 'setAnnotation'> = {
export const syncAnnotation: Omit<State, 'annotation' | 'setAnnotation' | 'commitDraftComponents'> = {
setEntityCategory: (input: SetEntityCategoryInput) => {
const {sliceIndex, entityId, category, entries} = input;
let key = `${entityId}:${category}`;
Expand Down Expand Up @@ -194,9 +194,6 @@ export const syncAnnotation: Omit<State, 'annotation' | 'setAnnotation'> = {
break;
}
},
commitDraftComponents: () => {
console.error('not implemented');
},
updatePolychainVertices: (input: UpdatePolychainVerticesInput) => {
const {componentId: cid, vertices} = input;
const verts = annoDoc.polychainVerticesMap();
Expand Down

0 comments on commit 14e6d89

Please sign in to comment.