From 4d15d4b1926e22ff56d3c5983913a48584a60398 Mon Sep 17 00:00:00 2001 From: Sean Hatfield Date: Tue, 12 Nov 2024 10:23:30 -0800 Subject: [PATCH] Fix chat window scrollbar appearance option (#2589) * wip fix chat window scrollbar * fix chat/default chat window scrollbare option * lint * small lint and refactor --------- Co-authored-by: timothycarambat --- frontend/src/components/DefaultChat/index.jsx | 6 ++- .../ChatContainer/ChatHistory/index.jsx | 4 +- frontend/src/index.css | 44 +++++++++++++++++-- frontend/src/models/appearance.js | 9 +++- 4 files changed, 55 insertions(+), 8 deletions(-) diff --git a/frontend/src/components/DefaultChat/index.jsx b/frontend/src/components/DefaultChat/index.jsx index 4241ed71ea..d542f309fd 100644 --- a/frontend/src/components/DefaultChat/index.jsx +++ b/frontend/src/components/DefaultChat/index.jsx @@ -18,8 +18,10 @@ import { userFromStorage } from "@/utils/request"; import { AI_BACKGROUND_COLOR, USER_BACKGROUND_COLOR } from "@/utils/constants"; import useUser from "@/hooks/useUser"; import { useTranslation, Trans } from "react-i18next"; +import Appearance from "@/models/appearance"; export default function DefaultChatContainer() { + const { showScrollbar } = Appearance.getSettings(); const [mockMsgs, setMockMessages] = useState([]); const { user } = useUser(); const [fetchedMessages, setFetchedMessages] = useState([]); @@ -305,7 +307,9 @@ export default function DefaultChatContainer() { return (
{isMobile && } {fetchedMessages.length === 0 diff --git a/frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/index.jsx b/frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/index.jsx index 99f133889d..85e45d695f 100644 --- a/frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/index.jsx +++ b/frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/index.jsx @@ -28,8 +28,8 @@ export default function ChatHistory({ const chatHistoryRef = useRef(null); const [textSize, setTextSize] = useState("normal"); const [isUserScrolling, setIsUserScrolling] = useState(false); - const showScrollbar = Appearance.getSettings()?.showScrollbar || false; const isStreaming = history[history.length - 1]?.animate; + const { showScrollbar } = Appearance.getSettings(); const getTextSizeClass = (size) => { switch (size) { @@ -205,7 +205,7 @@ export default function ChatHistory({ return (
{ - const settings = localStorage.getItem(APPEARANCE_SETTINGS); - return settings ? JSON.parse(settings) : { showScrollbar: false }; + try { + const settings = localStorage.getItem(APPEARANCE_SETTINGS); + return settings ? JSON.parse(settings) : Appearance.defaultSettings; + } catch (e) { + return Appearance.defaultSettings; + } }, /**