Files
tech-log-frontend/src/features/tech-log/presentation/public/components/search-dialog.tsx
T
DongHyeonka 11c2713139 feat: let Studio create the topics and projects publishing requires
Publishing needs a topic and nothing could create one. The backend now owns
that surface; this is its consumer — the management contract vendored, a
gateway over its nine operations, and one Studio screen that lists, creates,
and deletes topics and projects.

The screen adds no CSS. It reuses the classes the working-copy list already
uses, so it inherits Studio's spacing, type, and colour rather than growing a
second visual vocabulary beside them. Scope stops at list/create/delete:
renaming, phase changes, and visibility are implemented in the backend and
declared in the contract, but their screens are a separate design.

Two real defects surfaced while making the public port async, and both would
have shipped:

The search page and the header search dialog shared a query key. With an empty
query, `["tech-log","search",""]` was identical for both, so react-query
handed one surface the other's cache — different shapes — and the page died
reading a field that was not there. Keys now name the surface.

The explore filter's selects are uncontrolled and read `defaultValue`, which
React applies once. Their options arrive later now, so the first render had
nothing to match and the value stayed empty: a topic in the URL no longer
showed as selected. The form key includes whether the catalog has arrived, so
it remounts with the options present. Controlled inputs would be the other
answer, but this form submits to build a URL — the URL owns the value.

The route brought its own bookkeeping: a build chunk, a manual accessibility
evidence file, and the CI artifact baseline that counts them. The gate pins a
digest of its own shape precisely so a new route cannot slip in without that
count being reviewed.

Test harnesses that render public screens now assemble the query providers and
await the settled paint, because the screens they render became async.
2026-08-20 23:40:15 +09:00

132 lines
4.3 KiB
TypeScript

import { useId, useRef, useState } from "react";
import { Link } from "react-router-dom";
import { usePublicContent } from "../use-public-content.tsx";
type SearchDialogProps = {
className?: string;
onBeforeOpen?: () => void;
};
export function SearchDialog({
className = "",
onBeforeOpen,
}: SearchDialogProps) {
const dialogId = useId();
const dialogRef = useRef<HTMLDialogElement>(null);
const inputRef = useRef<HTMLInputElement>(null);
const triggerRef = useRef<HTMLButtonElement>(null);
const [query, setQuery] = useState("");
const normalizedQuery = query.trim().toLocaleLowerCase("ko-KR");
// Keyed on the empty query, then filtered here, rather than one request per
// keystroke. This is a type-ahead: re-querying per character would replace the
// result list with a loading skeleton on every key, which is a worse dialog
// than a stale-free local filter. The predicate is the same one the catalog
// applies for a non-empty query, so the visible result set is unchanged.
const view = usePublicContent(["tech-log", "search", "dialog"], async (queries) => ({
entities: await queries.searchPublicContent(""),
}));
const results = (view.data?.entities ?? []).filter((entity) =>
normalizedQuery
? [entity.title, entity.summary, entity.topic, entity.project, ...(entity.topics ?? [])]
.filter((value): value is string => Boolean(value))
.some((value) => value.toLocaleLowerCase("ko-KR").includes(normalizedQuery))
: true,
);
function open() {
onBeforeOpen?.();
dialogRef.current?.showModal();
requestAnimationFrame(() => inputRef.current?.focus());
}
function close() {
dialogRef.current?.close();
}
return (
<>
<button
ref={triggerRef}
className={className}
type="button"
aria-haspopup="dialog"
aria-controls={dialogId}
aria-label="TechLog 검색 열기"
onClick={open}
>
검색
</button>
<dialog
ref={dialogRef}
className="search-dialog"
id={dialogId}
aria-labelledby={dialogId + "-title"}
onClose={() => triggerRef.current?.focus()}
onKeyDown={(event) => {
if (event.key === "Escape") {
event.preventDefault();
close();
}
}}
onClick={(event) => {
if (event.target === event.currentTarget) close();
}}
>
<div className="search-dialog-inner">
<header>
<div>
<p className="context-label">Public records</p>
<h2 id={dialogId + "-title"}>TechLog 검색</h2>
</div>
<button type="button" className="dialog-close" onClick={close}>
닫기
</button>
</header>
<label className="search-field">
<span className="visually-hidden">검색어</span>
<span aria-hidden="true"></span>
<input
ref={inputRef}
type="search"
value={query}
onChange={(event) => setQuery(event.target.value)}
placeholder="제목, 요약, 주제, 프로젝트 검색"
autoComplete="off"
/>
</label>
<p className="search-count" aria-live="polite">
{results.length}개의 공개 기록
</p>
{results.length > 0 ? (
<>
<ul className="search-results">
{results.map((entry) => (
<li key={entry.path}>
<Link to={entry.path} onClick={close}>
<span>{entry.contentType}</span>
<strong>{entry.title}</strong>
<p>{entry.summary}</p>
</Link>
</li>
))}
</ul>
{normalizedQuery ? (
<Link
className="search-all-link"
to={`/search?q=${encodeURIComponent(query.trim())}`}
onClick={close}
>
전체 검색 결과 보기 <span aria-hidden="true"></span>
</Link>
) : null}
</>
) : (
<p className="search-empty">일치하는 공개 기록이 없습니다.</p>
)}
</div>
</dialog>
</>
);
}