1
0
mirror of https://github.com/kamranahmedse/developer-roadmap.git synced 2025-09-25 08:35:42 +02:00

Responsiveness of AI chat

This commit is contained in:
Kamran Ahmed
2025-05-27 02:11:09 +01:00
parent c0df7d7467
commit 00059b83ea
2 changed files with 40 additions and 2 deletions

View File

@@ -7,6 +7,7 @@ import {
Fragment,
useCallback,
useEffect,
useLayoutEffect,
useMemo,
useRef,
useState,
@@ -48,6 +49,9 @@ import { TopicDetail } from '../TopicDetail/TopicDetail';
import { slugify } from '../../lib/slugger';
import { AIChatActionButtons } from './AIChatActionButtons';
import { cn } from '../../lib/classname';
import {
getTailwindScreenDimension, type TailwindScreenDimensions
} from '../../lib/is-mobile';
export type RoamdapAIChatHistoryType = {
role: AllowedAIChatRole;
@@ -77,6 +81,12 @@ export function RoadmapAIChat(props: RoadmapAIChatProps) {
const editorRef = useRef<Editor | null>(null);
const scrollareaRef = useRef<HTMLDivElement>(null);
const [deviceType, setDeviceType] = useState<TailwindScreenDimensions>();
useLayoutEffect(() => {
setDeviceType(getTailwindScreenDimension());
}, []);
const [isChatMobileVisible, setIsChatMobileVisible] = useState(false);
const [isLoading, setIsLoading] = useState(true);
const [showUpgradeModal, setShowUpgradeModal] = useState(false);
@@ -182,6 +192,11 @@ export function RoadmapAIChat(props: RoadmapAIChatProps) {
setSelectedTopicId(topicId);
setSelectedTopicTitle(topicTitle);
setActiveTab('topic');
console.log(deviceType);
if (['sm', 'md', 'lg', 'xl'].includes(deviceType || 'xl')) {
setIsChatMobileVisible(true);
}
});
const topicWithSlug = slugify(topicTitle) + '@' + topicId;
@@ -196,7 +211,7 @@ export function RoadmapAIChat(props: RoadmapAIChatProps) {
}),
);
},
[roadmapId],
[roadmapId, deviceType],
);
const renderer: Record<string, MessagePartRenderer> = useMemo(() => {
@@ -395,9 +410,10 @@ export function RoadmapAIChat(props: RoadmapAIChatProps) {
<div className="fixed bottom-4 left-1/2 z-50 block -translate-x-1/2 xl:hidden">
<button
onClick={() => {
setActiveTab('chat');
setIsChatMobileVisible(true);
}}
className="relative hover:bg-stone-800 overflow-hidden rounded-full bg-stone-900 px-4 py-2 text-center text-white shadow-2xl"
className="relative overflow-hidden rounded-full bg-stone-900 px-4 py-2 text-center text-white shadow-2xl hover:bg-stone-800"
>
<span className="relative z-20 flex items-center gap-2 text-sm">
<Bot className="size-5" />

View File

@@ -31,3 +31,25 @@ export function isMobileScreen(): boolean {
typeof window !== 'undefined' && (window.innerWidth < 640 || isMobile())
);
}
export type TailwindScreenDimensions = 'sm' | 'md' | 'lg' | 'xl' | '2xl';
export function getTailwindScreenDimension(): TailwindScreenDimensions {
if (window.innerWidth < 640) {
return 'sm';
}
if (window.innerWidth < 768) {
return 'md';
}
if (window.innerWidth < 1024) {
return 'lg';
}
if (window.innerWidth < 1280) {
return 'xl';
}
return '2xl';
}