From 190a4815361ad41d91630d9f4fe1aee6e1e683c3 Mon Sep 17 00:00:00 2001 From: Sean Hatfield Date: Thu, 21 Nov 2024 12:07:46 -0800 Subject: [PATCH] Adjustable font size in chat input (#2692) * adjustable prompt input text sizing * dev build --------- Co-authored-by: timothycarambat --- .github/workflows/dev-build.yaml | 2 +- .../ChatContainer/ChatHistory/index.jsx | 34 ++--------------- .../ChatContainer/PromptInput/index.jsx | 4 +- frontend/src/hooks/useTextSize.js | 38 +++++++++++++++++++ 4 files changed, 45 insertions(+), 33 deletions(-) create mode 100644 frontend/src/hooks/useTextSize.js diff --git a/.github/workflows/dev-build.yaml b/.github/workflows/dev-build.yaml index ce6f6f9d30..85886fdb51 100644 --- a/.github/workflows/dev-build.yaml +++ b/.github/workflows/dev-build.yaml @@ -6,7 +6,7 @@ concurrency: on: push: - branches: ['light-mode-1'] # put your current branch to create a build. Core team only. + branches: ['2670-feat-can-the-font-size-of-the-chat-input-box-be-increased'] # put your current branch to create a build. Core team only. paths-ignore: - '**.md' - 'cloud-deployments/*' diff --git a/frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/index.jsx b/frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/index.jsx index 85c30f3121..9354e0312a 100644 --- a/frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/index.jsx +++ b/frontend/src/components/WorkspaceChat/ChatContainer/ChatHistory/index.jsx @@ -11,6 +11,7 @@ import Workspace from "@/models/workspace"; import { useParams } from "react-router-dom"; import paths from "@/utils/paths"; import Appearance from "@/models/appearance"; +import useTextSize from "@/hooks/useTextSize"; export default function ChatHistory({ history = [], @@ -26,39 +27,10 @@ export default function ChatHistory({ const { showing, showModal, hideModal } = useManageWorkspaceModal(); const [isAtBottom, setIsAtBottom] = useState(true); const chatHistoryRef = useRef(null); - const [textSize, setTextSize] = useState("normal"); const [isUserScrolling, setIsUserScrolling] = useState(false); const isStreaming = history[history.length - 1]?.animate; const { showScrollbar } = Appearance.getSettings(); - - const getTextSizeClass = (size) => { - switch (size) { - case "small": - return "text-[12px]"; - case "large": - return "text-[18px]"; - default: - return "text-[14px]"; - } - }; - - useEffect(() => { - const storedTextSize = window.localStorage.getItem("anythingllm_text_size"); - if (storedTextSize) { - setTextSize(getTextSizeClass(storedTextSize)); - } - - const handleTextSizeChange = (event) => { - const size = event.detail; - setTextSize(getTextSizeClass(size)); - }; - - window.addEventListener("textSizeChange", handleTextSizeChange); - - return () => { - window.removeEventListener("textSizeChange", handleTextSizeChange); - }; - }, []); + const { textSizeClass } = useTextSize(); useEffect(() => { if (!isUserScrolling && (isAtBottom || isStreaming)) { @@ -204,7 +176,7 @@ export default function ChatHistory({ return (
{buttonDisabled ? ( diff --git a/frontend/src/hooks/useTextSize.js b/frontend/src/hooks/useTextSize.js new file mode 100644 index 0000000000..5704e19c4c --- /dev/null +++ b/frontend/src/hooks/useTextSize.js @@ -0,0 +1,38 @@ +import { useState, useEffect } from "react"; + +export default function useTextSize() { + const [textSize, setTextSize] = useState("normal"); + const [textSizeClass, setTextSizeClass] = useState("text-[14px]"); + + const getTextSizeClass = (size) => { + switch (size) { + case "small": + return "text-[12px]"; + case "large": + return "text-[18px]"; + default: + return "text-[14px]"; + } + }; + + useEffect(() => { + const storedTextSize = window.localStorage.getItem("anythingllm_text_size"); + if (storedTextSize) { + setTextSize(storedTextSize); + setTextSizeClass(getTextSizeClass(storedTextSize)); + } + + const handleTextSizeChange = (event) => { + const size = event.detail; + setTextSize(size); + setTextSizeClass(getTextSizeClass(size)); + }; + + window.addEventListener("textSizeChange", handleTextSizeChange); + return () => { + window.removeEventListener("textSizeChange", handleTextSizeChange); + }; + }, []); + + return { textSize, textSizeClass }; +}