diff --git a/home-tabs-keycloak.png b/home-tabs-keycloak.png new file mode 100644 index 0000000..042e0e1 Binary files /dev/null and b/home-tabs-keycloak.png differ diff --git a/src/features/tech-log/presentation/public/components/home-topic-tabs.tsx b/src/features/tech-log/presentation/public/components/home-topic-tabs.tsx index 738c7f6..21aa120 100644 --- a/src/features/tech-log/presentation/public/components/home-topic-tabs.tsx +++ b/src/features/tech-log/presentation/public/components/home-topic-tabs.tsx @@ -1,37 +1,70 @@ import { useRef, useState } from "react"; import { Link } from "react-router-dom"; -import type { PublicTopicDetail } from "../../../application/ports/public-content-queries.ts"; +import { useApplication } from "../../../../../presentation/providers/application-provider.tsx"; +import { TECH_LOG_FEATURE_ID } from "../../../application/tech-log-feature-input.ts"; +import type { + PublicTopic, + PublicTopicDetail, +} from "../../../application/ports/public-content-queries.ts"; import { moveFocus } from "../../../domain/public/focus-state.ts"; /** * 홈에서 주제를 갈아 가며 그 안의 비교를 읽는 자리. * *

예전에는 주제 하나만 펴 두고 나머지는 아래 「다른 주제 N개 보기」 한 줄로 보냈다. 그 줄은 - * 비교 목록 밑에 작은 글씨로 있어서, 읽는 사람이 첫 주제를 다 읽고 나서야 만났고 대개 그냥 - * 지나쳤다 — 실제로 JPA 주제는 홈에 있는데도 없는 것과 같았다. 주제 이름을 탭으로 나란히 세우면 + * 비교 목록 밑에 작은 글씨로 있어서 읽는 사람이 첫 주제를 다 읽고 나서야 만났고 대개 그냥 + * 지나쳤다 — 실제로 JPA 주제는 홈에 있는데도 없는 것과 같았다. 주제 이름을 나란히 세우면 * 무엇이 더 있는지가 목록을 읽기 전에 먼저 보인다. * - *

패널은 전부 그려 두고 `hidden` 으로 감춘다. 주제 상세는 이미 다 받아 온 것이라 탭을 눌러도 - * 요청이 나가지 않고, 브라우저의 페이지 내 검색이 감춘 주제까지 찾아 준다. + *

이름은 칩 크기로 적는다. 한때 구역 제목 급(30px)으로 세웠는데, 그 급은 주제가 둘일 때나 + * 성립한다 — 열 개, 스무 개가 되면 이름만으로 화면이 덮인다. 지금 읽는 것이 무엇인지는 목록 + * 바로 위의 축 이름과 「전체 보기」 줄이 말한다. + * + *

상세는 고른 것만 받는다. 주제마다 미리 받으면 요청 수가 주제 수만큼 늘어나고, 그것이 + * 싫어 앞의 몇 개만 받으면 나머지는 다시 탭에 오르지 못한다 — 없애려던 문제로 되돌아간다. + * 목록은 한 번에 오고, 그 목록이 탭 전부다. */ export function HomeTopicTabs({ topics, + firstDetail, }: { - topics: ReadonlyArray; + topics: ReadonlyArray; + firstDetail: PublicTopicDetail; }) { - const [activeSlug, setActiveSlug] = useState(topics[0]?.slug ?? ""); + const { publicContent } = useApplication().features.get(TECH_LOG_FEATURE_ID); + const [activeSlug, setActiveSlug] = useState(firstDetail.slug); + const [details, setDetails] = useState>>({ + [firstDetail.slug]: firstDetail, + }); + const [failedSlug, setFailedSlug] = useState(null); const buttons = useRef>([]); const slugs = topics.map((topic) => topic.slug); const active = topics.find((topic) => topic.slug === activeSlug) ?? topics[0]; function select(slug: string, moveKeyboardFocus = false) { setActiveSlug(slug); + setFailedSlug((failed) => (failed === slug ? null : failed)); if (moveKeyboardFocus) { requestAnimationFrame(() => { buttons.current[slugs.indexOf(slug)]?.focus(); }); } + if (details[slug]) return; + void publicContent + .getTopicDetail(slug) + .then((detail) => { + if (!detail) { + setFailedSlug(slug); + return; + } + setDetails((loaded) => ({ ...loaded, [slug]: detail })); + }) + /* + 받지 못했다는 사실을 그 자리에 남긴다. 예전에 홈이 두 읽기를 `Promise.all` 로 묶었을 때는 + 하나가 실패하면 나머지까지 통째로 사라져, 무엇이 잘못됐는지 화면에 흔적이 없었다. + */ + .catch(() => setFailedSlug(slug)); } function onKeyDown(event: React.KeyboardEvent) { @@ -43,17 +76,20 @@ export function HomeTopicTabs({ if (!active) return null; + const detail = details[active.slug]; + const axisLabel = (detail?.variantLabel ?? active.variantLabel).trim(); + const multiple = topics.length > 1; + return ( <> {/* - 탭이 하나뿐이면 고를 것이 없다. 그래도 주제 이름은 보여야 한다 — 아래 목록이 무엇을 - 견준 것인지 말해 주는 유일한 자리이기 때문이다. 그래서 목록은 지우지 않고, 고르는 - 일만 없앤다. + 탭이 하나뿐이면 고를 것이 없다. 그래도 이름은 보여야 한다 — 아래 목록이 어느 주제의 + 것인지 말해 주는 자리이기 때문이다. 그래서 이름은 두고, 고르는 일만 없앤다. */}

1 ? "tablist" : undefined} - aria-label={topics.length > 1 ? "주제 고르기" : undefined} + role={multiple ? "tablist" : undefined} + aria-label={multiple ? "주제 고르기" : undefined} > {topics.map((topic, index) => { const selected = topic.slug === active.slug; @@ -65,10 +101,10 @@ export function HomeTopicTabs({ }} id={`home-topic-tab-${topic.slug}`} type="button" - role={topics.length > 1 ? "tab" : undefined} - aria-selected={topics.length > 1 ? selected : undefined} - aria-controls={`home-topic-panel-${topic.slug}`} - tabIndex={topics.length > 1 && !selected ? -1 : 0} + role={multiple ? "tab" : undefined} + aria-selected={multiple ? selected : undefined} + aria-controls="home-topic-panel" + tabIndex={multiple && !selected ? -1 : 0} onClick={() => select(topic.slug)} onKeyDown={onKeyDown} > @@ -78,47 +114,51 @@ export function HomeTopicTabs({ })}
- {topics.map((topic) => { - const axisLabel = topic.variantLabel.trim(); - return ( -
1 ? "tabpanel" : undefined} - aria-labelledby={ - topics.length > 1 ? `home-topic-tab-${topic.slug}` : undefined - } - hidden={topic.slug !== active.slug} - > - {/* - 무엇을 기준으로 나눈 목록인지 한 낱말로 말한다. 제목 자리를 탭이 가져갔으니 축의 - 이름은 목록 바로 위에 붙어야 짝이 보인다 — 「구조」 넷과 「조회 전략」 셋은 같은 - 배치로 그려지지만 다른 것을 견준다. - */} -
-

{axisLabel || "비교"}

- - {`${topic.name} 전체 보기`} - -
- -
- ); - })} + {/* + 패널은 하나다. 주제마다 하나씩 그려 두려면 상세를 전부 받아 와야 하고, 그러면 주제가 + 늘 때마다 홈이 보내는 요청이 함께 는다. + */} +
+ {/* + 무엇을 기준으로 나눈 목록인지 한 낱말로 말한다. 이름 칸을 칩이 가져갔으니 축의 이름은 + 목록 바로 위에 붙어야 짝이 보인다 — 「구조」 넷과 「조회 전략」 셋은 같은 배치로 + 그려지지만 다른 것을 견준다. + */} +
+

{axisLabel || "비교"}

+ + {`${active.name} 전체 보기`} + +
+ {detail ? ( + + ) : ( +

+ {failedSlug === active.slug + ? "이 주제를 지금 불러오지 못했습니다." + : `${active.name}을(를) 여는 중입니다.`} +

+ )} +
); } diff --git a/src/features/tech-log/presentation/public/pages/home-page.tsx b/src/features/tech-log/presentation/public/pages/home-page.tsx index 13580a1..95dbf05 100644 --- a/src/features/tech-log/presentation/public/pages/home-page.tsx +++ b/src/features/tech-log/presentation/public/pages/home-page.tsx @@ -125,9 +125,6 @@ function dateLabel(isoTimestamp: string): string { ).padStart(2, "0")}`; } -/** 홈이 탭으로 펴 두는 주제 수. 주제마다 상세 요청이 하나씩 나가므로 상한을 둔다. */ -const TOPIC_TABS_ON_HOME = 4; - /** * 홈이 비교를 펴 두는 주제들. * @@ -137,9 +134,9 @@ const TOPIC_TABS_ON_HOME = 4; *

예전에는 첫 주제 하나만 펴 두고 나머지는 아래 한 줄로 보냈다. 그 줄은 비교 목록 밑에 * 작은 글씨로 있어 대개 지나쳤고, 그래서 JPA 주제는 홈에 있으면서도 없는 것과 같았다. * - *

요청은 목록 하나 + 탭이 되는 주제마다 상세 하나다. 주제가 늘어도 상한이 있어 홈의 - * 요청 수는 정해져 있다 — 프로젝트마다 요청을 보내던 최근 기록에서 겪은 것과 같은 모양을 - * 만들지 않는다. + *

요청은 둘이다 — 목록 하나와 첫 주제의 상세 하나. 나머지 주제의 상세는 탭을 고를 때 + * 받는다. 여기서 전부 받으면 주제가 늘 때마다 홈의 요청이 함께 늘고, 그것이 싫어 앞의 몇 + * 개만 받으면 나머지는 다시 탭에 오르지 못한다 — 없애려던 문제로 되돌아간다. */ async function getTopics(publicContent: PublicContentQueries) { const topics = await publicContent.listTopics(); @@ -148,18 +145,15 @@ async function getTopics(publicContent: PublicContentQueries) { const comparable = [...topics] .filter((topic) => topic.variantCount > 1) .sort((left, right) => right.recordCount - left.recordCount); - const shown = comparable.slice(0, TOPIC_TABS_ON_HOME); - const details = await Promise.all( - shown.map((topic) => publicContent.getTopicDetail(topic.slug)), - ); + const first = comparable[0]; + const firstDetail = first ? await publicContent.getTopicDetail(first.slug) : undefined; return { /** 탭 하나씩. 축이 둘 이상이어야 견줄 것이 있다. */ - tabs: details.filter( - (detail): detail is PublicTopicDetail => - detail !== undefined && detail.variants.length > 1, - ), - /** 탭에 오르지 못한 주제 수. 있으면 주제 목록으로 가는 길을 남긴다. */ - remaining: topics.length - shown.length, + tabs: comparable, + /** 처음 열려 있을 주제. 이것만 미리 받는다. */ + firstDetail: firstDetail && firstDetail.variants.length > 1 ? firstDetail : undefined, + /** 축이 없어 탭이 되지 못한 주제 수. 있으면 주제 목록으로 가는 길을 남긴다. */ + remaining: topics.length - comparable.length, }; } @@ -224,9 +218,9 @@ export function HomePage() { 무엇이 더 있는지는 다 읽고 나서야 알 수 있었다. 이름을 나란히 세우면 목록을 읽기 전에 먼저 보인다. */} - {topics.tabs.length > 0 ? ( + {topics.firstDetail ? (

- + {/* 축을 쓰지 않아 탭이 되지 못한 주제로 가는 길. 탭에 다 올라와 있으면 이 줄은 diff --git a/src/features/tech-log/presentation/styles/globals.css b/src/features/tech-log/presentation/styles/globals.css index 4c43b41..6d79800 100644 --- a/src/features/tech-log/presentation/styles/globals.css +++ b/src/features/tech-log/presentation/styles/globals.css @@ -2965,49 +2965,41 @@ textarea.studio-control { min-height: 118px; resize: vertical; line-height: 1.65 } /* - 주제 이름 탭. 구역 제목이 서 있던 자리라 그 급을 그대로 쓴다 — 크기와 굵기는 - `.section-heading-row h2` 를 따른다(`section-heading-rank` 검사가 그 짝을 지킨다). + 주제 이름 탭. + + 한때 구역 제목 급(30px/650)으로 세웠다. 주제가 둘일 때는 그럴듯했지만 열 개, 스무 개가 되면 + 이름만으로 화면이 덮인다 — 여기서 하려는 말은 「이것이 이 구역의 제목이다」가 아니라 「고를 것이 + 이만큼 있다」이므로, 급도 그쪽이어야 한다. 지금 무엇을 읽는지는 목록 바로 위의 축 이름과 + 「전체 보기」 줄이 말한다. - 고르지 않은 탭은 색만 죽인다. 크기를 줄이면 탭이 아니라 「하나가 제목이고 나머지는 곁다리」로 - 읽히는데, 이 자리에서 하려는 말은 그 반대다 — 주제들은 나란하다. + 고르지 않은 것은 색만 죽인다. 밑줄 같은 표시를 더하면 주제 스무 개가 밑줄 스무 개 자리를 + 두고 늘어선다. */ .home-topic-tabs { display: flex; flex-wrap: wrap; - gap: 8px 32px; - padding-bottom: 26px; + gap: 4px 24px; + padding-bottom: 30px; } .home-topic-tabs button { - position: relative; - padding: 11px 0 6px; + display: inline-flex; + min-height: 32px; + align-items: center; + padding: 0; border: 0; background: transparent; color: var(--faint); cursor: pointer; font-family: inherit; - font-size: 30px; - font-weight: 650; - letter-spacing: -0.045em; - line-height: 1.15; + font-size: 14px; + font-weight: 560; + letter-spacing: -0.01em; text-align: left; } .home-topic-tabs button[aria-selected="true"], -.home-topic-tabs button:only-child { - color: var(--ink); -} - -.home-topic-tabs button[aria-selected="true"]::after { - position: absolute; - right: 0; - bottom: 0; - left: 0; - height: 2px; - background: var(--signal); - content: ""; -} - +.home-topic-tabs button:only-child, .home-topic-tabs button:hover { color: var(--ink); } @@ -3028,6 +3020,15 @@ textarea.studio-control { min-height: 118px; resize: vertical; line-height: 1.65 margin: 0; } +/* 아직 오지 않았거나 오지 못한 주제. 자리를 비워 두면 목록이 사라진 것처럼 보인다. */ +.home-topic-pending { + margin: 0; + padding: 26px 2px; + border-top: 1px solid var(--line-strong); + color: var(--muted); + font-size: 14px; +} + .home-comparison ul { margin: 0; padding: 0; @@ -3077,13 +3078,8 @@ textarea.studio-control { min-height: 118px; resize: vertical; line-height: 1.65 gap: 8px; } - /* 좁은 화면에서는 탭 이름이 두세 줄로 접힌다 — 나란히 세우려면 급을 한 단 낮춰야 한다. */ .home-topic-tabs { - gap: 6px 22px; - } - - .home-topic-tabs button { - font-size: 22px; + gap: 2px 18px; } } diff --git a/tests/features/tech-log/home-topic-tabs.test.tsx b/tests/features/tech-log/home-topic-tabs.test.tsx index f6949c3..535b6de 100644 --- a/tests/features/tech-log/home-topic-tabs.test.tsx +++ b/tests/features/tech-log/home-topic-tabs.test.tsx @@ -1,12 +1,20 @@ // @vitest-environment jsdom -import { render, screen, within } from "@testing-library/react"; +import { render, screen, waitFor, within } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; -import { describe, expect, it } from "vitest"; +import { describe, expect, it, vi } from "vitest"; import { MemoryRouter } from "react-router-dom"; -import type { PublicTopicDetail } from "../../../src/features/tech-log/application/ports/public-content-queries.ts"; +import { createTechLogFeatureInstalledInput } from "../../../src/features/tech-log/adapters/create-tech-log-feature-input.ts"; +import type { + PublicTopic, + PublicTopicDetail, +} from "../../../src/features/tech-log/application/ports/public-content-queries.ts"; import { HomeTopicTabs } from "../../../src/features/tech-log/presentation/public/components/home-topic-tabs.tsx"; +import { ApplicationProvider } from "../../../src/presentation/providers/application-provider.tsx"; +import { createTestApplication } from "../../helpers/create-test-application.ts"; +import { renderWithQueryProviders } from "../../helpers/query-providers.tsx"; +import { MOCK_STUDIO_INSTALL_CONTEXT } from "../../helpers/studio-install-context.ts"; /** * 홈이 주제 하나만 펴 두던 동안, 나머지로 가는 길은 비교 목록 밑의 작은 글씨 한 줄뿐이었다 — @@ -50,17 +58,52 @@ const JPA = topic("jpa-feed-query-performance", "JPA 피드 조회 성능", "조 ["derived-query", "Derived Query", "쿼리가 나뉜다"], ]); -function renderTabs(topics: ReadonlyArray) { - return render( - - - , - ); +/** 목록이 주는 만큼. 탭은 상세 없이 이것만으로 그려져야 한다. */ +function listItem(detail: PublicTopicDetail, recordCount: number): PublicTopic { + return { + name: detail.name, + slug: detail.slug, + thesis: "", + description: "", + variantLabel: detail.variantLabel, + variantCount: detail.variants.length, + recordCount, + }; } +function renderTabs( + topics: ReadonlyArray, + firstDetail: PublicTopicDetail, + getTopicDetail = vi.fn(async (slug: string) => + [AUTH, JPA].find((detail) => detail.slug === slug), + ), +) { + const techLog = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input; + const application = createTestApplication({ + featureInputs: { + "tech-log": { + ...techLog, + publicContent: { ...techLog.publicContent, getTopicDetail }, + }, + }, + }); + render( + renderWithQueryProviders( + + + + + , + ), + ); + return { getTopicDetail }; +} + +const TABS = [listItem(AUTH, 18), listItem(JPA, 3)]; + describe("홈의 주제 탭", () => { it("주제 이름이 목록보다 먼저 전부 보인다", () => { - renderTabs([AUTH, JPA]); + renderTabs(TABS, AUTH); expect(screen.getAllByRole("tab").map((tab) => tab.textContent)).toEqual([ "OAuth/OIDC 인증 경계", @@ -68,8 +111,10 @@ describe("홈의 주제 탭", () => { ]); }); - it("첫 주제의 축이 열려 있고 나머지 주제의 축은 감춰져 있다", () => { - renderTabs([AUTH, JPA]); + it("첫 주제의 축은 미리 받아 둔 것으로 곧바로 열린다", () => { + const { getTopicDetail } = renderTabs(TABS, AUTH); + + expect(getTopicDetail).not.toHaveBeenCalled(); const open = screen.getByRole("tabpanel"); expect(within(open).getAllByRole("link").map((link) => link.textContent)).toEqual([ @@ -82,28 +127,59 @@ describe("홈의 주제 탭", () => { expect(within(open).getByText("구조")).toBeTruthy(); }); - it("탭을 고르면 그 주제의 축으로 바뀐다", async () => { + it("고른 주제의 상세만 그때 받는다", async () => { const user = userEvent.setup(); - renderTabs([AUTH, JPA]); + const { getTopicDetail } = renderTabs(TABS, AUTH); await user.click(screen.getByRole("tab", { name: "JPA 피드 조회 성능" })); + expect(getTopicDetail).toHaveBeenCalledExactlyOnceWith("jpa-feed-query-performance"); const open = screen.getByRole("tabpanel"); expect(within(open).getByText("조회 전략")).toBeTruthy(); - expect( - within(open) - .getAllByRole("link") - .map((link) => link.getAttribute("href")), - ).toEqual([ - "/topics/jpa-feed-query-performance", - "/topics/jpa-feed-query-performance/fetch-join", - "/topics/jpa-feed-query-performance/derived-query", - ]); + await waitFor(() => + expect( + within(open) + .getAllByRole("link") + .map((link) => link.getAttribute("href")), + ).toEqual([ + "/topics/jpa-feed-query-performance", + "/topics/jpa-feed-query-performance/fetch-join", + "/topics/jpa-feed-query-performance/derived-query", + ]), + ); + }); + + it("한 번 받은 주제는 다시 받지 않는다", async () => { + const user = userEvent.setup(); + const { getTopicDetail } = renderTabs(TABS, AUTH); + + await user.click(screen.getByRole("tab", { name: "JPA 피드 조회 성능" })); + await screen.findByText("조회 전략"); + await user.click(screen.getByRole("tab", { name: "OAuth/OIDC 인증 경계" })); + await user.click(screen.getByRole("tab", { name: "JPA 피드 조회 성능" })); + + expect(getTopicDetail).toHaveBeenCalledOnce(); + }); + + it("받지 못하면 그 자리에 남긴다 — 목록만 사라지지 않는다", async () => { + const user = userEvent.setup(); + renderTabs( + TABS, + AUTH, + vi.fn(async () => { + throw new Error("불통"); + }), + ); + + await user.click(screen.getByRole("tab", { name: "JPA 피드 조회 성능" })); + + expect(await screen.findByText("이 주제를 지금 불러오지 못했습니다.")).toBeTruthy(); + expect(screen.getAllByRole("tab")).toHaveLength(2); }); it("방향키로 탭을 옮긴다", async () => { const user = userEvent.setup(); - renderTabs([AUTH, JPA]); + renderTabs(TABS, AUTH); await user.tab(); await user.keyboard("{ArrowRight}"); @@ -114,7 +190,7 @@ describe("홈의 주제 탭", () => { }); it("주제가 하나면 고를 것이 없지만 목록은 그대로 나온다", () => { - renderTabs([AUTH]); + renderTabs([listItem(AUTH, 18)], AUTH); expect(screen.queryAllByRole("tab")).toHaveLength(0); expect(screen.getByRole("button").textContent).toBe("OAuth/OIDC 인증 경계"); diff --git a/tests/features/tech-log/section-heading-rank.test.ts b/tests/features/tech-log/section-heading-rank.test.ts index 52611d3..324ef0f 100644 --- a/tests/features/tech-log/section-heading-rank.test.ts +++ b/tests/features/tech-log/section-heading-rank.test.ts @@ -17,18 +17,11 @@ const RAW = readFileSync("src/features/tech-log/presentation/styles/globals.css" */ const CSS = RAW.replace(/@media[^{]*\{(?:[^{}]*\{[^}]*\})*[^{}]*\}/gu, ""); -/** - * 나란히 서는 구역 제목들. 정본이 맨 앞이다. - * - *

홈의 주제 탭은 h2 가 아니지만 구역 제목이 서 있던 자리를 그대로 물려받았다. 태그가 다르다는 - * 이유로 급을 따로 정하면 같은 자리에 있는 글자가 화면마다 다른 크기로 나온다 — 이 검사가 처음 - * 잡은 것이 바로 그 일이다. - */ +/** 나란히 서는 구역 제목들. 정본이 맨 앞이다. */ const SECTION_HEADINGS = [ ".section-heading-row h2", ".document-relations h2", ".topic-variants h2", - ".home-topic-tabs button", ] as const; /** 마지막으로 선언된 값을 읽는다 — 뒤에 오는 규칙이 이긴다. */