feat: add a better scroll behave on playground's chat (#3680)
* feat: Add useUtilityStore hook to IOModal for setting playground scroll behavior * feat: Add useUtilityStore hook to IOModal for setting playground scroll behavior * feat: Add setPlaygroundScrollBehaves function to useUtilityStore hook * feat: Update codeTabsPropsType to allow undefined for the 'open' property * feat: Add `playgroundScrollBehaves` and `setPlaygroundScrollBehaves` to `UtilityStoreType` The `UtilityStoreType` now includes the `playgroundScrollBehaves` property of type `ScrollBehavior` and the `setPlaygroundScrollBehaves` function to update it. This allows for managing the scroll behavior of the playground in the application. * refactor: Remove unused 'open' prop from CodeTabsComponent
This commit is contained in:
parent
cb1d720796
commit
835559a05d
5 changed files with 33 additions and 4 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { useUtilityStore } from "@/stores/utilityStore";
|
||||||
import Convert from "ansi-to-html";
|
import Convert from "ansi-to-html";
|
||||||
import { useEffect, useMemo, useRef, useState } from "react";
|
import { useEffect, useMemo, useRef, useState } from "react";
|
||||||
import Markdown from "react-markdown";
|
import Markdown from "react-markdown";
|
||||||
|
|
@ -41,6 +42,13 @@ export default function ChatMessage({
|
||||||
const setErrorData = useAlertStore((state) => state.setErrorData);
|
const setErrorData = useAlertStore((state) => state.setErrorData);
|
||||||
const chatMessageRef = useRef(chatMessage);
|
const chatMessageRef = useRef(chatMessage);
|
||||||
|
|
||||||
|
const playgroundScrollBehaves = useUtilityStore(
|
||||||
|
(state) => state.playgroundScrollBehaves,
|
||||||
|
);
|
||||||
|
const setPlaygroundScrollBehaves = useUtilityStore(
|
||||||
|
(state) => state.setPlaygroundScrollBehaves,
|
||||||
|
);
|
||||||
|
|
||||||
// Sync ref with state
|
// Sync ref with state
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
chatMessageRef.current = chatMessage;
|
chatMessageRef.current = chatMessage;
|
||||||
|
|
@ -107,9 +115,14 @@ export default function ChatMessage({
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const element = document.getElementById("last-chat-message");
|
const element = document.getElementById("last-chat-message");
|
||||||
if (element) {
|
if (element) {
|
||||||
setTimeout(() => {
|
if (playgroundScrollBehaves === "instant") {
|
||||||
element.scrollIntoView({ behavior: "smooth" });
|
element.scrollIntoView({ behavior: playgroundScrollBehaves });
|
||||||
}, 200);
|
setPlaygroundScrollBehaves("smooth");
|
||||||
|
} else {
|
||||||
|
setTimeout(() => {
|
||||||
|
element.scrollIntoView({ behavior: playgroundScrollBehaves });
|
||||||
|
}, 200);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, [lastMessage]);
|
}, [lastMessage]);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import {
|
||||||
useDeleteMessages,
|
useDeleteMessages,
|
||||||
useGetMessagesQuery,
|
useGetMessagesQuery,
|
||||||
} from "@/controllers/API/queries/messages";
|
} from "@/controllers/API/queries/messages";
|
||||||
|
import { useUtilityStore } from "@/stores/utilityStore";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import AccordionComponent from "../../components/accordionComponent";
|
import AccordionComponent from "../../components/accordionComponent";
|
||||||
import IconComponent from "../../components/genericIconComponent";
|
import IconComponent from "../../components/genericIconComponent";
|
||||||
|
|
@ -172,6 +173,16 @@ export default function IOModal({
|
||||||
sessions;
|
sessions;
|
||||||
}, [messages]);
|
}, [messages]);
|
||||||
|
|
||||||
|
const setPlaygroundScrollBehaves = useUtilityStore(
|
||||||
|
(state) => state.setPlaygroundScrollBehaves,
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (open) {
|
||||||
|
setPlaygroundScrollBehaves("instant");
|
||||||
|
}
|
||||||
|
}, [open]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BaseModal
|
<BaseModal
|
||||||
size={"md-thin"}
|
size={"md-thin"}
|
||||||
|
|
|
||||||
|
|
@ -15,4 +15,7 @@ export const useUtilityStore = create<UtilityStoreType>((set, get) => ({
|
||||||
healthCheckTimeout: null,
|
healthCheckTimeout: null,
|
||||||
setHealthCheckTimeout: (timeout: string | null) =>
|
setHealthCheckTimeout: (timeout: string | null) =>
|
||||||
set({ healthCheckTimeout: timeout }),
|
set({ healthCheckTimeout: timeout }),
|
||||||
|
playgroundScrollBehaves: "instant",
|
||||||
|
setPlaygroundScrollBehaves: (behaves: ScrollBehavior) =>
|
||||||
|
set({ playgroundScrollBehaves: behaves }),
|
||||||
}));
|
}));
|
||||||
|
|
|
||||||
|
|
@ -775,7 +775,7 @@ export type tabsArrayType = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export type codeTabsPropsType = {
|
export type codeTabsPropsType = {
|
||||||
open: boolean;
|
open?: boolean;
|
||||||
tabs: Array<tabsArrayType>;
|
tabs: Array<tabsArrayType>;
|
||||||
activeTab: string;
|
activeTab: string;
|
||||||
setActiveTab: (value: string) => void;
|
setActiveTab: (value: string) => void;
|
||||||
|
|
|
||||||
|
|
@ -3,4 +3,6 @@ export type UtilityStoreType = {
|
||||||
setSelectedItems: (itemId: any) => void;
|
setSelectedItems: (itemId: any) => void;
|
||||||
healthCheckTimeout: string | null;
|
healthCheckTimeout: string | null;
|
||||||
setHealthCheckTimeout: (timeout: string | null) => void;
|
setHealthCheckTimeout: (timeout: string | null) => void;
|
||||||
|
playgroundScrollBehaves: ScrollBehavior;
|
||||||
|
setPlaygroundScrollBehaves: (behaves: ScrollBehavior) => void;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue