FEAT-5: Probeverpaarung entry point from animal detail (?parent=) + stored-vs-engine Farbschlag mismatch hint

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-06 00:09:22 +02:00
parent 5ee4b9874b
commit d8e94f6d05
4 changed files with 72 additions and 1 deletions

View File

@@ -1,6 +1,9 @@
import { useMemo, useState } from 'react'
import { useSearchParams } from 'react-router-dom'
import { de } from '../strings/de'
import { breed, fromDisplayString, type BreedingResult } from '../genetics'
import { getGerbil } from '../api/gerbils'
import { useApi } from '../hooks/useApi'
import ParentSelector, { type ParentValue } from '../components/ParentSelector'
import AnimalPicker from '../components/AnimalPicker'
import { isValidGenotype } from '../format/genotypeText'
@@ -18,6 +21,22 @@ export default function GenetikPage() {
const [mother, setMother] = useState<ParentValue>(EMPTY_PARENT)
const [showGenotypes, setShowGenotypes] = useState(false)
// Pre-fill a parent when arriving from an animal's detail page (?parent=<id>).
// Gender decides the side: female -> Mutter, otherwise Vater.
const [searchParams] = useSearchParams()
const parentId = searchParams.get('parent')
const prefill = useApi(
() => (parentId ? getGerbil(parentId) : Promise.resolve(null)),
[parentId],
)
const [prefilledFor, setPrefilledFor] = useState<string | null>(null)
if (prefill.data && prefilledFor !== prefill.data.id) {
setPrefilledFor(prefill.data.id)
const value: ParentValue = { genotype: prefill.data.genotype ?? '', animalName: prefill.data.name }
if (prefill.data.gender === 'female') setMother(value)
else setFather(value)
}
const bothValid = isValidGenotype(father.genotype) && isValidGenotype(mother.genotype)
const result: BreedingResult | null = useMemo(() => {