fix: 홈 주제 탭이 큐레이션 칸 대신 실제 기록을 읽는다
CPU 가상화 주제에 글을 게시했는데 홈 탭은 「아직 공개된 기록이 없습니다」였다. 축을 쓰지 않는 주제의 목록을 상세의 featuredCases 로 만들었는데, 그 칸은 작성자가 주제마다 손으로 골라 두는 값이라 대부분 비어 있다. 게다가 Case 만 담아서, 게시한 것이 동작 원리면 애초에 담기지 않는다 — 주제 목록의 recordCount 는 1 인데 탭은 0 이라고 말했다. 주제 화면이 하는 것과 같이 기록 자체를 읽는다. 받는 중에는 「없습니다」라고 말하지 않는다. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PTnWufiY9ATv57egkKKVAV
This commit is contained in:
co-authored by
Claude Opus 5
parent
304893dfde
commit
15af37bbc9
@@ -1,9 +1,10 @@
|
||||
import { useRef, useState } from "react";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
|
||||
import { useApplication } from "../../../../../presentation/providers/application-provider.tsx";
|
||||
import { TECH_LOG_FEATURE_ID } from "../../../application/tech-log-feature-input.ts";
|
||||
import type {
|
||||
PublicRecord,
|
||||
PublicTopic,
|
||||
PublicTopicDetail,
|
||||
} from "../../../application/ports/public-content-queries.ts";
|
||||
@@ -38,6 +39,16 @@ export function HomeTopicTabs({
|
||||
[firstDetail.slug]: firstDetail,
|
||||
});
|
||||
const [failedSlug, setFailedSlug] = useState<string | null>(null);
|
||||
/*
|
||||
축을 쓰지 않는 주제의 기록.
|
||||
|
||||
처음에는 상세의 `featuredCases` 를 썼는데 그것은 작성자가 주제마다 손으로 골라 두는 값이라
|
||||
대부분 비어 있다 — CPU 가상화에 글을 게시해도 홈 탭은 「아직 공개된 기록이 없습니다」였다.
|
||||
게다가 그 칸은 Case 만 담아서, 게시한 것이 동작 원리면 애초에 담기지 않는다.
|
||||
|
||||
주제 화면이 하는 것과 같이 기록 자체를 읽는다.
|
||||
*/
|
||||
const [records, setRecords] = useState<Readonly<Record<string, ReadonlyArray<PublicRecord>>>>({});
|
||||
const buttons = useRef<Array<HTMLButtonElement | null>>([]);
|
||||
const slugs = topics.map((topic) => topic.slug);
|
||||
const active = topics.find((topic) => topic.slug === activeSlug) ?? topics[0];
|
||||
@@ -50,6 +61,7 @@ export function HomeTopicTabs({
|
||||
buttons.current[slugs.indexOf(slug)]?.focus();
|
||||
});
|
||||
}
|
||||
loadRecordsIfNeeded(slug, details[slug]);
|
||||
if (details[slug]) return;
|
||||
void publicContent
|
||||
.getTopicDetail(slug)
|
||||
@@ -59,6 +71,7 @@ export function HomeTopicTabs({
|
||||
return;
|
||||
}
|
||||
setDetails((loaded) => ({ ...loaded, [slug]: detail }));
|
||||
loadRecordsIfNeeded(slug, detail);
|
||||
})
|
||||
/*
|
||||
받지 못했다는 사실을 그 자리에 남긴다. 예전에 홈이 두 읽기를 `Promise.all` 로 묶었을 때는
|
||||
@@ -67,6 +80,22 @@ export function HomeTopicTabs({
|
||||
.catch(() => setFailedSlug(slug));
|
||||
}
|
||||
|
||||
/* 견줄 축이 없는 주제만 기록을 따로 받는다. 축이 있으면 축이 곧 목록이다. */
|
||||
function loadRecordsIfNeeded(slug: string, detail: PublicTopicDetail | undefined) {
|
||||
if (!detail || detail.variants.length > 1) return;
|
||||
if (records[slug]) return;
|
||||
void publicContent
|
||||
.listRecords({ topic: slug })
|
||||
.then((found) => setRecords((loaded) => ({ ...loaded, [slug]: found })))
|
||||
.catch(() => setRecords((loaded) => ({ ...loaded, [slug]: [] })));
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
loadRecordsIfNeeded(firstDetail.slug, firstDetail);
|
||||
// 첫 주제는 상세가 이미 와 있으므로 여기서 한 번만 본다.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [firstDetail]);
|
||||
|
||||
function onKeyDown(event: React.KeyboardEvent<HTMLButtonElement>) {
|
||||
if (!["ArrowLeft", "ArrowRight", "Home", "End"].includes(event.key)) return;
|
||||
event.preventDefault();
|
||||
@@ -91,10 +120,10 @@ export function HomeTopicTabs({
|
||||
title: variant.title,
|
||||
line: variant.conclusion || variant.summary,
|
||||
}))
|
||||
: detail.featuredCases.map((record) => ({
|
||||
: (records[active.slug] ?? []).map((record) => ({
|
||||
path: record.path,
|
||||
title: record.title,
|
||||
line: record.summary || record.note,
|
||||
line: record.summary,
|
||||
}))
|
||||
: [];
|
||||
const comparing = (detail?.variants.length ?? 0) > 1;
|
||||
@@ -179,7 +208,7 @@ export function HomeTopicTabs({
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : detail ? (
|
||||
) : detail && (comparing || records[active.slug]) ? (
|
||||
<p className="home-topic-pending">
|
||||
{`${active.name}에는 아직 공개된 기록이 없습니다.`}
|
||||
</p>
|
||||
|
||||
Reference in New Issue
Block a user