All checks were successful
Deploy Development / deploy (push) Successful in 44s
Test Suite / pytest-backend (push) Successful in 40s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Successful in 14s
Test Suite / k6 /health Baseline (push) Successful in 33s
Test Suite / playwright-tests (push) Successful in 1m20s
- Updated ExerciseAiQuickCreateOffer to set showSketchField to true by default and introduced sketchOptional prop for improved flexibility in exercise creation. - Refactored ExercisePickerModal and ExercisesListPageRoot to leverage useExerciseAiQuickCreateFields hook, simplifying state management for quick create fields. - Removed deprecated parsing logic and streamlined error handling for sketch input, enhancing user experience during exercise creation. - Improved placeholder text and labels for clarity, ensuring better guidance for users when providing input for AI-generated exercises.
63 lines
1.8 KiB
JavaScript
63 lines
1.8 KiB
JavaScript
import { useState, useEffect, useMemo, useRef, useCallback } from 'react'
|
|
import { parseSearchQueryForQuickCreate } from '../utils/exerciseAiQuickCreate'
|
|
|
|
/**
|
|
* Titel aus Suche vorbelegen; Kurzbeschreibung optional und manuell editierbar.
|
|
* Suchwechsel setzt „touched“ zurück und befüllt neu — solange der Nutzer nicht editiert hat.
|
|
*/
|
|
export function useExerciseAiQuickCreateFields(debouncedSearch, { enabled = true } = {}) {
|
|
const [title, setTitleState] = useState('')
|
|
const [sketch, setSketchState] = useState('')
|
|
const [focusAreaId, setFocusAreaId] = useState('')
|
|
const titleTouchedRef = useRef(false)
|
|
const sketchTouchedRef = useRef(false)
|
|
const lastSearchRef = useRef('')
|
|
|
|
const parsed = useMemo(() => parseSearchQueryForQuickCreate(debouncedSearch), [debouncedSearch])
|
|
|
|
useEffect(() => {
|
|
if (!enabled) return
|
|
if (debouncedSearch !== lastSearchRef.current) {
|
|
lastSearchRef.current = debouncedSearch
|
|
titleTouchedRef.current = false
|
|
sketchTouchedRef.current = false
|
|
}
|
|
if (!debouncedSearch) return
|
|
if (!titleTouchedRef.current) {
|
|
setTitleState(parsed.title)
|
|
}
|
|
if (!sketchTouchedRef.current) {
|
|
setSketchState('')
|
|
}
|
|
}, [enabled, debouncedSearch, parsed.title])
|
|
|
|
const setTitle = useCallback((v) => {
|
|
titleTouchedRef.current = true
|
|
setTitleState(v)
|
|
}, [])
|
|
|
|
const setSketch = useCallback((v) => {
|
|
sketchTouchedRef.current = true
|
|
setSketchState(v)
|
|
}, [])
|
|
|
|
const resetQuickCreateFields = useCallback(() => {
|
|
setTitleState('')
|
|
setSketchState('')
|
|
setFocusAreaId('')
|
|
titleTouchedRef.current = false
|
|
sketchTouchedRef.current = false
|
|
lastSearchRef.current = ''
|
|
}, [])
|
|
|
|
return {
|
|
title,
|
|
sketch,
|
|
focusAreaId,
|
|
setTitle,
|
|
setSketch,
|
|
setFocusAreaId,
|
|
resetQuickCreateFields,
|
|
}
|
|
}
|