Add minimal stock listing app: actions, Postgres schema, stocks page, Claude Agent SDK harness

- Add stocks table (server/db) with list/get/add/update/delete actions, scoped
  per user, backing both the chat agent and the /stocks UI via
  useActionQuery/useActionMutation
- Add mobile-first /stocks page (shadcn table/cards, watchlist, search) and
  wire it into the sidebar, navigation state, and view-screen context
- Install the platform's Claude Agent SDK harness (server/plugins,
  server/routes/api/claude-agent) so the app agent runs on the platform's own
  Claude subscription instead of the Builder.io gateway; fix the vendored
  turn.post.ts route to resolve the session and wrap it in
  runWithRequestContext, since custom /api/ routes aren't auto-wrapped in
  request context the way /_agent-native/actions/* are
- Add shadcn table/badge/dialog/select components (Tabler icons, not lucide)
This commit is contained in:
exe.dev user
2026-07-29 12:18:14 +00:00
parent 138d195e4c
commit e859245867
25 changed files with 14804 additions and 10 deletions
+7
View File
@@ -14,6 +14,7 @@ import {
type ChatHistoryItem,
} from "@agent-native/toolkit/chat-history";
import {
IconChartLine,
IconLayoutSidebarLeftCollapse,
IconLayoutSidebarLeftExpand,
IconMessageCircle,
@@ -39,6 +40,12 @@ const navItems = [
href: "/",
view: "chat",
},
{
icon: IconChartLine,
labelKey: "navigation.stocks",
href: "/stocks",
view: "stocks",
},
];
const bottomNavItems = [
+36
View File
@@ -0,0 +1,36 @@
import * as React from "react"
import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "@/lib/utils"
const badgeVariants = cva(
"inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
{
variants: {
variant: {
default:
"border-transparent bg-primary text-primary-foreground hover:bg-primary/80",
secondary:
"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",
destructive:
"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",
outline: "text-foreground",
},
},
defaultVariants: {
variant: "default",
},
}
)
export interface BadgeProps
extends React.HTMLAttributes<HTMLDivElement>,
VariantProps<typeof badgeVariants> {}
function Badge({ className, variant, ...props }: BadgeProps) {
return (
<div className={cn(badgeVariants({ variant }), className)} {...props} />
)
}
export { Badge, badgeVariants }
+120
View File
@@ -0,0 +1,120 @@
import * as React from "react"
import * as DialogPrimitive from "@radix-ui/react-dialog"
import { IconX } from "@tabler/icons-react"
import { cn } from "@/lib/utils"
const Dialog = DialogPrimitive.Root
const DialogTrigger = DialogPrimitive.Trigger
const DialogPortal = DialogPrimitive.Portal
const DialogClose = DialogPrimitive.Close
const DialogOverlay = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Overlay
ref={ref}
className={cn(
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
className
)}
{...props}
/>
))
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName
const DialogContent = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>
>(({ className, children, ...props }, ref) => (
<DialogPortal>
<DialogOverlay />
<DialogPrimitive.Content
ref={ref}
className={cn(
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
className
)}
{...props}
>
{children}
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
<IconX className="h-4 w-4" />
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
</DialogPrimitive.Content>
</DialogPortal>
))
DialogContent.displayName = DialogPrimitive.Content.displayName
const DialogHeader = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col space-y-1.5 text-center sm:text-left",
className
)}
{...props}
/>
)
DialogHeader.displayName = "DialogHeader"
const DialogFooter = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
className
)}
{...props}
/>
)
DialogFooter.displayName = "DialogFooter"
const DialogTitle = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Title
ref={ref}
className={cn(
"text-lg font-semibold leading-none tracking-tight",
className
)}
{...props}
/>
))
DialogTitle.displayName = DialogPrimitive.Title.displayName
const DialogDescription = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>
>(({ className, ...props }, ref) => (
<DialogPrimitive.Description
ref={ref}
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
))
DialogDescription.displayName = DialogPrimitive.Description.displayName
export {
Dialog,
DialogPortal,
DialogOverlay,
DialogClose,
DialogTrigger,
DialogContent,
DialogHeader,
DialogFooter,
DialogTitle,
DialogDescription,
}
+160
View File
@@ -0,0 +1,160 @@
"use client"
import * as React from "react"
import * as SelectPrimitive from "@radix-ui/react-select"
import { IconCheck, IconChevronDown, IconChevronUp } from "@tabler/icons-react"
import { cn } from "@/lib/utils"
const Select = SelectPrimitive.Root
const SelectGroup = SelectPrimitive.Group
const SelectValue = SelectPrimitive.Value
const SelectTrigger = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Trigger>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>
>(({ className, children, ...props }, ref) => (
<SelectPrimitive.Trigger
ref={ref}
className={cn(
"flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background data-[placeholder]:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",
className
)}
{...props}
>
{children}
<SelectPrimitive.Icon asChild>
<IconChevronDown className="h-4 w-4 opacity-50" />
</SelectPrimitive.Icon>
</SelectPrimitive.Trigger>
))
SelectTrigger.displayName = SelectPrimitive.Trigger.displayName
const SelectScrollUpButton = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.ScrollUpButton>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollUpButton>
>(({ className, ...props }, ref) => (
<SelectPrimitive.ScrollUpButton
ref={ref}
className={cn(
"flex cursor-default items-center justify-center py-1",
className
)}
{...props}
>
<IconChevronUp className="h-4 w-4" />
</SelectPrimitive.ScrollUpButton>
))
SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName
const SelectScrollDownButton = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.ScrollDownButton>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollDownButton>
>(({ className, ...props }, ref) => (
<SelectPrimitive.ScrollDownButton
ref={ref}
className={cn(
"flex cursor-default items-center justify-center py-1",
className
)}
{...props}
>
<IconChevronDown className="h-4 w-4" />
</SelectPrimitive.ScrollDownButton>
))
SelectScrollDownButton.displayName =
SelectPrimitive.ScrollDownButton.displayName
const SelectContent = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>
>(({ className, children, position = "popper", ...props }, ref) => (
<SelectPrimitive.Portal>
<SelectPrimitive.Content
ref={ref}
className={cn(
"relative z-50 max-h-[--radix-select-content-available-height] min-w-[8rem] overflow-y-auto overflow-x-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-select-content-transform-origin]",
position === "popper" &&
"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
className
)}
position={position}
{...props}
>
<SelectScrollUpButton />
<SelectPrimitive.Viewport
className={cn(
"p-1",
position === "popper" &&
"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"
)}
>
{children}
</SelectPrimitive.Viewport>
<SelectScrollDownButton />
</SelectPrimitive.Content>
</SelectPrimitive.Portal>
))
SelectContent.displayName = SelectPrimitive.Content.displayName
const SelectLabel = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Label>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Label>
>(({ className, ...props }, ref) => (
<SelectPrimitive.Label
ref={ref}
className={cn("py-1.5 pl-8 pr-2 text-sm font-semibold", className)}
{...props}
/>
))
SelectLabel.displayName = SelectPrimitive.Label.displayName
const SelectItem = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Item>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Item>
>(({ className, children, ...props }, ref) => (
<SelectPrimitive.Item
ref={ref}
className={cn(
"relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
className
)}
{...props}
>
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
<SelectPrimitive.ItemIndicator>
<IconCheck className="h-4 w-4" />
</SelectPrimitive.ItemIndicator>
</span>
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
</SelectPrimitive.Item>
))
SelectItem.displayName = SelectPrimitive.Item.displayName
const SelectSeparator = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Separator>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Separator>
>(({ className, ...props }, ref) => (
<SelectPrimitive.Separator
ref={ref}
className={cn("-mx-1 my-1 h-px bg-muted", className)}
{...props}
/>
))
SelectSeparator.displayName = SelectPrimitive.Separator.displayName
export {
Select,
SelectGroup,
SelectValue,
SelectTrigger,
SelectContent,
SelectLabel,
SelectItem,
SelectSeparator,
SelectScrollUpButton,
SelectScrollDownButton,
}
+117
View File
@@ -0,0 +1,117 @@
import * as React from "react"
import { cn } from "@/lib/utils"
const Table = React.forwardRef<
HTMLTableElement,
React.HTMLAttributes<HTMLTableElement>
>(({ className, ...props }, ref) => (
<div className="relative w-full overflow-auto">
<table
ref={ref}
className={cn("w-full caption-bottom text-sm", className)}
{...props}
/>
</div>
))
Table.displayName = "Table"
const TableHeader = React.forwardRef<
HTMLTableSectionElement,
React.HTMLAttributes<HTMLTableSectionElement>
>(({ className, ...props }, ref) => (
<thead ref={ref} className={cn("[&_tr]:border-b", className)} {...props} />
))
TableHeader.displayName = "TableHeader"
const TableBody = React.forwardRef<
HTMLTableSectionElement,
React.HTMLAttributes<HTMLTableSectionElement>
>(({ className, ...props }, ref) => (
<tbody
ref={ref}
className={cn("[&_tr:last-child]:border-0", className)}
{...props}
/>
))
TableBody.displayName = "TableBody"
const TableFooter = React.forwardRef<
HTMLTableSectionElement,
React.HTMLAttributes<HTMLTableSectionElement>
>(({ className, ...props }, ref) => (
<tfoot
ref={ref}
className={cn(
"border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",
className
)}
{...props}
/>
))
TableFooter.displayName = "TableFooter"
const TableRow = React.forwardRef<
HTMLTableRowElement,
React.HTMLAttributes<HTMLTableRowElement>
>(({ className, ...props }, ref) => (
<tr
ref={ref}
className={cn(
"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",
className
)}
{...props}
/>
))
TableRow.displayName = "TableRow"
const TableHead = React.forwardRef<
HTMLTableCellElement,
React.ThHTMLAttributes<HTMLTableCellElement>
>(({ className, ...props }, ref) => (
<th
ref={ref}
className={cn(
"h-12 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",
className
)}
{...props}
/>
))
TableHead.displayName = "TableHead"
const TableCell = React.forwardRef<
HTMLTableCellElement,
React.TdHTMLAttributes<HTMLTableCellElement>
>(({ className, ...props }, ref) => (
<td
ref={ref}
className={cn("p-4 align-middle [&:has([role=checkbox])]:pr-0", className)}
{...props}
/>
))
TableCell.displayName = "TableCell"
const TableCaption = React.forwardRef<
HTMLTableCaptionElement,
React.HTMLAttributes<HTMLTableCaptionElement>
>(({ className, ...props }, ref) => (
<caption
ref={ref}
className={cn("mt-4 text-sm text-muted-foreground", className)}
{...props}
/>
))
TableCaption.displayName = "TableCaption"
export {
Table,
TableHeader,
TableBody,
TableFooter,
TableHead,
TableRow,
TableCell,
TableCaption,
}
+3
View File
@@ -39,6 +39,7 @@ function threadIdFromPath(pathname: string): string | null {
function viewForPath(pathname: string): string {
if (isChatPath(pathname)) return "chat";
if (pathname.startsWith("/stocks")) return "stocks";
if (pathname.startsWith("/database")) return "database";
if (pathname.startsWith("/extensions")) return "extensions";
if (pathname.startsWith("/observability")) return "observability";
@@ -53,6 +54,8 @@ function pathForView(view?: string): string {
case "home":
case "ask":
return "/";
case "stocks":
return "/stocks";
case "database":
return "/database";
case "extensions":
+2
View File
@@ -50,11 +50,13 @@ const messages = {
observability: "Observability",
openNavigation: "Open navigation",
settings: "Settings",
stocks: "Stocks",
team: "Team",
},
pages: {
databaseTitle: "Database",
observabilityPageTitle: "Agent Observability",
stocksDescription: "Track tickers, prices, and your watchlist.",
teamTitle: "Team",
teamCreateOrgDescription:
"Create an organization to invite teammates and share this app.",
+414
View File
@@ -0,0 +1,414 @@
import {
useActionMutation,
useActionQuery,
} from "@agent-native/core/client/hooks";
import { useT } from "@agent-native/core/client/i18n";
import { useSetPageTitle } from "@agent-native/toolkit/app-shell";
import { IconPlus, IconStar, IconStarFilled, IconTrash } from "@tabler/icons-react";
import { useMemo, useState } from "react";
import { toast } from "sonner";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Card, CardContent } from "@/components/ui/card";
import {
Dialog,
DialogContent,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
import { APP_TITLE } from "@/lib/app-config";
import { cn } from "@/lib/utils";
export function meta() {
return [{ title: `Stocks - ${APP_TITLE}` }];
}
interface StockFormState {
symbol: string;
companyName: string;
exchange: string;
sector: string;
currency: string;
price: string;
changePercent: string;
marketCap: string;
}
const EMPTY_FORM: StockFormState = {
symbol: "",
companyName: "",
exchange: "NASDAQ",
sector: "",
currency: "USD",
price: "",
changePercent: "",
marketCap: "",
};
function formatMoney(value: number, currency: string) {
try {
return new Intl.NumberFormat(undefined, {
style: "currency",
currency,
maximumFractionDigits: 2,
}).format(value);
} catch {
return `${value.toFixed(2)} ${currency}`;
}
}
function formatMarketCap(value: number | null) {
if (value === null || value === undefined) return "—";
if (value >= 1_000_000_000_000) return `${(value / 1_000_000_000_000).toFixed(2)}T`;
if (value >= 1_000_000_000) return `${(value / 1_000_000_000).toFixed(2)}B`;
if (value >= 1_000_000) return `${(value / 1_000_000).toFixed(2)}M`;
return String(value);
}
function AddStockDialog() {
const [open, setOpen] = useState(false);
const [form, setForm] = useState<StockFormState>(EMPTY_FORM);
const addStock = useActionMutation("add-stock", {
onSuccess: () => {
toast.success(`${form.symbol.toUpperCase()} added`);
setForm(EMPTY_FORM);
setOpen(false);
},
onError: (error) => toast.error(error.message),
});
function submit() {
if (!form.symbol.trim() || !form.companyName.trim()) {
toast.error("Symbol and company name are required.");
return;
}
addStock.mutate({
symbol: form.symbol.trim(),
companyName: form.companyName.trim(),
exchange: form.exchange.trim() || "NASDAQ",
sector: form.sector.trim() || undefined,
currency: form.currency.trim() || "USD",
price: form.price ? Number(form.price) : 0,
changePercent: form.changePercent ? Number(form.changePercent) : 0,
marketCap: form.marketCap ? Number(form.marketCap) : undefined,
});
}
return (
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
<Button size="sm" className="gap-1.5">
<IconPlus className="size-4" />
Add stock
</Button>
</DialogTrigger>
<DialogContent className="sm:max-w-md">
<DialogHeader>
<DialogTitle>Add stock</DialogTitle>
</DialogHeader>
<div className="grid grid-cols-2 gap-3">
<div className="col-span-2 space-y-1.5">
<Label htmlFor="symbol">Symbol</Label>
<Input
id="symbol"
placeholder="AAPL"
value={form.symbol}
onChange={(e) => setForm({ ...form, symbol: e.target.value })}
/>
</div>
<div className="col-span-2 space-y-1.5">
<Label htmlFor="companyName">Company name</Label>
<Input
id="companyName"
placeholder="Apple Inc."
value={form.companyName}
onChange={(e) => setForm({ ...form, companyName: e.target.value })}
/>
</div>
<div className="space-y-1.5">
<Label htmlFor="exchange">Exchange</Label>
<Input
id="exchange"
value={form.exchange}
onChange={(e) => setForm({ ...form, exchange: e.target.value })}
/>
</div>
<div className="space-y-1.5">
<Label htmlFor="sector">Sector</Label>
<Input
id="sector"
placeholder="Technology"
value={form.sector}
onChange={(e) => setForm({ ...form, sector: e.target.value })}
/>
</div>
<div className="space-y-1.5">
<Label htmlFor="price">Price</Label>
<Input
id="price"
type="number"
inputMode="decimal"
value={form.price}
onChange={(e) => setForm({ ...form, price: e.target.value })}
/>
</div>
<div className="space-y-1.5">
<Label htmlFor="changePercent">Change %</Label>
<Input
id="changePercent"
type="number"
inputMode="decimal"
value={form.changePercent}
onChange={(e) =>
setForm({ ...form, changePercent: e.target.value })
}
/>
</div>
<div className="space-y-1.5">
<Label htmlFor="currency">Currency</Label>
<Input
id="currency"
value={form.currency}
onChange={(e) => setForm({ ...form, currency: e.target.value })}
/>
</div>
<div className="space-y-1.5">
<Label htmlFor="marketCap">Market cap</Label>
<Input
id="marketCap"
type="number"
inputMode="decimal"
value={form.marketCap}
onChange={(e) => setForm({ ...form, marketCap: e.target.value })}
/>
</div>
</div>
<DialogFooter>
<Button onClick={submit} disabled={addStock.isPending}>
{addStock.isPending ? "Adding…" : "Add stock"}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
);
}
interface StockRow {
id: string;
symbol: string;
companyName: string;
exchange: string;
sector: string | null;
currency: string;
price: number;
changePercent: number;
marketCap: number | null;
watchlisted: boolean;
}
function ChangeBadge({ value }: { value: number }) {
const positive = value > 0;
const negative = value < 0;
return (
<Badge
variant="outline"
className={cn(
"font-mono tabular-nums",
positive && "border-emerald-500/40 text-emerald-600 dark:text-emerald-400",
negative && "border-red-500/40 text-red-600 dark:text-red-400",
)}
>
{positive ? "+" : ""}
{value.toFixed(2)}%
</Badge>
);
}
function WatchlistButton({ stock }: { stock: StockRow }) {
const toggle = useActionMutation("update-stock", {
method: "PUT",
onError: (error) => toast.error(error.message),
});
return (
<Button
variant="ghost"
size="icon"
className="size-8"
aria-label={stock.watchlisted ? "Remove from watchlist" : "Add to watchlist"}
disabled={toggle.isPending}
onClick={() =>
toggle.mutate({
id: stock.id,
watchlisted: stock.watchlisted ? "false" : "true",
})
}
>
{stock.watchlisted ? (
<IconStarFilled className="size-4 text-amber-500" />
) : (
<IconStar className="size-4 text-muted-foreground" />
)}
</Button>
);
}
function DeleteStockButton({ stock }: { stock: StockRow }) {
const del = useActionMutation("delete-stock", {
method: "DELETE",
onSuccess: () => toast.success(`${stock.symbol} removed`),
onError: (error) => toast.error(error.message),
});
return (
<Button
variant="ghost"
size="icon"
className="size-8 text-muted-foreground hover:text-destructive"
aria-label={`Delete ${stock.symbol}`}
disabled={del.isPending}
onClick={() => {
if (window.confirm(`Remove ${stock.symbol} from your listings?`)) {
del.mutate({ id: stock.id });
}
}}
>
<IconTrash className="size-4" />
</Button>
);
}
export default function StocksRoute() {
const t = useT();
useSetPageTitle(t("navigation.stocks"));
const [search, setSearch] = useState("");
const { data, isLoading } = useActionQuery("list-stocks", {
search: search || undefined,
});
const stocks = useMemo(() => (data?.stocks ?? []) as StockRow[], [data]);
return (
<div className="mx-auto flex w-full max-w-4xl flex-col gap-4 p-4 sm:p-6">
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
<div>
<h1 className="text-lg font-semibold tracking-tight">
{t("navigation.stocks")}
</h1>
<p className="text-sm text-muted-foreground">
{t("pages.stocksDescription")}
</p>
</div>
<AddStockDialog />
</div>
<Input
placeholder="Search symbol or company…"
value={search}
onChange={(e) => setSearch(e.target.value)}
className="sm:max-w-xs"
/>
{isLoading ? (
<p className="py-8 text-center text-sm text-muted-foreground">Loading</p>
) : stocks.length === 0 ? (
<Card>
<CardContent className="py-10 text-center text-sm text-muted-foreground">
No stocks listed yet. Add one, or ask the agent to add some.
</CardContent>
</Card>
) : (
<>
{/* Mobile: stacked cards */}
<div className="flex flex-col gap-2 sm:hidden">
{stocks.map((stock) => (
<Card key={stock.id}>
<CardContent className="flex items-center gap-3 py-3">
<div className="min-w-0 flex-1">
<div className="flex items-center gap-2">
<span className="font-semibold">{stock.symbol}</span>
<span className="truncate text-xs text-muted-foreground">
{stock.exchange}
</span>
</div>
<p className="truncate text-sm text-muted-foreground">
{stock.companyName}
</p>
<div className="mt-1 flex items-center gap-2">
<span className="font-mono text-sm tabular-nums">
{formatMoney(stock.price, stock.currency)}
</span>
<ChangeBadge value={stock.changePercent} />
</div>
</div>
<WatchlistButton stock={stock} />
<DeleteStockButton stock={stock} />
</CardContent>
</Card>
))}
</div>
{/* Desktop: table */}
<div className="hidden overflow-x-auto rounded-md border sm:block">
<Table>
<TableHeader>
<TableRow>
<TableHead className="w-8" />
<TableHead>Symbol</TableHead>
<TableHead>Company</TableHead>
<TableHead>Exchange</TableHead>
<TableHead>Sector</TableHead>
<TableHead className="text-right">Price</TableHead>
<TableHead className="text-right">Change</TableHead>
<TableHead className="text-right">Market Cap</TableHead>
<TableHead className="w-8" />
</TableRow>
</TableHeader>
<TableBody>
{stocks.map((stock) => (
<TableRow key={stock.id}>
<TableCell>
<WatchlistButton stock={stock} />
</TableCell>
<TableCell className="font-semibold">{stock.symbol}</TableCell>
<TableCell className="max-w-52 truncate text-muted-foreground">
{stock.companyName}
</TableCell>
<TableCell className="text-muted-foreground">
{stock.exchange}
</TableCell>
<TableCell className="text-muted-foreground">
{stock.sector ?? "—"}
</TableCell>
<TableCell className="text-right font-mono tabular-nums">
{formatMoney(stock.price, stock.currency)}
</TableCell>
<TableCell className="text-right">
<ChangeBadge value={stock.changePercent} />
</TableCell>
<TableCell className="text-right text-muted-foreground">
{formatMarketCap(stock.marketCap)}
</TableCell>
<TableCell>
<DeleteStockButton stock={stock} />
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</div>
</>
)}
</div>
);
}