diff --git a/app/components/StockTable.tsx b/app/components/StockTable.tsx index 7c71037..90ed748 100644 --- a/app/components/StockTable.tsx +++ b/app/components/StockTable.tsx @@ -1,4 +1,4 @@ -import React, { useState, useMemo } from "react"; +import { useState, useMemo, type ReactNode } from "react"; interface Stock { id: string; @@ -45,6 +45,7 @@ export default function StockTable({ stocks, onNotesSave, saveError }: StockTabl const paged = filtered.slice(page * pageSize, (page + 1) * pageSize); const handleSort = (field: SortField) => { + setPage(0); if (sortField === field) { setSortDirection((d) => (d === "asc" ? "desc" : "asc")); } else { @@ -63,15 +64,15 @@ export default function StockTable({ stocks, onNotesSave, saveError }: StockTabl setSavingNotes(editingTicker); try { await onNotesSave(editingTicker, editingNotes); + setEditingTicker(null); } catch (e) { console.error("Failed to save notes:", e); } finally { setSavingNotes(null); - setEditingTicker(null); } }; - const SortHeader = ({ field, children }: { field: SortField; children: React.ReactNode }) => ( + const SortHeader = ({ field, children }: { field: SortField; children: ReactNode }) => ( handleSort(field)} @@ -83,23 +84,12 @@ export default function StockTable({ stocks, onNotesSave, saveError }: StockTabl if (stocks.length === 0) { return ( -
-
-

Stock Database

-

Manage tracked stocks and their analysis notes.

-
-

No stocks tracked yet. Visit the stocks page to add some.

-
+

No stocks tracked yet. Visit the stocks page to add some.

); } return (
-
-

Stock Database

-

Manage tracked stocks and their analysis notes.

-
- {saveError && (
{saveError}
)} @@ -129,20 +119,28 @@ export default function StockTable({ stocks, onNotesSave, saveError }: StockTabl {paged.map((stock) => ( - + {stock.ticker} - {editingTicker === stock.ticker ? ( - setEditingNotes(e.target.value)} - onBlur={saveNotes} - onKeyDown={(e) => { if (e.key === "Enter") saveNotes(); if (e.key === "Escape") setEditingTicker(null); }} - className="w-full border border-blue-300 rounded px-2 py-1 text-sm focus:ring-2 focus:ring-blue-500" - autoFocus - /> - ) : ( + {editingTicker === stock.ticker ? ( +
+ setEditingNotes(e.target.value)} + onKeyDown={(e) => { if (e.key === "Enter") saveNotes(); if (e.key === "Escape") setEditingTicker(null); }} + className="flex-1 border border-blue-300 rounded px-2 py-1 text-sm focus:ring-2 focus:ring-blue-500" + autoFocus + /> + +
+ ) : ( startEditing(stock)}