import FieldError from '@/components/common/FieldError' import PostImportStatusBadge from '@/components/posts/import/PostImportStatusBadge' import ThumbnailPreview from '@/components/posts/import/ThumbnailPreview' import { Button } from '@/components/ui/button' import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog' import { inputClass } from '@/lib/utils' import type { FC } from 'react' import { useEffect, useState } from 'react' import type { PostImportOrigin, PostImportRow } from '@/lib/postImportSession' type Draft = { url: string title: string thumbnailBase: string originalCreatedFrom: string originalCreatedBefore: string duration: string tags: string parentPostIds: string } type Props = { open: boolean row: PostImportRow | null saving: boolean onOpenChange: (open: boolean) => void onSave: (draft: Draft) => Promise } const originOf = ( row: PostImportRow, field: string, ): PostImportOrigin => row.provenance[field] ?? 'automatic' const buildDraft = (row: PostImportRow): Draft => ({ url: row.url, title: String (row.attributes.title ?? ''), thumbnailBase: String (row.attributes.thumbnailBase ?? ''), originalCreatedFrom: String (row.attributes.originalCreatedFrom ?? ''), originalCreatedBefore: String (row.attributes.originalCreatedBefore ?? ''), duration: String (row.attributes.duration ?? ''), tags: String (row.attributes.tags ?? ''), parentPostIds: String (row.attributes.parentPostIds ?? '') }) const PostImportRowDialog: FC = ( { open, row, saving, onOpenChange, onSave }, ) => { const [draft, setDraft] = useState (null) useEffect (() => { if (open && row) setDraft (buildDraft (row)) }, [open, row]) if (!(row) || !(draft)) return null const update = ( key: Key, value: Draft[Key], ) => { setDraft (current => current ? { ...current, [key]: value } : current) } const save = async () => { if (await onSave (draft)) onOpenChange (false) } return ( 投稿 {row.sourceRow} を編集 自動取得結果を確認し、必要な項目だけ修正してください.
update ('url', value)}/> update ('title', value)}/> update ('thumbnailBase', value)}/>
update ('originalCreatedFrom', value)}/> update ('originalCreatedBefore', value)}/>
update ('duration', value)}/> update ('tags', value)}/> update ('parentPostIds', value)}/>
) } const DialogField = ( { label, value, origin, onChange }: { label: string value: string origin: PostImportOrigin onChange: (value: string) => void }, ) => ( ) const DialogArea = ( { label, value, origin, onChange }: { label: string value: string origin: PostImportOrigin onChange: (value: string) => void }, ) => (