From 566f59cb00958caa073279a7bb698e1ede48c0d4 Mon Sep 17 00:00:00 2001 From: Tyler Hoang Date: Mon, 18 May 2026 22:15:42 -0700 Subject: feat: add RatiosPage data-fetch wrapper --- frontend/components/prism/RatiosPage.tsx | 57 ++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 frontend/components/prism/RatiosPage.tsx (limited to 'frontend') diff --git a/frontend/components/prism/RatiosPage.tsx b/frontend/components/prism/RatiosPage.tsx new file mode 100644 index 0000000..26868f8 --- /dev/null +++ b/frontend/components/prism/RatiosPage.tsx @@ -0,0 +1,57 @@ +"use client"; + +import { useEffect, useState } from "react"; +import { api } from "@/lib/api"; +import { RatiosCard } from "@/components/prism/RatiosCard"; +import type { RatiosResponse } from "@/types/api"; + +type RatiosState = "loading" | "ready" | "error"; + +type Props = { + ticker: string; +}; + +export function RatiosPage({ ticker }: Props) { + const [data, setData] = useState(null); + const [ratiosState, setRatiosState] = useState("loading"); + + useEffect(() => { + let cancelled = false; + setRatiosState("loading"); + setData(null); + + api + .ratios(ticker) + .then((res) => { + if (!cancelled) { + setData(res); + setRatiosState("ready"); + } + }) + .catch(() => { + if (!cancelled) setRatiosState("error"); + }); + + return () => { + cancelled = true; + }; + }, [ticker]); + + if (ratiosState === "loading") { + return
; + } + + if (ratiosState === "error") { + return ( +
+

Ratio data unavailable for {ticker}.

+
+ ); + } + + if (ratiosState === "ready" && data) { + return ; + } + + return null; +} -- cgit v1.3-2-g0d8e