mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-20 10:20:15 +01:00
fix static flag bug
This commit is contained in:
parent
92b2109dc3
commit
779f142058
4 changed files with 50 additions and 39 deletions
File diff suppressed because one or more lines are too long
15
src/App.jsx
15
src/App.jsx
|
|
@ -1,14 +1,17 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Messages from './components/main/Messages';
|
import Messages from './components/main/Messages';
|
||||||
|
import Landing from './components/main/Landing';
|
||||||
import TextChat from './components/main/TextChat';
|
import TextChat from './components/main/TextChat';
|
||||||
import Nav from './components/Nav';
|
import Nav from './components/Nav';
|
||||||
import MobileNav from './components/Nav/MobileNav';
|
import MobileNav from './components/Nav/MobileNav';
|
||||||
|
import useDocumentTitle from '~/hooks/useDocumentTitle';
|
||||||
import { useSelector } from 'react-redux';
|
import { useSelector } from 'react-redux';
|
||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
|
|
||||||
const { messages } = useSelector((state) => state.messages);
|
const { messages } = useSelector((state) => state.messages);
|
||||||
const convo = useSelector((state) => state.convo);
|
const { title } = useSelector((state) => state.convo);
|
||||||
|
|
||||||
|
useDocumentTitle(title);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex h-screen">
|
<div className="flex h-screen">
|
||||||
|
|
@ -16,7 +19,13 @@ const App = () => {
|
||||||
<div className="flex h-full w-full flex-1 flex-col bg-gray-50 md:pl-[260px]">
|
<div className="flex h-full w-full flex-1 flex-col bg-gray-50 md:pl-[260px]">
|
||||||
<div className="transition-width relative flex h-full w-full flex-1 flex-col items-stretch overflow-hidden dark:bg-gray-800">
|
<div className="transition-width relative flex h-full w-full flex-1 flex-col items-stretch overflow-hidden dark:bg-gray-800">
|
||||||
<MobileNav />
|
<MobileNav />
|
||||||
<Messages messages={messages} title={convo.title}/>
|
{messages.length === 0 ? (
|
||||||
|
<Landing title={title} />
|
||||||
|
) : (
|
||||||
|
<Messages
|
||||||
|
messages={messages}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<TextChat messages={messages} />
|
<TextChat messages={messages} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,28 +1,24 @@
|
||||||
import React, { useEffect, useState, useRef } from 'react';
|
import React, { useEffect, useState, useRef } from 'react';
|
||||||
import { useSelector } from 'react-redux';
|
|
||||||
import useDocumentTitle from '~/hooks/useDocumentTitle';
|
|
||||||
import useDidMountEffect from '~/hooks/useDidMountEffect';
|
import useDidMountEffect from '~/hooks/useDidMountEffect';
|
||||||
import Message from './Message';
|
import Message from './Message';
|
||||||
import ScrollToBottom from './ScrollToBottom';
|
import ScrollToBottom from './ScrollToBottom';
|
||||||
import Landing from './Landing';
|
|
||||||
|
|
||||||
export default function Messages({ title, messages }) {
|
const Messages = ({ messages }) => {
|
||||||
if (messages.length === 0) {
|
|
||||||
return <Landing title={title}/>;
|
|
||||||
}
|
|
||||||
|
|
||||||
useDocumentTitle(title);
|
|
||||||
const messagesEndRef = useRef(null);
|
|
||||||
const [showScrollButton, setShowScrollButton] = useState(false);
|
const [showScrollButton, setShowScrollButton] = useState(false);
|
||||||
|
const scrollableRef = useRef(null);
|
||||||
|
const messagesEndRef = useRef(null);
|
||||||
|
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const scrollable = scrollableRef.current;
|
||||||
|
const hasScrollbar = scrollable.scrollHeight > scrollable.clientHeight;
|
||||||
|
setShowScrollButton(hasScrollbar);
|
||||||
|
}, [scrollableRef]);
|
||||||
|
|
||||||
const scrollToBottom = () => {
|
const scrollToBottom = () => {
|
||||||
messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' });
|
messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' });
|
||||||
};
|
};
|
||||||
|
|
||||||
if (document.body.clientHeight > window.innerHeight) {
|
|
||||||
setShowScrollButton(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleScroll = (e) => {
|
const handleScroll = (e) => {
|
||||||
const bottom = e.target.scrollHeight - e.target.scrollTop === e.target.clientHeight;
|
const bottom = e.target.scrollHeight - e.target.scrollTop === e.target.clientHeight;
|
||||||
if (bottom) {
|
if (bottom) {
|
||||||
|
|
@ -30,7 +26,7 @@ export default function Messages({ title, messages }) {
|
||||||
} else {
|
} else {
|
||||||
setShowScrollButton(true);
|
setShowScrollButton(true);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
const scrollHandler = (e) => {
|
const scrollHandler = (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
@ -38,7 +34,11 @@ export default function Messages({ title, messages }) {
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex-1 overflow-y-auto " onScroll={handleScroll}>
|
<div
|
||||||
|
className="flex-1 overflow-y-auto "
|
||||||
|
ref={scrollableRef}
|
||||||
|
onScroll={handleScroll}
|
||||||
|
>
|
||||||
{/* <div className="flex-1 overflow-hidden"> */}
|
{/* <div className="flex-1 overflow-hidden"> */}
|
||||||
<div className="h-full dark:bg-gray-800">
|
<div className="h-full dark:bg-gray-800">
|
||||||
<div className="flex h-full flex-col items-center text-sm dark:bg-gray-800">
|
<div className="flex h-full flex-col items-center text-sm dark:bg-gray-800">
|
||||||
|
|
@ -61,4 +61,6 @@ export default function Messages({ title, messages }) {
|
||||||
{/* </div> */}
|
{/* </div> */}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
export default Messages
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,7 @@ export default function TextChat({ messages }) {
|
||||||
onKeyDown={handleKeyDown}
|
onKeyDown={handleKeyDown}
|
||||||
onChange={changeHandler}
|
onChange={changeHandler}
|
||||||
placeholder=""
|
placeholder=""
|
||||||
className="m-0 h-auto max-h-52 resize-none overflow-auto border-0 bg-transparent p-0 pl-9 pr-7 leading-6 focus:outline-none focus:ring-0 focus-visible:ring-0 dark:bg-transparent md:pl-7"
|
className="m-0 h-auto max-h-52 resize-none overflow-auto border-0 bg-transparent p-0 pl-9 pr-7 leading-6 focus:outline-none focus:ring-0 focus-visible:ring-0 dark:bg-transparent md:pl-8"
|
||||||
/>
|
/>
|
||||||
<SubmitButton submitMessage={submitMessage} />
|
<SubmitButton submitMessage={submitMessage} />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue