You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
3.4 KiB
TypeScript
106 lines
3.4 KiB
TypeScript
// frontend/components/research/ResearchClient.tsx — 리서치 페이지 오케스트레이터 (Topbar 제외)
|
|
"use client";
|
|
import { useEffect, useRef, useState } from "react";
|
|
import { useResearch } from "@/lib/hooks/useResearch";
|
|
import { Icon } from "@/components/Icon";
|
|
import { ResearchSidebar, type ResearchView } from "./ResearchSidebar";
|
|
import { Composer } from "./Composer";
|
|
import { HomeGrid } from "./HomeGrid";
|
|
import { ReportCard } from "./ReportCard";
|
|
import { QACard } from "./QACard";
|
|
import { ChartCard } from "./ChartCard";
|
|
|
|
const RS_HEAD: Record<ResearchView, { h: string; p: string }> = {
|
|
home: {
|
|
h: "지능형 리서치 파트너",
|
|
p: "찾고, 비교하고, 그려보는 일은 아리가 — 판단은 지우님이 하세요.",
|
|
},
|
|
report: { h: "멀티소스 종합 리포트", p: "논문·뉴스·보고서를 모아 출처군별로 교차 분석해요." },
|
|
qa: { h: "지식 베이스 Q&A", p: "저장한 PDF·웹·메모를 학습해 근거와 함께 답해요." },
|
|
chart: { h: "시각화 & 추세 예측", p: "데이터를 그리고, 한계까지 짚어 예측해요." },
|
|
};
|
|
|
|
function isView(v: string): v is ResearchView {
|
|
return v === "home" || v === "report" || v === "qa" || v === "chart";
|
|
}
|
|
|
|
export function ResearchClient() {
|
|
const [view, setView] = useState<ResearchView>("home");
|
|
const [hydrated, setHydrated] = useState(false);
|
|
const shellRef = useRef<HTMLDivElement>(null);
|
|
const { home, report, qa, chart, error, reload } = useResearch();
|
|
|
|
// localStorage 복원 (SSR 안정)
|
|
useEffect(() => {
|
|
try {
|
|
const v = localStorage.getItem("ariR.view");
|
|
if (v) {
|
|
const parsed = JSON.parse(v);
|
|
if (typeof parsed === "string" && isView(parsed)) setView(parsed);
|
|
}
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
setHydrated(true);
|
|
}, []);
|
|
useEffect(() => {
|
|
if (hydrated) {
|
|
try {
|
|
localStorage.setItem("ariR.view", JSON.stringify(view));
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
}
|
|
}, [view, hydrated]);
|
|
|
|
// 진입 애니메이션
|
|
useEffect(() => {
|
|
const el = shellRef.current;
|
|
const id = requestAnimationFrame(() => el && el.classList.add("entered"));
|
|
return () => cancelAnimationFrame(id);
|
|
}, [view]);
|
|
|
|
if (error && !home) {
|
|
return (
|
|
<div className="researchpage">
|
|
<div className="rs-error" role="alert">
|
|
<Icon name="x" /> 리서치를 불러오지 못했어요
|
|
<button onClick={() => reload()}>다시 시도</button>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
const head = RS_HEAD[view];
|
|
|
|
return (
|
|
<div className="researchpage" ref={shellRef}>
|
|
<div className="tpage">
|
|
<div className="twork">
|
|
<ResearchSidebar
|
|
view={view}
|
|
onPick={setView}
|
|
collections={home?.collections ?? []}
|
|
sources={home?.sources ?? []}
|
|
/>
|
|
<main className="rs-main">
|
|
<div className="rs-head">
|
|
<h1>{head.h}</h1>
|
|
<p>{head.p}</p>
|
|
</div>
|
|
{view === "home" && (
|
|
<>
|
|
<Composer prompts={home?.prompts ?? []} onReady={setView} />
|
|
<HomeGrid entries={home?.entries ?? []} go={setView} />
|
|
</>
|
|
)}
|
|
{view === "report" && <ReportCard report={report} />}
|
|
{view === "qa" && <QACard qa={qa} />}
|
|
{view === "chart" && <ChartCard chart={chart} />}
|
|
</main>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|