Spaces:
Sleeping
Sleeping
| import { useState, useCallback } from "react"; | |
| import { createEmptyAnnotations } from "./promptSchema"; | |
| // Shared annotation-state logic for the Training and Evaluation pages: an | |
| // empty {events, video} structure derived from an item's applicable axes, | |
| // plus update helpers. `resetFor(item)` re-initializes when the current | |
| // item/video changes (e.g. moving to the next task). | |
| export default function useAnnotations(initialItem) { | |
| const [annotations, setAnnotations] = useState(() => createEmptyAnnotations(initialItem)); | |
| const updateEventField = useCallback((eventId, axisId, field, value) => { | |
| setAnnotations((prev) => ({ | |
| ...prev, | |
| events: { | |
| ...prev.events, | |
| [eventId]: { | |
| ...prev.events[eventId], | |
| [axisId]: { ...prev.events[eventId][axisId], [field]: value } | |
| } | |
| } | |
| })); | |
| }, []); | |
| const updateVideoField = useCallback((axisId, field, value) => { | |
| setAnnotations((prev) => ({ | |
| ...prev, | |
| video: { | |
| ...prev.video, | |
| [axisId]: { ...prev.video[axisId], [field]: value } | |
| } | |
| })); | |
| }, []); | |
| const resetFor = useCallback((item) => { | |
| setAnnotations(createEmptyAnnotations(item)); | |
| }, []); | |
| return { annotations, updateEventField, updateVideoField, resetFor, setAnnotations }; | |
| } | |