Files
faunosteo/apps/app/src/components/editor/tabs/ViewsTab.tsx
T

70 lines
2.4 KiB
TypeScript

import { useState } from 'react'
import DeleteDialog, {
type DeleteTarget,
} from '@/components/editor/DeleteDialog'
import DetailViewForm from '@/components/editor/views/DetailViewForm'
import DetailViewRow from '@/components/editor/views/DetailViewRow'
import MainViewCard from '@/components/editor/views/MainViewCard'
import { useRowFocus } from '@/editor/focusRequest'
import { useSheetDocument } from '@/editor/sheetDocument'
import type { EditorTabProps } from '@/editor/tabs'
import { useT } from '@/i18n/useT'
import { useLocaleStore } from '@/state/localeStore'
/**
* Vues et illustrations: the main view and its drawing, the detail views (parent, own
* drawing or crop), the upload of a drawing and the frame changes it brings.
*/
export default function ViewsTab({ readOnly, focus }: EditorTabProps) {
const t = useT()
useRowFocus(focus)
const locale = useLocaleStore((s) => s.locale)
const doc = useSheetDocument()
const [deleting, setDeleting] = useState<DeleteTarget | null>(null)
const [cropOpen, setCropOpen] = useState<string | null>(null)
const views = doc?.views ?? []
const main = views.find((view) => view.kind === 'main')
const details = views.filter((view) => view.kind === 'detail')
return (
<section
data-testid="editor-tab-views"
aria-label={t('editor.tab.views')}
className="min-h-24 space-y-4"
>
{main?.kind === 'main' && (
<MainViewCard view={main} readOnly={readOnly} />
)}
<h3 className="text-base font-semibold">
{t('editor.views.details_title')}
</h3>
{doc && details.length === 0 && (
<p className="text-sm text-[var(--color-ink-muted)]">
{t('editor.views.empty')}
</p>
)}
<ul className="space-y-3">
{details.map((view) => (
<DetailViewRow
key={view.id}
view={view}
views={views}
readOnly={readOnly}
cropOpen={cropOpen === view.id}
onToggleCrop={() =>
setCropOpen(cropOpen === view.id ? null : view.id)
}
onDelete={() =>
setDeleting({
key: { kind: 'view', id: view.id },
label: view.name[locale],
})
}
/>
))}
</ul>
{doc && !readOnly && <DetailViewForm views={views} />}
<DeleteDialog target={deleting} onClose={() => setDeleting(null)} />
</section>
)
}