mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-09-25 00:21:28 +02:00
Responsiveness of AI chat
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
|||||||
Fragment,
|
Fragment,
|
||||||
useCallback,
|
useCallback,
|
||||||
useEffect,
|
useEffect,
|
||||||
|
useLayoutEffect,
|
||||||
useMemo,
|
useMemo,
|
||||||
useRef,
|
useRef,
|
||||||
useState,
|
useState,
|
||||||
@@ -48,6 +49,9 @@ import { TopicDetail } from '../TopicDetail/TopicDetail';
|
|||||||
import { slugify } from '../../lib/slugger';
|
import { slugify } from '../../lib/slugger';
|
||||||
import { AIChatActionButtons } from './AIChatActionButtons';
|
import { AIChatActionButtons } from './AIChatActionButtons';
|
||||||
import { cn } from '../../lib/classname';
|
import { cn } from '../../lib/classname';
|
||||||
|
import {
|
||||||
|
getTailwindScreenDimension, type TailwindScreenDimensions
|
||||||
|
} from '../../lib/is-mobile';
|
||||||
|
|
||||||
export type RoamdapAIChatHistoryType = {
|
export type RoamdapAIChatHistoryType = {
|
||||||
role: AllowedAIChatRole;
|
role: AllowedAIChatRole;
|
||||||
@@ -77,6 +81,12 @@ export function RoadmapAIChat(props: RoadmapAIChatProps) {
|
|||||||
const editorRef = useRef<Editor | null>(null);
|
const editorRef = useRef<Editor | null>(null);
|
||||||
const scrollareaRef = useRef<HTMLDivElement>(null);
|
const scrollareaRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
const [deviceType, setDeviceType] = useState<TailwindScreenDimensions>();
|
||||||
|
|
||||||
|
useLayoutEffect(() => {
|
||||||
|
setDeviceType(getTailwindScreenDimension());
|
||||||
|
}, []);
|
||||||
|
|
||||||
const [isChatMobileVisible, setIsChatMobileVisible] = useState(false);
|
const [isChatMobileVisible, setIsChatMobileVisible] = useState(false);
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [showUpgradeModal, setShowUpgradeModal] = useState(false);
|
const [showUpgradeModal, setShowUpgradeModal] = useState(false);
|
||||||
@@ -182,6 +192,11 @@ export function RoadmapAIChat(props: RoadmapAIChatProps) {
|
|||||||
setSelectedTopicId(topicId);
|
setSelectedTopicId(topicId);
|
||||||
setSelectedTopicTitle(topicTitle);
|
setSelectedTopicTitle(topicTitle);
|
||||||
setActiveTab('topic');
|
setActiveTab('topic');
|
||||||
|
|
||||||
|
console.log(deviceType);
|
||||||
|
if (['sm', 'md', 'lg', 'xl'].includes(deviceType || 'xl')) {
|
||||||
|
setIsChatMobileVisible(true);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const topicWithSlug = slugify(topicTitle) + '@' + topicId;
|
const topicWithSlug = slugify(topicTitle) + '@' + topicId;
|
||||||
@@ -196,7 +211,7 @@ export function RoadmapAIChat(props: RoadmapAIChatProps) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
[roadmapId],
|
[roadmapId, deviceType],
|
||||||
);
|
);
|
||||||
|
|
||||||
const renderer: Record<string, MessagePartRenderer> = useMemo(() => {
|
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">
|
<div className="fixed bottom-4 left-1/2 z-50 block -translate-x-1/2 xl:hidden">
|
||||||
<button
|
<button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
setActiveTab('chat');
|
||||||
setIsChatMobileVisible(true);
|
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">
|
<span className="relative z-20 flex items-center gap-2 text-sm">
|
||||||
<Bot className="size-5" />
|
<Bot className="size-5" />
|
||||||
|
@@ -31,3 +31,25 @@ export function isMobileScreen(): boolean {
|
|||||||
typeof window !== 'undefined' && (window.innerWidth < 640 || isMobile())
|
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';
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user