diff --git a/frontend/components/dashboard/ScanTerminalDashboard.tsx b/frontend/components/dashboard/ScanTerminalDashboard.tsx index 64a47bd9..a18d446d 100644 --- a/frontend/components/dashboard/ScanTerminalDashboard.tsx +++ b/frontend/components/dashboard/ScanTerminalDashboard.tsx @@ -6,6 +6,8 @@ import { Activity, BarChart3, Bell, + ChevronDown, + ChevronRight, CloudSun, CreditCard, Gauge, @@ -18,7 +20,7 @@ import { Table2, UserRound, } from "lucide-react"; -import { useEffect, useMemo, useState } from "react"; +import { Fragment, useEffect, useMemo, useState } from "react"; import { Area, AreaChart, @@ -34,6 +36,19 @@ import type { ProAccessState, ScanOpportunityRow } from "@/lib/dashboard-types"; import { getInitialLocaleFromNavigator } from "@/lib/i18n"; import { isBrowserLocalFullAccess } from "@/lib/local-dev-access"; import { sortRowsByUserTime } from "@/components/dashboard/scan-terminal/decision-utils"; +import { + type ContinentGroup, + buildContinentGroups, + formatPrice, + formatSpreadLiquidity, + GAP_COLOR_MAP, + getDefaultExpanded, + getGapColor, + getSignalLabel, + getSignalState, +} from "@/components/dashboard/scan-terminal/continent-grouping"; +import { MobileCityCard } from "@/components/dashboard/scan-terminal/MobileCityCard"; +import { MobileRegionTabs } from "@/components/dashboard/scan-terminal/MobileRegionTabs"; import { useScanTerminalQuery } from "@/components/dashboard/scan-terminal/use-scan-terminal-query"; import { useScanTerminalTheme, @@ -306,80 +321,134 @@ function Panel({ ); } -function MarketTable({ +function GroupedMarketTable({ + groups, + isEn, onSelect, - rows, selectedId, - isEn = true, }: { + groups: ContinentGroup[]; + isEn: boolean; onSelect: (row: ScanOpportunityRow) => void; - rows: ScanOpportunityRow[]; selectedId?: string | null; - isEn?: boolean; }) { + const [collapsed, setCollapsed] = useState>(() => { + const c = new Set(); + const defaultExpanded = getDefaultExpanded(groups); + for (const g of groups) { + if (!defaultExpanded.has(g.key)) c.add(g.key); + } + return c; + }); + + const toggleGroup = (key: string) => { + setCollapsed((prev) => { + const next = new Set(prev); + if (next.has(key)) next.delete(key); + else next.add(key); + return next; + }); + }; + return (
- +
- - - - - - - + + + + + + + + + - {rows.map((row) => { - const label = decisionLabel(row); + {groups.map((group) => { + const isExpanded = !collapsed.has(group.key); + const label = isEn ? group.labelEn : group.labelZh; return ( - onSelect(row)} - > - - - - - - - - + + {/* Group header row */} + + + + {/* Data rows */} + {isExpanded && + group.rows.map((row) => { + const signal = getSignalState(row); + const gapColor = GAP_COLOR_MAP[getGapColor(row)]; + return ( + onSelect(row)} + > + + + + + + + + + + + ); + })} + ); })} @@ -411,14 +480,27 @@ function KoyfinWeatherTerminal({ toggleLocale: () => void; userLocalTime: string; }) { - const topRows = rows.slice(0, 18); const approveRows = rows .filter((row) => ["Approve", "Tradable"].includes(decisionLabel(row))) .slice(0, 8); const watchRows = rows .filter((row) => decisionLabel(row) === "Watch" || !row.tradable) .slice(0, 8); - const selectedLabel = decisionLabel(selectedRow); + const selectedLabel = selectedRow ? getSignalLabel(getSignalState(selectedRow), isEn) : ""; + const continentGroups = useMemo( + () => buildContinentGroups(rows, isEn), + [rows, isEn] + ); + const [mobileTab, setMobileTab] = useState("active_signals"); + const mobileActiveGroup = useMemo( + () => continentGroups.find((g) => g.key === mobileTab) || continentGroups[0], + [continentGroups, mobileTab] + ); + useEffect(() => { + if (continentGroups.length > 0 && !continentGroups.find((g) => g.key === mobileTab)) { + setMobileTab(continentGroups[0].key); + } + }, [continentGroups, mobileTab]); const avgEdge = rows.reduce((sum, row) => sum + Number(row.edge_percent || 0), 0) / Math.max(rows.length, 1); @@ -522,7 +604,49 @@ function KoyfinWeatherTerminal({
-
+ {/* Mobile layout */} +
+ +
+ {mobileActiveGroup?.rows.map((row) => ( + + ))} +
+ {/* Mobile Selected Row Detail */} + {selectedRow && ( +
+

{rowName(selectedRow)}

+
+ {[ + ["Obs", temp(selectedRow.current_temp, selectedRow.temp_symbol)], + ["High", temp(selectedRow.current_max_so_far, selectedRow.temp_symbol)], + ["DEB", temp(selectedRow.deb_prediction, selectedRow.temp_symbol)], + ["Gap", temp(selectedRow.signed_gap ?? selectedRow.gap_to_target, selectedRow.temp_symbol)], + ["Edge", pct(selectedRow.edge_percent)], + ["Market", formatPrice(selectedRow.midpoint, selectedRow.ask, selectedRow.bid)], + ].map(([label, value]) => ( +
+
{label}
+
{value}
+
+ ))} +
+
+ )} +
+ + {/* Desktop layout */} +
@@ -549,17 +673,17 @@ function KoyfinWeatherTerminal({
-
- {(approveRows.length ? approveRows : topRows.slice(0, 5)).map((row) => ( + {(approveRows.length ? approveRows : rows.slice(0, 5)).map((row) => (
@@ -679,7 +803,7 @@ function KoyfinWeatherTerminal({
- {(watchRows.length ? watchRows : topRows.slice(0, 8)).map((row) => ( + {(watchRows.length ? watchRows : rows.slice(0, 8)).map((row) => (
{t("cityContract", isEn)}{t("live", isEn)}{t("deb", isEn)}{t("mkt", isEn)}{t("edge", isEn)}{t("liq", isEn)}{t("signal", isEn)}CityObsHighDEBGapMarketEdgeSpr/LiqSignal
-
{rowName(row)}
-
- {row.target_label || row.market_question || row.airport || "--"} -
-
- {temp(row.current_max_so_far ?? row.current_temp, row.temp_symbol)} - - {temp(row.deb_prediction, row.temp_symbol)} - - {pct(row.market_probability ?? row.market_event_probability)} - - {pct(row.edge_percent ?? row.signed_gap ?? row.gap)} - - {money(row.book_liquidity ?? row.market_liquidity ?? row.volume)} - - - {label} - -
+ +
+
{rowName(row)}
+
+ {row.airport || ""}{row.local_time ? ` · ${row.local_time}` : ""} +
+
+ {temp(row.current_temp, row.temp_symbol)} + + {temp(row.current_max_so_far, row.temp_symbol)} + + {temp(row.deb_prediction, row.temp_symbol)} + + {temp(row.signed_gap ?? row.gap_to_target, row.temp_symbol)} + + {formatPrice(row.midpoint, row.ask, row.bid)} + + {pct(row.edge_percent)} + + {formatSpreadLiquidity(row.spread, row.book_liquidity ?? row.market_liquidity)} + + + {getSignalLabel(signal, isEn)} + +