52 lines
1.7 KiB
TypeScript
52 lines
1.7 KiB
TypeScript
import { useState } from 'react'
|
|
import DeleteDialog, {
|
|
type DeleteTarget,
|
|
} from '@/components/editor/DeleteDialog'
|
|
import ReferenceForm from '@/components/editor/references/ReferenceForm'
|
|
import ReferenceRow from '@/components/editor/references/ReferenceRow'
|
|
import { useRowFocus } from '@/editor/focusRequest'
|
|
import { useSheetDocument } from '@/editor/sheetDocument'
|
|
import type { EditorTabProps } from '@/editor/tabs'
|
|
import { useT } from '@/i18n/useT'
|
|
|
|
/** Références: the sheet's bibliography, cited by id from the findings. */
|
|
export default function ReferencesTab({ readOnly, focus }: EditorTabProps) {
|
|
const t = useT()
|
|
useRowFocus(focus)
|
|
const doc = useSheetDocument()
|
|
const [deleting, setDeleting] = useState<DeleteTarget | null>(null)
|
|
const references = doc?.references ?? []
|
|
return (
|
|
<section
|
|
data-testid="editor-tab-references"
|
|
aria-label={t('editor.tab.references')}
|
|
className="min-h-24 space-y-3"
|
|
>
|
|
{doc && references.length === 0 && (
|
|
<p className="text-sm text-[var(--color-ink-muted)]">
|
|
{t('editor.reference.empty')}
|
|
</p>
|
|
)}
|
|
<ul className="space-y-3">
|
|
{references.map((reference, index) => (
|
|
<ReferenceRow
|
|
key={reference.id}
|
|
reference={reference}
|
|
index={index}
|
|
count={references.length}
|
|
readOnly={readOnly}
|
|
onDelete={() =>
|
|
setDeleting({
|
|
key: { kind: 'reference', id: reference.id },
|
|
label: reference.citation,
|
|
})
|
|
}
|
|
/>
|
|
))}
|
|
</ul>
|
|
{doc && !readOnly && <ReferenceForm />}
|
|
<DeleteDialog target={deleting} onClose={() => setDeleting(null)} />
|
|
</section>
|
|
)
|
|
}
|