Summary card links to the detailed analysis tab
CI / test (push) Successful in 47s
CI / build (push) Successful in 3m41s
CI / deploy (push) Skipped

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-17 10:43:03 +00:00
co-authored by Claude Opus 5.5
parent 1e95459671
commit 0e01f88f31
4 changed files with 48 additions and 5 deletions
@@ -7,6 +7,7 @@ import type { Analysis } from "@/lib/types";
import { AnalysisLoading } from "./AnalysisLoading";
import { Rich } from "./Rich";
import { openTab } from "./Tabs";
const POLL_MS = 3000;
const MAX_POLLS = 60;
@@ -16,7 +17,16 @@ const MAX_POLLS = 60;
* saved; this asks for it (queueing it again if it failed) and polls until the
* worker has written it.
*/
export function ChartSummary({ chartId, initial }: { chartId: string; initial: Analysis | null }) {
export function ChartSummary({
chartId,
initial,
detailedDone = false,
}: {
chartId: string;
initial: Analysis | null;
/** The detailed analysis is ready: the link says so instead of offering it. */
detailedDone?: boolean;
}) {
const [summary, setSummary] = useState<Analysis | null>(initial);
const [gaveUp, setGaveUp] = useState(false);
const done = summary?.status === "done";
@@ -57,6 +67,17 @@ export function ChartSummary({ chartId, initial }: { chartId: string; initial: A
<p className="summary-text">
<Rich text={content.summary ?? ""} />
</p>
<a
href="#elemzes"
className="summary-more"
onClick={(e) => {
e.preventDefault();
openTab("elemzes");
}}
>
{detailedDone ? "Elolvasom a részletes elemzést" : "Kérj részletes elemzést: hat fejezet a képletedről"}
<span aria-hidden="true"> →</span>
</a>
</>
) : (
<>
+19 -3
View File
@@ -9,13 +9,29 @@ export type Tab = { id: string; label: string; content: ReactNode };
* shared link opens the same tab. Hidden panels stay mounted: a running
* analysis keeps polling while another tab is open.
*/
/** Opens a tab from anywhere on the page (also when the hash is already that tab). */
export function openTab(id: string) {
history.replaceState(null, "", `#${id}`);
window.dispatchEvent(new HashChangeEvent("hashchange"));
}
export function Tabs({ tabs, label }: { tabs: Tab[]; label: string }) {
const [active, setActive] = useState(tabs[0]?.id);
const buttons = useRef<(HTMLButtonElement | null)[]>([]);
const root = useRef<HTMLDivElement>(null);
// A link to #<tab> (on load, or from elsewhere on the page) opens that tab and scrolls to it.
useEffect(() => {
const fromHash = window.location.hash.slice(1);
if (tabs.some((t) => t.id === fromHash)) setActive(fromHash);
const open = () => {
const id = window.location.hash.slice(1);
if (!tabs.some((t) => t.id === id)) return;
setActive(id);
root.current?.scrollIntoView({ behavior: "smooth", block: "start" });
};
open();
window.addEventListener("hashchange", open);
return () => window.removeEventListener("hashchange", open);
}, [tabs]);
function choose(id: string) {
@@ -33,7 +49,7 @@ export function Tabs({ tabs, label }: { tabs: Tab[]; label: string }) {
}
return (
<div className="tabs">
<div className="tabs" ref={root}>
<div className="tab-list" role="tablist" aria-label={label}>
{tabs.map((t, i) => (
<button