mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 08:23:34 +00:00
feat(mobile): improve GlobalChatPane behavior on mobile screens
- Hide FloatingChatButton on mobile for all pages except home (/ and /giftcard) - Add Building/Chatting toggle on mobile Chat tab in ProjectView - Add embedded mode to GlobalChatPane for inline rendering without fixed positioning - Add translations for "building" and "chatting" in all locales (en, pt, zh, ha, yo, ig)
This commit is contained in:
1 parent
075495fe7c
commit
395a7a76bb
9 files changed
+211
-31
No files matched your search
@@ -4,12 +4,14 @@ import { MessageCircle, X } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useGlobalChat } from '@/hooks/useGlobalChat';
|
||||
import { useAppContext } from '@/hooks/useAppContext';
|
||||
import { useIsMobile } from '@/hooks/useIsMobile';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
export function FloatingChatButton() {
|
||||
const { isOpen, setIsOpen, hasUnread } = useGlobalChat();
|
||||
const { config } = useAppContext();
|
||||
const location = useLocation();
|
||||
const isMobile = useIsMobile();
|
||||
const [isHovered, setIsHovered] = useState(false);
|
||||
const [isHiddenTemporarily, setIsHiddenTemporarily] = useState(false);
|
||||
|
||||
@@ -28,6 +30,12 @@ export function FloatingChatButton() {
|
||||
return null;
|
||||
}
|
||||
|
||||
// On mobile, only show on home screen (/ or /giftcard)
|
||||
const isHomePage = location.pathname === '/' || location.pathname === '/giftcard';
|
||||
if (isMobile && !isHomePage) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Don't render if temporarily hidden
|
||||
if (isHiddenTemporarily) {
|
||||
return null;
|
||||
|
||||
@@ -80,7 +80,12 @@ function ChatMessage({ message }: { message: GlobalChatMessage }) {
|
||||
);
|
||||
}
|
||||
|
||||
export function GlobalChatPane() {
|
||||
interface GlobalChatPaneProps {
|
||||
/** When true, renders inline without fixed positioning (for embedding in ProjectView) */
|
||||
embedded?: boolean;
|
||||
}
|
||||
|
||||
export function GlobalChatPane({ embedded = false }: GlobalChatPaneProps) {
|
||||
const { t } = useTranslation();
|
||||
const {
|
||||
messages,
|
||||
@@ -188,18 +193,132 @@ export function GlobalChatPane() {
|
||||
}
|
||||
}, [handleSend, isMobile]);
|
||||
|
||||
// Don't render if disabled or not open
|
||||
if (config.globalChatEnabled === false || !isOpen) {
|
||||
// For non-embedded mode: Don't render if disabled or not open
|
||||
if (!embedded && (config.globalChatEnabled === false || !isOpen)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Don't render on settings pages
|
||||
if (location.pathname.startsWith('/settings')) {
|
||||
// For non-embedded mode: Don't render on settings pages
|
||||
if (!embedded && location.pathname.startsWith('/settings')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const hasProviders = settings.providers.length > 0;
|
||||
|
||||
// Embedded mode: Render inline without fixed positioning
|
||||
if (embedded) {
|
||||
return (
|
||||
<div className="h-full flex flex-col bg-background">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between px-4 py-3 border-b bg-background/95 backdrop-blur supports-[backdrop-filter]:bg-background/60">
|
||||
<h2 className="font-semibold text-lg">{t('globalChat')}</h2>
|
||||
<div className="flex items-center gap-1">
|
||||
{messages.length > 0 && (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8"
|
||||
onClick={clearMessages}
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>{t('clearChat')}</TooltipContent>
|
||||
</Tooltip>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Messages */}
|
||||
<div
|
||||
ref={scrollAreaRef}
|
||||
className="flex-1 overflow-y-auto p-4 space-y-4"
|
||||
onScroll={handleScroll}
|
||||
>
|
||||
{messages.length === 0 ? (
|
||||
<div className="flex-1 flex items-center justify-center text-center text-muted-foreground px-8 py-12">
|
||||
<div>
|
||||
<p className="text-lg font-medium mb-2">{t('globalChatWelcome')}</p>
|
||||
<p className="text-sm">{t('globalChatDescription')}</p>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
messages.map((message) => (
|
||||
<ChatMessage key={message.id} message={message} />
|
||||
))
|
||||
)}
|
||||
|
||||
{isLoading && messages[messages.length - 1]?.role !== 'assistant' && (
|
||||
<div className="flex justify-start">
|
||||
<div className="bg-muted rounded-2xl rounded-bl-md px-4 py-3">
|
||||
<Loader2 className="h-4 w-4 animate-spin text-muted-foreground" />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Scroll to bottom button */}
|
||||
{showScrollToBottom && (
|
||||
<Button
|
||||
onClick={scrollToBottom}
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
className="absolute bottom-32 left-1/2 -translate-x-1/2 rounded-full shadow-lg"
|
||||
>
|
||||
<ChevronDown className="h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
|
||||
{/* Input */}
|
||||
<div className="p-4 border-t bg-background space-y-3 pb-safe">
|
||||
<div className="flex gap-2">
|
||||
<ModelSelector
|
||||
value={providerModel}
|
||||
onChange={setProviderModel}
|
||||
className="flex-1"
|
||||
disabled={isLoading}
|
||||
placeholder={t('chooseModel')}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex gap-2 items-end">
|
||||
<Textarea
|
||||
ref={textareaRef}
|
||||
value={input}
|
||||
onChange={(e) => {
|
||||
setInput(e.target.value);
|
||||
// Auto-resize
|
||||
const target = e.target as HTMLTextAreaElement;
|
||||
target.style.height = 'auto';
|
||||
target.style.height = Math.min(target.scrollHeight, 128) + 'px';
|
||||
}}
|
||||
onKeyDown={handleKeyDown}
|
||||
placeholder={hasProviders ? t('typeMessage') : t('configureAIFirst')}
|
||||
disabled={!hasProviders || isLoading}
|
||||
className="resize-none min-h-[44px] max-h-32"
|
||||
rows={1}
|
||||
/>
|
||||
{isLoading ? (
|
||||
<Button onClick={stopGeneration} size="icon" variant="destructive" className="h-11 w-11 shrink-0">
|
||||
<Square className="h-4 w-4" />
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
onClick={handleSend}
|
||||
size="icon"
|
||||
disabled={!input.trim() || !providerModel || !hasProviders}
|
||||
className="h-11 w-11 shrink-0"
|
||||
>
|
||||
<ArrowUp className="h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// Mobile: Full screen drawer from bottom
|
||||
if (isMobile) {
|
||||
return (
|
||||
|
||||
+3
-1
@@ -542,5 +542,7 @@
|
||||
"globalChatEnabled": "Floating Chat Button",
|
||||
"globalChatEnabledDescription": "Show a floating chat button for quick AI conversations",
|
||||
"globalChatSystemPrompt": "Chat System Prompt",
|
||||
"globalChatSystemPromptDescription": "Custom system prompt for the floating chat assistant"
|
||||
"globalChatSystemPromptDescription": "Custom system prompt for the floating chat assistant",
|
||||
"building": "Building",
|
||||
"chatting": "Chatting"
|
||||
}
|
||||
+3
-1
@@ -443,5 +443,7 @@
|
||||
"globalChatEnabled": "Maballin Tattaunawa Mai Yawo",
|
||||
"globalChatEnabledDescription": "Nuna maballin tattaunawa mai yawo don saurin tattaunawa da AI",
|
||||
"globalChatSystemPrompt": "Jagorar Tsarin Tattaunawa",
|
||||
"globalChatSystemPromptDescription": "Jagorar tsarin da aka keɓe don mataimakin tattaunawa mai yawo"
|
||||
"globalChatSystemPromptDescription": "Jagorar tsarin da aka keɓe don mataimakin tattaunawa mai yawo",
|
||||
"building": "Ginawa",
|
||||
"chatting": "Tattaunawa"
|
||||
}
|
||||
+3
-1
@@ -440,5 +440,7 @@
|
||||
"globalChatEnabled": "Bọtịnụ Nkata Na-epupụta",
|
||||
"globalChatEnabledDescription": "Gosi bọtịnụ nkata na-epupụta maka nkata AI ngwa ngwa",
|
||||
"globalChatSystemPrompt": "Usoro Nkata",
|
||||
"globalChatSystemPromptDescription": "Usoro nke gị maka onye enyemaka nkata na-epupụta"
|
||||
"globalChatSystemPromptDescription": "Usoro nke gị maka onye enyemaka nkata na-epupụta",
|
||||
"building": "Nrụpụta",
|
||||
"chatting": "Nkwurịta"
|
||||
}
|
||||
+3
-1
@@ -452,5 +452,7 @@
|
||||
"globalChatEnabled": "Botão de Chat Flutuante",
|
||||
"globalChatEnabledDescription": "Mostrar um botão de chat flutuante para conversas rápidas com IA",
|
||||
"globalChatSystemPrompt": "Prompt do Sistema do Chat",
|
||||
"globalChatSystemPromptDescription": "Prompt do sistema personalizado para o assistente de chat flutuante"
|
||||
"globalChatSystemPromptDescription": "Prompt do sistema personalizado para o assistente de chat flutuante",
|
||||
"building": "Construindo",
|
||||
"chatting": "Conversando"
|
||||
}
|
||||
+3
-1
@@ -440,5 +440,7 @@
|
||||
"globalChatEnabled": "Bọtini Ibanisọrọ Ti O N Lọ",
|
||||
"globalChatEnabledDescription": "Fi bọtini ibanisọrọ ti o n lọ han fun ibaraẹnisọrọ AI ni iyara",
|
||||
"globalChatSystemPrompt": "Itọsọna Eto Ibanisọrọ",
|
||||
"globalChatSystemPromptDescription": "Itọsọna eto aṣa fun oluranlọwọ ibanisọrọ ti o n lọ"
|
||||
"globalChatSystemPromptDescription": "Itọsọna eto aṣa fun oluranlọwọ ibanisọrọ ti o n lọ",
|
||||
"building": "Kíkọ́",
|
||||
"chatting": "Sísọ̀rọ̀"
|
||||
}
|
||||
+3
-1
@@ -452,5 +452,7 @@
|
||||
"globalChatEnabled": "浮动聊天按钮",
|
||||
"globalChatEnabledDescription": "显示浮动聊天按钮以便快速AI对话",
|
||||
"globalChatSystemPrompt": "聊天系统提示",
|
||||
"globalChatSystemPromptDescription": "浮动聊天助手的自定义系统提示"
|
||||
"globalChatSystemPromptDescription": "浮动聊天助手的自定义系统提示",
|
||||
"building": "构建",
|
||||
"chatting": "聊天"
|
||||
}
|
||||
+61
-20
@@ -20,6 +20,8 @@ import { useBuildProject } from '@/hooks/useBuildProject';
|
||||
import { useIsProjectPreviewable } from '@/hooks/useIsProjectPreviewable';
|
||||
import { useConsoleError } from '@/hooks/useConsoleError';
|
||||
import { useAutoBuild } from '@/hooks/useAutoBuild';
|
||||
import { GlobalChatPane } from '@/components/GlobalChatPane';
|
||||
import { useAppContext } from '@/hooks/useAppContext';
|
||||
|
||||
export function ProjectView() {
|
||||
const { projectId } = useParams<{ projectId: string }>();
|
||||
@@ -28,6 +30,7 @@ export function ProjectView() {
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [activeTab, setActiveTab] = useState<'preview' | 'code'>('preview');
|
||||
const [mobileView, setMobileView] = useState<'chat' | 'preview' | 'code'>('chat');
|
||||
const [mobileChatMode, setMobileChatMode] = useState<'building' | 'chatting'>('building');
|
||||
const [isAILoading, setIsAILoading] = useState(false);
|
||||
const [isProjectDetailsOpen, setIsProjectDetailsOpen] = useState(false);
|
||||
|
||||
@@ -38,6 +41,7 @@ export function ProjectView() {
|
||||
const chatPaneRef = useRef<ChatPaneRef>(null);
|
||||
const navigate = useNavigate();
|
||||
const isMobile = useIsMobile();
|
||||
const { config } = useAppContext();
|
||||
|
||||
const [isSidebarVisible, setIsSidebarVisible] = useState(!isMobile);
|
||||
|
||||
@@ -218,28 +222,65 @@ export function ProjectView() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex-1 overflow-hidden">
|
||||
<div className="flex-1 overflow-hidden flex flex-col">
|
||||
{mobileView === 'chat' && (
|
||||
project ? (
|
||||
<ChatPane
|
||||
ref={chatPaneRef}
|
||||
projectId={project.id}
|
||||
onNewChat={handleNewChat}
|
||||
onFirstInteraction={handleFirstInteraction}
|
||||
onLoadingChange={handleAILoadingChange}
|
||||
isLoading={isAILoading}
|
||||
isBuildLoading={build.isPending}
|
||||
consoleError={consoleError}
|
||||
onDismissConsoleError={handleDismissConsoleError}
|
||||
/>
|
||||
) : (
|
||||
<div className="h-full p-4 space-y-4">
|
||||
<Skeleton className="h-12 w-full" />
|
||||
<Skeleton className="h-8 w-3/4" />
|
||||
<Skeleton className="h-8 w-1/2" />
|
||||
<Skeleton className="h-32 w-full" />
|
||||
<>
|
||||
{/* Building/Chatting toggle - only show if global chat is enabled */}
|
||||
{config.globalChatEnabled !== false && (
|
||||
<div className="flex-shrink-0 border-b bg-muted/30">
|
||||
<div className="flex">
|
||||
<button
|
||||
onClick={() => setMobileChatMode('building')}
|
||||
className={`flex-1 py-2 text-xs font-medium transition-colors ${
|
||||
mobileChatMode === 'building'
|
||||
? 'text-primary border-b-2 border-primary bg-background'
|
||||
: 'text-muted-foreground hover:text-foreground'
|
||||
}`}
|
||||
>
|
||||
{t('building')}
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setMobileChatMode('chatting')}
|
||||
className={`flex-1 py-2 text-xs font-medium transition-colors ${
|
||||
mobileChatMode === 'chatting'
|
||||
? 'text-primary border-b-2 border-primary bg-background'
|
||||
: 'text-muted-foreground hover:text-foreground'
|
||||
}`}
|
||||
>
|
||||
{t('chatting')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Chat content based on mode */}
|
||||
<div className="flex-1 overflow-hidden">
|
||||
{mobileChatMode === 'building' ? (
|
||||
project ? (
|
||||
<ChatPane
|
||||
ref={chatPaneRef}
|
||||
projectId={project.id}
|
||||
onNewChat={handleNewChat}
|
||||
onFirstInteraction={handleFirstInteraction}
|
||||
onLoadingChange={handleAILoadingChange}
|
||||
isLoading={isAILoading}
|
||||
isBuildLoading={build.isPending}
|
||||
consoleError={consoleError}
|
||||
onDismissConsoleError={handleDismissConsoleError}
|
||||
/>
|
||||
) : (
|
||||
<div className="h-full p-4 space-y-4">
|
||||
<Skeleton className="h-12 w-full" />
|
||||
<Skeleton className="h-8 w-3/4" />
|
||||
<Skeleton className="h-8 w-1/2" />
|
||||
<Skeleton className="h-32 w-full" />
|
||||
</div>
|
||||
)
|
||||
) : (
|
||||
<GlobalChatPane embedded />
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
</>
|
||||
)}
|
||||
{(mobileView === 'preview' || mobileView === 'code') && (
|
||||
project ? (
|
||||
|
||||
Reference in new issue
Block a user