feat: port TechLog Studio shell and indexes
This commit is contained in:
@@ -0,0 +1,226 @@
|
||||
import { useEffect, useState, type FormEvent } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
|
||||
import type { ListDocumentsQuery } from "../../../application/ports/studio-gateway.ts";
|
||||
import type { DocumentPage } from "../../../contracts/studio/contract.ts";
|
||||
import { useStudio } from "../use-studio.ts";
|
||||
|
||||
const kindLabel = {
|
||||
CASE: "Case",
|
||||
REFERENCE: "Reference",
|
||||
QUESTION: "Question",
|
||||
} as const;
|
||||
const publicationLabel = {
|
||||
NEVER_PUBLISHED: "게시 전",
|
||||
PUBLISHED: "게시 중",
|
||||
UNPUBLISHED: "게시 취소",
|
||||
} as const;
|
||||
const nextLabel = {
|
||||
CONTINUE_EDITING: "작성 계속",
|
||||
VALIDATE: "검증하기",
|
||||
FIX_VALIDATION: "오류 수정",
|
||||
CREATE_PREVIEW: "미리보기",
|
||||
PUBLISH: "게시하기",
|
||||
NONE: "완료",
|
||||
} as const;
|
||||
|
||||
function isAbortError(error: unknown): boolean {
|
||||
return error instanceof DOMException && error.name === "AbortError";
|
||||
}
|
||||
|
||||
export function DocumentList() {
|
||||
const { gateway } = useStudio();
|
||||
const [searchDraft, setSearchDraft] = useState("");
|
||||
const [q, setQ] = useState("");
|
||||
const [kind, setKind] = useState<ListDocumentsQuery["kind"]>();
|
||||
const [status, setStatus] =
|
||||
useState<ListDocumentsQuery["publicationStatus"]>();
|
||||
const [cursor, setCursor] = useState<string>();
|
||||
const [page, setPage] = useState<DocumentPage | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState("");
|
||||
const [retryGeneration, setRetryGeneration] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
const controller = new AbortController();
|
||||
setLoading(true);
|
||||
setError("");
|
||||
void gateway
|
||||
.listDocuments(
|
||||
{
|
||||
...(q ? { q } : {}),
|
||||
...(kind ? { kind } : {}),
|
||||
...(status ? { publicationStatus: status } : {}),
|
||||
...(cursor ? { cursor } : {}),
|
||||
limit: 20,
|
||||
},
|
||||
{ signal: controller.signal },
|
||||
)
|
||||
.then(
|
||||
(value) => {
|
||||
setPage(value);
|
||||
setLoading(false);
|
||||
},
|
||||
(reason: unknown) => {
|
||||
if (isAbortError(reason)) return;
|
||||
setError("작업본을 불러오지 못했습니다.");
|
||||
setLoading(false);
|
||||
},
|
||||
);
|
||||
return () => controller.abort();
|
||||
}, [cursor, gateway, kind, q, retryGeneration, status]);
|
||||
|
||||
const changeFilter = (next: {
|
||||
kind?: ListDocumentsQuery["kind"];
|
||||
status?: ListDocumentsQuery["publicationStatus"];
|
||||
}) => {
|
||||
if ("kind" in next) setKind(next.kind);
|
||||
if ("status" in next) setStatus(next.status);
|
||||
setCursor(undefined);
|
||||
};
|
||||
const submitSearch = (event: FormEvent) => {
|
||||
event.preventDefault();
|
||||
setQ(searchDraft.trim());
|
||||
setCursor(undefined);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="studio-page studio-documents-page">
|
||||
<header className="studio-page-top">
|
||||
<div className="studio-page-heading">
|
||||
<p className="studio-eyebrow">WORKING COPIES</p>
|
||||
<h1>작업본</h1>
|
||||
<p>
|
||||
세션에 있는 Case, Reference, Question을 찾고 다음 작업으로 이동합니다.
|
||||
</p>
|
||||
</div>
|
||||
<Link className="studio-primary-action" to="/studio/documents/new">
|
||||
새 문서
|
||||
</Link>
|
||||
</header>
|
||||
<section className="studio-document-tools" aria-label="작업본 검색과 필터">
|
||||
<form role="search" onSubmit={submitSearch}>
|
||||
<label htmlFor="studio-search">검색</label>
|
||||
<div>
|
||||
<input
|
||||
id="studio-search"
|
||||
type="search"
|
||||
value={searchDraft}
|
||||
placeholder="제목, 요약, slug"
|
||||
onChange={(event) => setSearchDraft(event.target.value)}
|
||||
/>
|
||||
<button type="submit">검색</button>
|
||||
</div>
|
||||
</form>
|
||||
<label>
|
||||
종류
|
||||
<select
|
||||
value={kind ?? ""}
|
||||
onChange={(event) =>
|
||||
changeFilter({
|
||||
kind: (event.target.value || undefined) as ListDocumentsQuery["kind"],
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="">전체</option>
|
||||
<option value="CASE">Case</option>
|
||||
<option value="REFERENCE">Reference</option>
|
||||
<option value="QUESTION">Question</option>
|
||||
</select>
|
||||
</label>
|
||||
<label>
|
||||
상태
|
||||
<select
|
||||
value={status ?? ""}
|
||||
onChange={(event) =>
|
||||
changeFilter({
|
||||
status: (event.target.value || undefined) as ListDocumentsQuery["publicationStatus"],
|
||||
})
|
||||
}
|
||||
>
|
||||
<option value="">전체</option>
|
||||
<option value="NEVER_PUBLISHED">게시 전</option>
|
||||
<option value="PUBLISHED">게시 중</option>
|
||||
<option value="UNPUBLISHED">게시 취소</option>
|
||||
</select>
|
||||
</label>
|
||||
</section>
|
||||
{loading ? (
|
||||
<p className="studio-loading" role="status">
|
||||
작업본을 불러오는 중입니다.
|
||||
</p>
|
||||
) : null}
|
||||
{error ? (
|
||||
<>
|
||||
<p className="studio-screen-error" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
<button
|
||||
className="studio-secondary-button"
|
||||
type="button"
|
||||
onClick={() => setRetryGeneration((current) => current + 1)}
|
||||
>
|
||||
다시 시도
|
||||
</button>
|
||||
</>
|
||||
) : null}
|
||||
{page && !loading && !error ? (
|
||||
<>
|
||||
<p className="studio-result-count">{page.items.length}개의 작업본</p>
|
||||
{page.items.length ? (
|
||||
<div className="studio-document-list">
|
||||
{page.items.map((item) => (
|
||||
<article className="studio-document-row" key={item.id}>
|
||||
<p className="studio-row-label">{kindLabel[item.kind]}</p>
|
||||
<div className="studio-document-title">
|
||||
<h2>
|
||||
<Link to={`/studio/documents/${item.id}/edit`}>
|
||||
{item.title || "제목 없는 작업본"}
|
||||
</Link>
|
||||
</h2>
|
||||
<p>{item.project?.label ?? "프로젝트 미지정"}</p>
|
||||
</div>
|
||||
<dl>
|
||||
<div>
|
||||
<dt>상태</dt>
|
||||
<dd>{publicationLabel[item.publicationStatus]}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>다음</dt>
|
||||
<dd>{nextLabel[item.nextAction]}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>수정</dt>
|
||||
<dd>
|
||||
<time dateTime={item.updatedAt}>
|
||||
{new Date(item.updatedAt).toLocaleDateString("ko-KR", {
|
||||
timeZone: "Asia/Seoul",
|
||||
})}
|
||||
</time>
|
||||
</dd>
|
||||
</div>
|
||||
</dl>
|
||||
</article>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<section className="studio-empty-state">
|
||||
<h2>조건에 맞는 작업본이 없습니다</h2>
|
||||
<p>검색어 또는 필터를 바꾸거나 새 문서를 만드세요.</p>
|
||||
<Link to="/studio/documents/new">새 문서 만들기</Link>
|
||||
</section>
|
||||
)}
|
||||
{page.nextCursor ? (
|
||||
<button
|
||||
className="studio-secondary-button"
|
||||
type="button"
|
||||
onClick={() => setCursor(page.nextCursor ?? undefined)}
|
||||
>
|
||||
다음 작업본
|
||||
</button>
|
||||
) : null}
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user