From c02223d6b4630b04441bbcd1b724cd97cba54143 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Mon, 24 May 2021 11:38:33 +0900 Subject: [PATCH] Update useTeacherList.ts --- frontend/composables/useTeacherList.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/frontend/composables/useTeacherList.ts b/frontend/composables/useTeacherList.ts index 0362b979..aae1b88b 100644 --- a/frontend/composables/useTeacherList.ts +++ b/frontend/composables/useTeacherList.ts @@ -21,7 +21,7 @@ export const useTeacherList = (service: any) => { await getTeacherList(projectId, exampleId) } - const annotateExample = async( + const annotateLabel = async( projectId: string, exampleId: number, labelId: number @@ -46,10 +46,27 @@ export const useTeacherList = (service: any) => { await getTeacherList(projectId, exampleId) } + const annotateOrRemoveLabel = async( + projectId: string, + exampleId: number, + srcKey: string + ) => { + const labelId = parseInt(srcKey, 10) + // @ts-ignore + const annotation = state.teacherList.find(item => item.label === labelId) + if (annotation) { + // @ts-ignore + await removeTeacher(projectId, exampleId, annotation.id) + } else { + await annotateLabel(projectId, exampleId, labelId) + } + } + return { state, getTeacherList, - annotateExample, + annotateLabel, + annotateOrRemoveLabel, removeTeacher, clearTeacherList, autoLabel,