Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjustable font size in chat input #2692

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/dev-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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/*'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [],
Expand All @@ -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)) {
Expand Down Expand Up @@ -204,7 +176,7 @@ export default function ChatHistory({

return (
<div
className={`markdown text-white/80 light:text-theme-text-primary font-light ${textSize} h-full md:h-[83%] pb-[100px] pt-6 md:pt-0 md:pb-20 md:mx-0 overflow-y-scroll flex flex-col justify-start ${
className={`markdown text-white/80 light:text-theme-text-primary font-light ${textSizeClass} h-full md:h-[83%] pb-[100px] pt-6 md:pt-0 md:pb-20 md:mx-0 overflow-y-scroll flex flex-col justify-start ${
showScrollbar ? "show-scrollbar" : "no-scroll"
}`}
id="chat-history"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { Tooltip } from "react-tooltip";
import AttachmentManager from "./Attachments";
import AttachItem from "./AttachItem";
import { PASTE_ATTACHMENT_EVENT } from "../DnDWrapper";
import useTextSize from "@/hooks/useTextSize";

export const PROMPT_INPUT_EVENT = "set_prompt_input";
const MAX_EDIT_STACK_SIZE = 100;
Expand All @@ -36,6 +37,7 @@ export default function PromptInput({
const [_, setFocused] = useState(false);
const undoStack = useRef([]);
const redoStack = useRef([]);
const { textSizeClass } = useTextSize();

/**
* To prevent too many re-renders we remotely listen for updates from the parent
Expand Down Expand Up @@ -269,7 +271,7 @@ export default function PromptInput({
adjustTextArea(e);
}}
value={promptInput}
className="cursor-text max-h-[50vh] md:max-h-[350px] md:min-h-[40px] mx-2 md:mx-0 pt-[12px] w-full text-[14px] leading-5 md:text-md text-white bg-transparent placeholder:text-white/60 light:placeholder:text-theme-text-primary resize-none active:outline-none focus:outline-none flex-grow"
className={`cursor-text max-h-[50vh] md:max-h-[350px] md:min-h-[40px] mx-2 md:mx-0 pt-[12px] w-full leading-5 md:text-md text-white bg-transparent placeholder:text-white/60 light:placeholder:text-theme-text-primary resize-none active:outline-none focus:outline-none flex-grow ${textSizeClass}`}
placeholder={"Send a message"}
/>
{buttonDisabled ? (
Expand Down
38 changes: 38 additions & 0 deletions frontend/src/hooks/useTextSize.js
Original file line number Diff line number Diff line change
@@ -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 };
}