From 256518b68c5e88bdba269570deccd765523cfb3f Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Wed, 18 Jun 2025 23:01:40 +0600 Subject: [PATCH] fix: chat responsiveness --- src/components/GenerateGuide/AIGuide.tsx | 3 +- src/components/GenerateGuide/AIGuideChat.tsx | 62 +++++++++++++++++++- 2 files changed, 60 insertions(+), 5 deletions(-) diff --git a/src/components/GenerateGuide/AIGuide.tsx b/src/components/GenerateGuide/AIGuide.tsx index fd78f1fbf..47c726f28 100644 --- a/src/components/GenerateGuide/AIGuide.tsx +++ b/src/components/GenerateGuide/AIGuide.tsx @@ -93,11 +93,10 @@ export function AIGuide(props: AIGuideProps) { }); }; - console.log(isLoadingBySlug); return ( {showUpgradeModal && ( setShowUpgradeModal(false)} /> diff --git a/src/components/GenerateGuide/AIGuideChat.tsx b/src/components/GenerateGuide/AIGuideChat.tsx index 4081937ff..407ddc00d 100644 --- a/src/components/GenerateGuide/AIGuideChat.tsx +++ b/src/components/GenerateGuide/AIGuideChat.tsx @@ -1,13 +1,21 @@ -import { useCallback, useEffect, useRef, useState } from 'react'; +import { + useCallback, + useEffect, + useLayoutEffect, + useRef, + useState, +} from 'react'; import { useChat, type ChatMessage } from '../../hooks/use-chat'; import { RoadmapAIChatCard } from '../RoadmapAIChat/RoadmapAIChatCard'; import { ArrowDownIcon, BotIcon, LockIcon, + MessageCircleIcon, PauseCircleIcon, SendIcon, Trash2Icon, + XIcon, } from 'lucide-react'; import { ChatHeaderButton } from '../FrameRenderer/RoadmapFloatingChat'; import { isLoggedIn } from '../../lib/jwt'; @@ -19,6 +27,7 @@ import { useQuery } from '@tanstack/react-query'; import { queryClient } from '../../stores/query-client'; import { billingDetailsOptions } from '../../queries/billing'; import { LoadingChip } from '../LoadingChip'; +import { getTailwindScreenDimension } from '../../lib/is-mobile'; type AIGuideChatProps = { guideSlug?: string; @@ -42,6 +51,8 @@ export function AIGuideChat(props: AIGuideChatProps) { const [inputValue, setInputValue] = useState(''); const [showScrollToBottom, setShowScrollToBottom] = useState(false); + const [isChatOpen, setIsChatOpen] = useState(true); + const [isMobile, setIsMobile] = useState(false); const { data: tokenUsage, @@ -144,13 +155,58 @@ export function AIGuideChat(props: AIGuideChatProps) { const isLoading = isGuideLoading || isTokenUsageLoading || isBillingDetailsLoading; + useLayoutEffect(() => { + const deviceType = getTailwindScreenDimension(); + const isMediumSize = ['sm', 'md'].includes(deviceType); + + if (!isMediumSize) { + const storedState = localStorage.getItem('chat-history-sidebar-open'); + setIsChatOpen(storedState === null ? true : storedState === 'true'); + } else { + setIsChatOpen(!isMediumSize); + } + + setIsMobile(isMediumSize); + }, []); + + useEffect(() => { + if (!isMobile) { + localStorage.setItem('chat-history-sidebar-open', isChatOpen.toString()); + } + }, [isChatOpen, isMobile]); + + if (!isChatOpen) { + return ( +
+ +
+ ); + } + return ( -
-
+
+

AI Guide

+ +
{isLoading && (