From 3ca117ed7f811e695861a03f25afad5aea790829 Mon Sep 17 00:00:00 2001 From: Tyler Hoang Date: Mon, 18 May 2026 01:35:43 -0700 Subject: feat: add ValuationPage data-fetch wrapper --- frontend/components/prism/ValuationPage.tsx | 61 +++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 frontend/components/prism/ValuationPage.tsx (limited to 'frontend') diff --git a/frontend/components/prism/ValuationPage.tsx b/frontend/components/prism/ValuationPage.tsx new file mode 100644 index 0000000..3a3ba27 --- /dev/null +++ b/frontend/components/prism/ValuationPage.tsx @@ -0,0 +1,61 @@ +"use client"; +import { useEffect, useState } from "react"; +import { api } from "@/lib/api"; +import { buildKpis } from "@/lib/overview"; +import { ValuationCard } from "@/components/prism/ValuationCard"; +import { KPIStrip } from "@/components/prism/KPIStrip"; +import { TickerHeader } from "@/components/prism/TickerHeader"; +import type { TickerOverview, ValuationResponse } from "@/types/api"; + +type ValState = "loading" | "ready" | "error"; + +type Props = { + ticker: string; + overview: TickerOverview; + isSaved: boolean; + onToggleWatchlist: () => void; +}; + +export function ValuationPage({ ticker, overview, isSaved, onToggleWatchlist }: Props) { + const [data, setData] = useState(null); + const [valState, setValState] = useState("loading"); + const kpis = buildKpis(overview); + + useEffect(() => { + let cancelled = false; + setValState("loading"); + setData(null); + + api + .valuation(ticker) + .then((res) => { + if (!cancelled) { + setData(res); + setValState("ready"); + } + }) + .catch(() => { + if (!cancelled) setValState("error"); + }); + + return () => { + cancelled = true; + }; + }, [ticker]); + + return ( + <> + + + {valState === "loading" && ( +
+ )} + {valState === "error" && ( +
+

Valuation data unavailable for {ticker}.

+
+ )} + {valState === "ready" && data && } + + ); +} -- cgit v1.3-2-g0d8e