From 7c808a6f761242b31f2cb0d7996f821bc64dc112 Mon Sep 17 00:00:00 2001 From: miteruzo Date: Sat, 18 Jul 2026 15:15:10 +0900 Subject: [PATCH] #399 --- .../src/pages/posts/PostImportReviewPage.tsx | 63 +++++++++++++++---- 1 file changed, 52 insertions(+), 11 deletions(-) diff --git a/frontend/src/pages/posts/PostImportReviewPage.tsx b/frontend/src/pages/posts/PostImportReviewPage.tsx index 50042c5..299f64a 100644 --- a/frontend/src/pages/posts/PostImportReviewPage.tsx +++ b/frontend/src/pages/posts/PostImportReviewPage.tsx @@ -145,6 +145,16 @@ const shouldFetchMetadata = (row: PostImportRow): boolean => && !(isNonRecoverableFailedRow (row)) && row.metadataUrl == null +const shouldHydrateExistingPost = (row: PostImportRow): boolean => + row.skipReason === 'existing' + && row.existingPostId != null + && row.existingPost == null + && row.importStatus !== 'created' + && row.importStatus !== 'skipped' + +const shouldFetchReviewRow = (row: PostImportRow): boolean => + shouldFetchMetadata (row) || shouldHydrateExistingPost (row) + const applyDuplicateUrlErrors = ( rows: PostImportRow[], ): PostImportRow[] => { @@ -356,7 +366,7 @@ const indexedBulkResults = ( sourceRow: row.sourceRow, status: 'skipped', existingPostId, - existingPost: result.existingPost, + existingPost: result.existingPost ?? row.existingPost, fieldWarnings: result.fieldWarnings, baseWarnings: result.baseWarnings, errors } @@ -454,6 +464,21 @@ const mergePreviewRow = ( } +const mergeExistingSkippedRow = ( + currentRow: PostImportRow, + preview: PostMetadataResponse, +): PostImportRow => + preview.existingPostId != null || preview.existingPost?.id != null + ? { + ...currentRow, + url: preview.url, + existingPostId: preview.existingPostId ?? preview.existingPost?.id, + existingPost: preview.existingPost ?? currentRow.existingPost, + skipReason: 'existing', + metadataUrl: preview.url } + : currentRow + + const buildBulkFormData = (rows: PostImportRow[]): FormData => { const formData = new FormData () formData.append ( @@ -478,14 +503,25 @@ const buildBulkFormData = (rows: PostImportRow[]): FormData => { const ExistingSkippedRows: FC = ({ id, rows }) => { - const posts = rows - .map (row => row.existingPost) - .filter ((post): post is NonNullable => post != null) - return (
- {posts.map (post => { + {rows.map (row => { + const post = row.existingPost + if (post == null) + { + return ( +
+ +
+
+ {row.url} +
+
+
) + } return ( = ({ user }) => { if (sessionRef.current != null && persistedSearchRef.current === location.search - && !(sessionRef.current.rows.some (row => shouldFetchMetadata (row)))) + && !(sessionRef.current.rows.some (row => shouldFetchReviewRow (row)))) return () => { previewSequenceRef.current = previewSequence } const refreshRows = async (baseSession: PostImportSession) => { - if (active) + const blocksSubmit = baseSession.rows.some (row => shouldFetchMetadata (row)) + if (active && blocksSubmit) setMetadataLoading (true) try { @@ -652,7 +689,7 @@ const PostImportReviewPage: FC = ({ user }) => { const baseRow = baseSession.rows[index] const currentRow = currentRowBySource (baseRow.sourceRow, baseSession) - if (currentRow == null || !(shouldFetchMetadata (currentRow))) + if (currentRow == null || !(shouldFetchReviewRow (currentRow))) continue const controller = new AbortController () controllers.add (controller) @@ -669,7 +706,9 @@ const PostImportReviewPage: FC = ({ user }) => { || isNonRecoverableFailedRow (row) || row.skipReason === 'manual' ? row - : mergePreviewRow (row, preview)) + : (shouldFetchMetadata (row) + ? mergePreviewRow (row, preview) + : mergeExistingSkippedRow (row, preview))) } catch (requestError) { @@ -723,7 +762,9 @@ const PostImportReviewPage: FC = ({ user }) => { } finally { - if (active && metadataSequenceRef.current === previewSequence) + if (active + && blocksSubmit + && metadataSequenceRef.current === previewSequence) setMetadataLoading (false) } }