fix: improve settings page error handling, race condition, and metadata

This commit is contained in:
2026-05-16 21:21:35 +02:00
parent 07c7182ed6
commit 1f7c07b427
+6 -4
View File
@@ -1,4 +1,4 @@
import React, { useEffect, useState } from "react";
import { useEffect, useState } from "react";
import Navbar from "../components/Navbar";
import SettingsSidebar, { type SettingsSection } from "../components/SettingsSidebar";
import LlmSettings from "../components/LlmSettings";
@@ -6,6 +6,8 @@ import TradingSettings from "../components/TradingSettings";
import StockTable from "../components/StockTable";
import SystemSettings from "../components/SystemSettings";
export const meta = () => [{ title: "Settings - AITrader" }];
interface Stock {
id: string;
ticker: string;
@@ -69,7 +71,7 @@ export default function SettingsPage() {
const saveStockNotes = async (ticker: string, notes: string) => {
setSaveError(null);
const prevStocks = [...stocks];
const prevNotes = stocks.find((st) => st.ticker === ticker)?.notes ?? null;
setStocks((s) => s.map((st) => (st.ticker === ticker ? { ...st, notes } : st)));
try {
const fd = new FormData();
@@ -80,7 +82,7 @@ export default function SettingsPage() {
throw new Error("Failed to save notes");
}
} catch (err) {
setStocks(prevStocks);
setStocks((s) => s.map((st) => (st.ticker === ticker ? { ...st, notes: prevNotes } : st)));
setSaveError(err instanceof Error ? err.message : "Save failed");
}
};
@@ -117,7 +119,7 @@ export default function SettingsPage() {
<div className="mx-auto max-w-7xl px-6 sm:px-8 lg:px-8 py-8">
<div className="bg-white rounded-xl shadow-lg border border-gray-200 overflow-hidden">
<div className="flex min-h-[600px]">
<SettingsSidebar activeSection={activeSection} onSectionChange={setActiveSection} />
<SettingsSidebar activeSection={activeSection} onSectionChange={(s) => { setActiveSection(s); setSaveError(null); }} />
<main className="flex-1 p-6 overflow-y-auto">
{renderSection()}
</main>