feat: scaffold complete danable frontend architecture with all pages, layouts, stores, and 3 annotator modes
This commit is contained in:
commit
78848dd7d1
173 changed files with 18649 additions and 0 deletions
45
src/services/labelService.ts
Normal file
45
src/services/labelService.ts
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import { LabelClass } from '@/types'
|
||||
import { getColorForClass } from '@/utils/colors'
|
||||
import { delay } from './api'
|
||||
import { getMockDb, saveMockDb } from './mockData'
|
||||
|
||||
export async function getLabels(projectId: string): Promise<LabelClass[]> {
|
||||
await delay(80)
|
||||
const db = getMockDb()
|
||||
const project = db.projects.find((p) => p.id === projectId || p.slug === projectId)
|
||||
return project ? project.classes : db.projects[0]?.classes ?? []
|
||||
}
|
||||
|
||||
export async function createLabel(
|
||||
projectId: string,
|
||||
input: { name: string; color?: string }
|
||||
): Promise<LabelClass> {
|
||||
await delay(140)
|
||||
const db = getMockDb()
|
||||
const project = db.projects.find((p) => p.id === projectId || p.slug === projectId)
|
||||
if (!project) {
|
||||
throw new Error(`Không tìm thấy dự án: ${projectId}`)
|
||||
}
|
||||
|
||||
const nextShortcut = String(project.classes.length + 1)
|
||||
const newLabel: LabelClass = {
|
||||
id: `cls-${Date.now()}`,
|
||||
name: input.name.trim(),
|
||||
color: input.color || getColorForClass(project.classes.length),
|
||||
count: 0,
|
||||
shortcutKey: project.classes.length < 9 ? nextShortcut : undefined,
|
||||
}
|
||||
|
||||
project.classes.push(newLabel)
|
||||
saveMockDb(db)
|
||||
return newLabel
|
||||
}
|
||||
|
||||
export async function deleteLabel(projectId: string, labelId: string): Promise<void> {
|
||||
await delay(120)
|
||||
const db = getMockDb()
|
||||
const project = db.projects.find((p) => p.id === projectId || p.slug === projectId)
|
||||
if (!project) return
|
||||
project.classes = project.classes.filter((c) => c.id !== labelId)
|
||||
saveMockDb(db)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue