このコミットが含まれているのは:
2026-07-14 19:37:04 +09:00
コミット f9463f383f
11個のファイルの変更202行の追加92行の削除
+25 -19
ファイルの表示
@@ -15,11 +15,12 @@ import { SITE_TITLE } from '@/config'
import { apiPost } from '@/lib/api'
import { canEditContent } from '@/lib/users'
import { loadPostImportSession,
creatableImportRows,
mergeImportResults,
mergeValidatedImportRows,
processableImportRows,
reviewSummaryCounts,
savePostImportSession,
submittableImportRows,
type PostImportResultRow,
type PostImportRow,
type PostImportSession } from '@/lib/postImportSession'
@@ -54,7 +55,7 @@ const PostImportReviewPage: FC<Props> = ({ user }) => {
const [savingRow, setSavingRow] = useState<number | null> (null)
useEffect (() => {
if (!(sessionId))
if (sessionId == null)
return
const loaded = loadPostImportSession (sessionId, message =>
@@ -64,7 +65,7 @@ const PostImportReviewPage: FC<Props> = ({ user }) => {
}, [sessionId])
useEffect (() => {
if (!(sessionId) || !(session))
if (sessionId == null || session == null)
return
savePostImportSession (sessionId, session, message =>
@@ -78,9 +79,12 @@ const PostImportReviewPage: FC<Props> = ({ user }) => {
? rows.find (_1 => _1.sourceRow === editingSourceRow) ?? null
: null
const counts = useMemo (() => reviewSummaryCounts (rows), [rows])
const submittable = useMemo (
() => submittableImportRows (rows).filter (row =>
Object.keys (row.validationErrors ?? { }).length === 0),
const processable = useMemo (
() => processableImportRows (rows),
[rows],
)
const creatable = useMemo (
() => creatableImportRows (rows),
[rows],
)
const reviewRows =
@@ -105,7 +109,7 @@ const PostImportReviewPage: FC<Props> = ({ user }) => {
current ? { ...current, rows: nextRows } : current)
const saveDraft = async (draft: Draft): Promise<boolean> => {
if (!(session))
if (session == null)
return false
if (editingRow == null)
return false
@@ -186,7 +190,7 @@ const PostImportReviewPage: FC<Props> = ({ user }) => {
}
const submit = async () => {
if (!(sessionId) || !(session) || submittable.length === 0)
if (sessionId == null || session == null || processable.length === 0)
return
setLoading (true)
@@ -197,7 +201,7 @@ const PostImportReviewPage: FC<Props> = ({ user }) => {
skipped: number
failed: number
rows: PostImportResultRow[] }> ('/posts/import', {
rows: submittable.map (row => ({
rows: processable.map (row => ({
sourceRow: row.sourceRow,
url: row.url,
attributes: row.attributes,
@@ -226,7 +230,7 @@ const PostImportReviewPage: FC<Props> = ({ user }) => {
if (!(editable))
return <Forbidden/>
if (missing || !(sessionId) || !(session))
if (missing || sessionId == null || session == null)
{
return (
<MainArea>
@@ -278,7 +282,8 @@ const PostImportReviewPage: FC<Props> = ({ user }) => {
<PostImportFooter
loading={loading}
invalidCount={counts.invalid}
submittableCount={submittable.length}
processableCount={processable.length}
creatableCount={creatable.length}
onBack={() => navigate ('/posts/import')}
onSubmit={submit}/>
@@ -295,12 +300,13 @@ const PostImportReviewPage: FC<Props> = ({ user }) => {
}
const PostImportFooter = (
{ loading, invalidCount, submittableCount, onBack, onSubmit }: {
loading: boolean
invalidCount: number
submittableCount: number
onBack: () => void
onSubmit: () => void },
{ loading, invalidCount, processableCount, creatableCount, onBack, onSubmit }: {
loading: boolean
invalidCount: number
processableCount: number
creatableCount: number
onBack: () => void
onSubmit: () => void },
) => (
<div
className="shrink-0 border-t bg-white/95 p-4 backdrop-blur
@@ -309,7 +315,7 @@ const PostImportFooter = (
md:items-center md:justify-between">
<div className="flex flex-wrap items-center gap-2 text-sm">
<PostImportStatusBadge value="pending"/>
<span> {submittableCount} </span>
<span> {creatableCount} </span>
<PostImportStatusBadge value="error"/>
<span> {invalidCount} </span>
</div>
@@ -320,7 +326,7 @@ const PostImportFooter = (
<Button
type="button"
onClick={onSubmit}
disabled={loading || submittableCount === 0}>
disabled={loading || processableCount === 0}>
稿
</Button>
</div>