Skip to content

Commit

Permalink
Scroll to bottom feature completely removed
Browse files Browse the repository at this point in the history
  • Loading branch information
FunkyOz committed Jan 2, 2025
1 parent ce58b05 commit e6244ac
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 23 deletions.
10 changes: 9 additions & 1 deletion apps/site/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,17 @@ function App() {

const [message, setMessage] = useState("");

useEffect(() => {
window.scrollTo({
left: 0,
top: document.body.scrollHeight,
behavior: "instant",
});
}, []);

return (
<div className="w-screen flex flex-col bg-white overflow-hidden">
<Chat withScroll>
<Chat>
<Sidebar items={conversations}>
{(item: Conversation, key: number) => (
<SidebarItem
Expand Down
2 changes: 0 additions & 2 deletions lib/components/chat/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ const ChatHelper: React.FC<ChatProps> = ({
children,
className,
classNames,
withScroll,
}) => {
const { sidebar, messageInput, messages, others } = useChat({
children,
withScroll,
});
const classes = useClassNames({ className, classNames });
const isMobile = useMediaQuery("(max-width: 768px)");
Expand Down
18 changes: 2 additions & 16 deletions lib/components/chat/hooks/useChat.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ReactNode, ReactElement, useMemo, useEffect } from "react";
import React, { ReactNode, ReactElement, useMemo } from "react";
import { Sidebar } from "../../../components/sidebar/sidebar";
import { MessageInput } from "../../../components/message/message-input";
import { Messages } from "../../../components/message/messages";
Expand All @@ -12,7 +12,6 @@ type UseChatReturn = {

type UseChatProps = {
children: ReactNode;
withScroll?: boolean;
};

const isSidebarElement = (child: ReactNode): child is ReactElement => {
Expand All @@ -27,10 +26,7 @@ const isMessagesElement = (child: ReactNode): child is ReactElement => {
return React.isValidElement(child) && child.type === Messages;
};

export const useChat = ({
children,
withScroll,
}: UseChatProps): UseChatReturn => {
export const useChat = ({ children }: UseChatProps): UseChatReturn => {
const childrenAsArray = useMemo(() => {
return Array.isArray(children) ? children : [children];
}, [children]);
Expand All @@ -56,16 +52,6 @@ export const useChat = ({
);
}, [childrenAsArray]);

useEffect(() => {
if (withScroll) {
window.scrollTo({
left: 0,
top: document.body.scrollHeight,
behavior: "instant",
});
}
}, []);

return {
sidebar,
messageInput,
Expand Down
4 changes: 0 additions & 4 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ export type ChatProps = {
* The children of the chat component
*/
children?: ReactNode;
/**
* Whether to scroll to the bottom of the chat when the component is mounted
*/
withScroll?: boolean;
/**
* The className of the chat component
*/
Expand Down

0 comments on commit e6244ac

Please sign in to comment.