From 96e26340538b4bbb18ecb9962fb2ac4faf5dd80b Mon Sep 17 00:00:00 2001 From: Yunxiao Xu Date: Tue, 17 Feb 2026 01:53:25 -0800 Subject: [PATCH] fix: Address code review findings (backend validation, hydration efficiency, plot readability) --- backend/src/ea_chatbot/api/routers/agent.py | 2 +- backend/src/ea_chatbot/api/schemas.py | 6 +++--- backend/src/ea_chatbot/app.py | 2 +- frontend/src/App.tsx | 6 +++--- frontend/src/components/theme-provider.tsx | 7 ++++++- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/backend/src/ea_chatbot/api/routers/agent.py b/backend/src/ea_chatbot/api/routers/agent.py index 320573e..349dc6b 100644 --- a/backend/src/ea_chatbot/api/routers/agent.py +++ b/backend/src/ea_chatbot/api/routers/agent.py @@ -91,7 +91,7 @@ async def stream_agent_events( encoded_plots: list[str] = [] for fig in plots: buf = io.BytesIO() - fig.savefig(buf, format="png", transparent=True) + fig.savefig(buf, format="png") plot_bytes = buf.getvalue() assistant_plots.append(plot_bytes) encoded_plots.append(base64.b64encode(plot_bytes).decode('utf-8')) diff --git a/backend/src/ea_chatbot/api/schemas.py b/backend/src/ea_chatbot/api/schemas.py index 619a529..9acddb8 100644 --- a/backend/src/ea_chatbot/api/schemas.py +++ b/backend/src/ea_chatbot/api/schemas.py @@ -1,5 +1,5 @@ from pydantic import BaseModel, EmailStr -from typing import List, Optional +from typing import List, Optional, Literal from datetime import datetime # --- Auth Schemas --- @@ -17,10 +17,10 @@ class UserResponse(BaseModel): id: str email: str display_name: str - theme_preference: str + theme_preference: Literal["light", "dark"] class ThemeUpdate(BaseModel): - theme: str + theme: Literal["light", "dark"] # --- History Schemas --- diff --git a/backend/src/ea_chatbot/app.py b/backend/src/ea_chatbot/app.py index 1f45d52..9585868 100644 --- a/backend/src/ea_chatbot/app.py +++ b/backend/src/ea_chatbot/app.py @@ -420,7 +420,7 @@ def main(): st.pyplot(fig) # Convert fig to bytes buf = io.BytesIO() - fig.savefig(buf, format="png", transparent=True) + fig.savefig(buf, format="png") plot_bytes_list.append(buf.getvalue()) if final_state.get("dfs"): diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 6c14c27..c34bdcc 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -12,7 +12,7 @@ import { Button } from "./components/ui/button" import { useTheme } from "./components/theme-provider" function App() { - const { setTheme } = useTheme() + const { setThemeLocal } = useTheme() const [isAuthenticated, setIsAuthenticated] = useState(false) const [user, setUser] = useState(null) const [authMode, setAuthMode] = useState<"login" | "register">("login") @@ -37,7 +37,7 @@ function App() { setUser(userData) setIsAuthenticated(true) if (userData.theme_preference) { - setTheme(userData.theme_preference as "light" | "dark") + setThemeLocal(userData.theme_preference as "light" | "dark") } // Load history after successful auth loadHistory() @@ -67,7 +67,7 @@ function App() { setUser(userData) setIsAuthenticated(true) if (userData.theme_preference) { - setTheme(userData.theme_preference as "light" | "dark") + setThemeLocal(userData.theme_preference as "light" | "dark") } loadHistory() } catch (err: unknown) { diff --git a/frontend/src/components/theme-provider.tsx b/frontend/src/components/theme-provider.tsx index 37ad2a7..5b8fcce 100644 --- a/frontend/src/components/theme-provider.tsx +++ b/frontend/src/components/theme-provider.tsx @@ -6,6 +6,7 @@ type Theme = "light" | "dark" interface ThemeContextType { theme: Theme setTheme: (theme: Theme) => void + setThemeLocal: (theme: Theme) => void toggleTheme: () => void } @@ -35,12 +36,16 @@ export function ThemeProvider({ } } + const setThemeLocal = (newTheme: Theme) => { + setThemeState(newTheme) + } + const toggleTheme = () => { setTheme(theme === "light" ? "dark" : "light") } return ( - + {children} )