11import BackButton from "@valuecell/button/back-button" ;
2- import { memo , useMemo } from "react" ;
2+ import { memo } from "react" ;
33import { useNavigate , useParams } from "react-router" ;
4- import {
5- useGetStockDetail ,
6- useGetStockPrice ,
7- useRemoveStockFromWatchlist ,
8- } from "@/api/stock" ;
4+ import { useGetStockDetail , useRemoveStockFromWatchlist } from "@/api/stock" ;
95import TradingViewAdvancedChart from "@/components/tradingview/tradingview-advanced-chart" ;
106import { Button } from "@/components/ui/button" ;
117import type { Route } from "./+types/stock" ;
@@ -16,15 +12,6 @@ function Stock() {
1612 // Use stockId as ticker to fetch real data from API
1713 const ticker = stockId || "" ;
1814
19- // Fetch current stock price data
20- const {
21- data : stockPriceData ,
22- isLoading : isPriceLoading ,
23- error : priceError ,
24- } = useGetStockPrice ( {
25- ticker,
26- } ) ;
27-
2815 // Fetch stock detail data
2916 const {
3017 data : stockDetailData ,
@@ -34,36 +21,20 @@ function Stock() {
3421 ticker,
3522 } ) ;
3623
37- const removeStockMutation = useRemoveStockFromWatchlist ( ) ;
24+ const { mutateAsync : removeStockMutation , isPending : isRemovingStock } =
25+ useRemoveStockFromWatchlist ( ) ;
3826
3927 const handleRemoveStock = async ( ) => {
4028 try {
41- await removeStockMutation . mutateAsync ( ticker ) ;
29+ await removeStockMutation ( ticker ) ;
4230 navigate ( - 1 ) ;
4331 } catch ( error ) {
4432 console . error ( "Failed to remove stock from watchlist:" , error ) ;
4533 }
4634 } ;
4735
48- // Create stock info from API data
49- const stockInfo = useMemo ( ( ) => {
50- if ( ! stockPriceData ) return null ;
51-
52- // Use display name from detail data if available, otherwise use ticker
53- const companyName = stockDetailData ?. display_name || ticker ;
54-
55- return {
56- symbol : ticker ,
57- companyName,
58- price : stockPriceData . price_formatted ,
59- changePercent : stockPriceData . change_percent ,
60- currency : stockPriceData . currency ,
61- changeAmount : stockPriceData . change ,
62- } ;
63- } , [ stockPriceData , stockDetailData , ticker ] ) ;
64-
6536 // Handle loading states
66- if ( isPriceLoading || isDetailLoading ) {
37+ if ( isDetailLoading ) {
6738 return (
6839 < div className = "flex h-96 items-center justify-center" >
6940 < div className = "text-gray-500 text-lg" > Loading stock data...</ div >
@@ -72,39 +43,31 @@ function Stock() {
7243 }
7344
7445 // Handle error states
75- if ( priceError || detailError ) {
46+ if ( detailError ) {
7647 return (
7748 < div className = "flex h-96 items-center justify-center" >
7849 < div className = "text-lg text-red-500" >
79- Error loading stock data:{ " " }
80- { priceError ?. message || detailError ?. message }
50+ Error loading stock data: { detailError ?. message }
8151 </ div >
8252 </ div >
8353 ) ;
8454 }
8555
86- // Handle no data found
87- if ( ! stockInfo || ! stockPriceData ) {
88- return (
89- < div className = "flex h-96 items-center justify-center" >
90- < div className = "text-gray-500 text-lg" > Stock { stockId } not found</ div >
91- </ div >
92- ) ;
93- }
94-
9556 return (
9657 < div className = "flex flex-col gap-8 bg-white px-8 py-6" >
9758 < div className = "flex flex-col gap-4" >
9859 < BackButton />
9960 < div className = "flex items-center gap-2" >
100- < span className = "font-bold text-lg" > { stockInfo . companyName } </ span >
61+ < span className = "font-bold text-lg" >
62+ { stockDetailData ?. display_name ?? ticker }
63+ </ span >
10164 < Button
10265 variant = "secondary"
10366 className = "ml-auto text-neutral-400"
10467 onClick = { handleRemoveStock }
105- disabled = { removeStockMutation . isPending }
68+ disabled = { isRemovingStock }
10669 >
107- { removeStockMutation . isPending ? "Removing..." : "Remove" }
70+ { isRemovingStock ? "Removing..." : "Remove" }
10871 </ Button >
10972 </ div >
11073 </ div >
0 commit comments