このコミットが含まれているのは:
@@ -18,6 +18,9 @@ export type PostImportBadgeValue =
|
||||
export const effectivePostImportStatus = (
|
||||
row: PostImportRow,
|
||||
): PostImportEffectiveStatus => {
|
||||
if (Object.keys (row.validationErrors ?? { }).length > 0)
|
||||
return 'error'
|
||||
|
||||
switch (row.importStatus)
|
||||
{
|
||||
case 'created':
|
||||
|
||||
@@ -218,6 +218,10 @@ const sanitiseRow = (value: unknown): PostImportRow | null => {
|
||||
return null
|
||||
if (value.skipReason !== 'existing' && value.existingPostId != null)
|
||||
return null
|
||||
if (value.importStatus === 'created' && !(isPositiveInteger (value.createdPostId)))
|
||||
return null
|
||||
if (value.importStatus !== 'created' && value.createdPostId != null)
|
||||
return null
|
||||
if (value.createdPostId != null && !(isPositiveInteger (value.createdPostId)))
|
||||
return null
|
||||
|
||||
@@ -618,14 +622,12 @@ const hasValidationErrors = (row: PostImportRow): boolean =>
|
||||
Object.keys (row.validationErrors ?? { }).length > 0
|
||||
|
||||
|
||||
export const submittableImportRows = (rows: PostImportRow[]): PostImportRow[] =>
|
||||
export const processableImportRows = (rows: PostImportRow[]): PostImportRow[] =>
|
||||
rows.filter (row => {
|
||||
if (row.importStatus === 'created')
|
||||
return false
|
||||
if (row.importStatus === 'skipped')
|
||||
return false
|
||||
if (hasSkipReason (row) && !(hasValidationErrors (row)))
|
||||
return false
|
||||
if (row.importStatus === 'failed')
|
||||
return false
|
||||
if (hasValidationErrors (row))
|
||||
@@ -633,11 +635,14 @@ export const submittableImportRows = (rows: PostImportRow[]): PostImportRow[] =>
|
||||
return row.importStatus == null || row.importStatus === 'pending'
|
||||
})
|
||||
|
||||
export const creatableImportRows = (rows: PostImportRow[]): PostImportRow[] =>
|
||||
processableImportRows (rows).filter (row => !(hasSkipReason (row)))
|
||||
|
||||
|
||||
export const reviewSummaryCounts = (rows: PostImportRow[]) => ({
|
||||
total: rows.length,
|
||||
submittable: rows.filter (row =>
|
||||
submittableImportRows ([row]).length > 0
|
||||
creatableImportRows ([row]).length > 0
|
||||
&& !(hasValidationErrors (row))).length,
|
||||
invalid: rows.filter (row => hasValidationErrors (row)).length,
|
||||
skipPlanned: rows.filter (row =>
|
||||
|
||||
@@ -8,6 +8,7 @@ import PageTitle from '@/components/common/PageTitle'
|
||||
import PrefetchLink from '@/components/PrefetchLink'
|
||||
import MainArea from '@/components/layout/MainArea'
|
||||
import PostImportStatusBadge from '@/components/posts/import/PostImportStatusBadge'
|
||||
import { effectivePostImportStatus } from '@/components/posts/import/postImportRowStatus'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { toast } from '@/components/ui/use-toast'
|
||||
import { SITE_TITLE } from '@/config'
|
||||
@@ -30,7 +31,9 @@ import type { User } from '@/types'
|
||||
|
||||
type Props = { user: User | null }
|
||||
|
||||
const resultToneClass = (status: string | undefined): string[] => {
|
||||
const resultToneClass = (
|
||||
status: ReturnType<typeof effectivePostImportStatus>,
|
||||
): string[] => {
|
||||
switch (status)
|
||||
{
|
||||
case 'created':
|
||||
@@ -42,9 +45,14 @@ const resultToneClass = (status: string | undefined): string[] => {
|
||||
'border-stone-200 bg-stone-50',
|
||||
'dark:border-stone-800 dark:bg-stone-900/60']
|
||||
case 'failed':
|
||||
case 'error':
|
||||
return [
|
||||
'border-rose-200 bg-rose-50',
|
||||
'dark:border-rose-900 dark:bg-rose-950/30']
|
||||
case 'warning':
|
||||
return [
|
||||
'border-amber-200 bg-amber-50',
|
||||
'dark:border-amber-900 dark:bg-amber-950/30']
|
||||
default:
|
||||
return [
|
||||
'border-border bg-white',
|
||||
@@ -52,6 +60,10 @@ const resultToneClass = (status: string | undefined): string[] => {
|
||||
}
|
||||
}
|
||||
|
||||
const rowMessages = (row: PostImportRow): string[] => [
|
||||
...Object.values (row.validationErrors ?? { }).flat (),
|
||||
...Object.values (row.importErrors ?? { }).flat ()]
|
||||
|
||||
|
||||
const PostImportResultPage: FC<Props> = ({ user }) => {
|
||||
const editable = canEditContent (user)
|
||||
@@ -63,7 +75,7 @@ const PostImportResultPage: FC<Props> = ({ user }) => {
|
||||
const [loadingRow, setLoadingRow] = useState<number | null> (null)
|
||||
|
||||
useEffect (() => {
|
||||
if (!(sessionId))
|
||||
if (sessionId == null)
|
||||
return
|
||||
|
||||
const loaded = loadPostImportSession (sessionId, message =>
|
||||
@@ -73,7 +85,7 @@ const PostImportResultPage: FC<Props> = ({ user }) => {
|
||||
}, [sessionId])
|
||||
|
||||
useEffect (() => {
|
||||
if (!(sessionId) || !(session))
|
||||
if (sessionId == null || session == null)
|
||||
return
|
||||
|
||||
savePostImportSession (sessionId, session, message =>
|
||||
@@ -83,10 +95,13 @@ const PostImportResultPage: FC<Props> = ({ user }) => {
|
||||
const counts = useMemo (() => ({
|
||||
created: session?.rows.filter (_1 => _1.importStatus === 'created').length ?? 0,
|
||||
skipped: session?.rows.filter (_1 => _1.importStatus === 'skipped').length ?? 0,
|
||||
failed: session?.rows.filter (_1 => _1.importStatus === 'failed').length ?? 0 }), [session])
|
||||
failed: session?.rows.filter (_1 => _1.importStatus === 'failed').length ?? 0,
|
||||
invalid:
|
||||
session?.rows.filter (_1 => effectivePostImportStatus (_1) === 'error').length ?? 0,
|
||||
}), [session])
|
||||
|
||||
const retry = async (sourceRow: number) => {
|
||||
if (!(session))
|
||||
if (session == null)
|
||||
return
|
||||
|
||||
setLoadingRow (sourceRow)
|
||||
@@ -164,7 +179,7 @@ const PostImportResultPage: FC<Props> = ({ user }) => {
|
||||
if (!(editable))
|
||||
return <Forbidden/>
|
||||
|
||||
if (missing || !(sessionId) || !(session))
|
||||
if (missing || sessionId == null || session == null)
|
||||
{
|
||||
return (
|
||||
<MainArea>
|
||||
@@ -193,22 +208,25 @@ const PostImportResultPage: FC<Props> = ({ user }) => {
|
||||
<SummaryChip label="登録成功" value={counts.created} badge="created"/>
|
||||
<SummaryChip label="スキップ" value={counts.skipped} badge="skipped"/>
|
||||
<SummaryChip label="失敗" value={counts.failed} badge="failed"/>
|
||||
<SummaryChip label="要修正" value={counts.invalid} badge="error"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="space-y-3">
|
||||
{session.rows.map (row => (
|
||||
{session.rows.map (row => {
|
||||
const status = effectivePostImportStatus (row)
|
||||
return (
|
||||
<div
|
||||
key={row.sourceRow}
|
||||
className={[
|
||||
'rounded-lg border p-4',
|
||||
...resultToneClass (row.importStatus)].join (' ')}>
|
||||
...resultToneClass (status)].join (' ')}>
|
||||
<div className="flex flex-col gap-3 md:flex-row md:items-start
|
||||
md:justify-between">
|
||||
<div className="space-y-2">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span className="text-sm font-medium">行 {row.sourceRow}</span>
|
||||
<PostImportStatusBadge value={row.importStatus ?? 'pending'}/>
|
||||
<PostImportStatusBadge value={status}/>
|
||||
</div>
|
||||
<div className="text-sm text-neutral-700 dark:text-neutral-200">
|
||||
{String (row.attributes.title ?? '') || row.url}
|
||||
@@ -216,7 +234,7 @@ const PostImportResultPage: FC<Props> = ({ user }) => {
|
||||
<div className="text-xs text-neutral-500 dark:text-neutral-400">
|
||||
{row.url}
|
||||
</div>
|
||||
<FieldError messages={Object.values (row.importErrors ?? { }).flat ()}/>
|
||||
<FieldError messages={rowMessages (row)}/>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-2 sm:flex-row">
|
||||
@@ -226,14 +244,15 @@ const PostImportResultPage: FC<Props> = ({ user }) => {
|
||||
投稿を開く
|
||||
</PrefetchLink>
|
||||
</Button>)}
|
||||
{status === 'error' && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => openRepair (row.sourceRow)}>
|
||||
編輯
|
||||
</Button>)}
|
||||
{row.importStatus === 'failed' && (
|
||||
<>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => openRepair (row.sourceRow)}>
|
||||
編輯
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
onClick={() => retry (row.sourceRow)}
|
||||
@@ -243,7 +262,7 @@ const PostImportResultPage: FC<Props> = ({ user }) => {
|
||||
</>)}
|
||||
</div>
|
||||
</div>
|
||||
</div>))}
|
||||
</div>)})}
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-2 sm:flex-row">
|
||||
@@ -280,7 +299,7 @@ const SummaryChip = (
|
||||
{ label, value, badge }: {
|
||||
label: string
|
||||
value: number
|
||||
badge: 'created' | 'skipped' | 'failed' },
|
||||
badge: 'created' | 'skipped' | 'failed' | 'error' },
|
||||
) => (
|
||||
<div className="flex items-center gap-2 rounded-full border border-border
|
||||
bg-background px-3 py-1 text-sm">
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -24,7 +24,8 @@ import type { User } from '@/types'
|
||||
|
||||
type Props = { user: User | null }
|
||||
|
||||
type PostFormField = 'url'
|
||||
type PostFormField =
|
||||
'url'
|
||||
| 'title'
|
||||
| 'tags'
|
||||
| 'parentPostIds'
|
||||
@@ -54,9 +55,11 @@ const PostNewPage: FC<Props> = ({ user }) => {
|
||||
const [url, setURL] = useState ('')
|
||||
|
||||
const thumbnailPreviewRef = useRef ('')
|
||||
const videoFlg = useMemo (() =>
|
||||
tags.split (/\s+/).some (
|
||||
tag => tag.replace (/\[.*\]$/, '') === '動画'), [tags])
|
||||
const videoFlg =
|
||||
useMemo (() =>
|
||||
tags.split (/\s+/).some (
|
||||
tag => tag.replace (/\[.*\]$/, '') === '動画'),
|
||||
[tags])
|
||||
|
||||
const handleSubmit = async () => {
|
||||
clearValidationErrors ()
|
||||
@@ -109,11 +112,13 @@ const PostNewPage: FC<Props> = ({ user }) => {
|
||||
URL.revokeObjectURL (thumbnailPreviewRef.current)
|
||||
try
|
||||
{
|
||||
const data = await apiGet<Blob> ('/preview/thumbnail', { params: { url },
|
||||
responseType: 'blob' })
|
||||
const data = await apiGet<Blob> ('/preview/thumbnail',
|
||||
{ params: { url },
|
||||
responseType: 'blob' })
|
||||
const imageURL = URL.createObjectURL (data)
|
||||
setThumbnailPreview (imageURL)
|
||||
setThumbnailFile (new File ([data], 'thumbnail.png',
|
||||
setThumbnailFile (new File ([data],
|
||||
'thumbnail.png',
|
||||
{ type: data.type || 'image/png' }))
|
||||
}
|
||||
finally
|
||||
|
||||
新しい課題から参照
ユーザをブロックする