refactor(mobile): move Building/Chatting toggle into compose box

- Remove toggle tabs from top of mobile chat pane
- Add pill-style toggle button inside the compose area (similar to Lovable's UI)
- Toggle shows Building (hammer icon) and Chatting (message icon) modes
- Toggle appears in both ChatInput and GlobalChatPane embedded mode
- Maintains consistent styling with rounded-full bg-muted design
This commit is contained in:
MK Fain committed 2025-12-03 22:06:51 -06:00
1 parent 395a7a76bb
commit ed512c5d64
4 files changed
+147 -85

No files matched your search

+71 -28
View File
@@ -1,7 +1,7 @@
import { useState, useRef, useEffect, useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { useLocation } from 'react-router-dom';
import { X, Trash2, Copy, Check, ChevronDown, ArrowUp, Square, Loader2 } from 'lucide-react';
import { X, Trash2, Copy, Check, ChevronDown, ArrowUp, Square, Loader2, Hammer, MessageCircle } from 'lucide-react';
import { Streamdown } from 'streamdown';
import { Button } from '@/components/ui/button';
import { Textarea } from '@/components/ui/textarea';
@@ -83,9 +83,12 @@ function ChatMessage({ message }: { message: GlobalChatMessage }) {
interface GlobalChatPaneProps {
/** When true, renders inline without fixed positioning (for embedding in ProjectView) */
embedded?: boolean;
/** Mobile chat mode toggle - only used in embedded mode */
mobileChatMode?: 'building' | 'chatting';
onMobileChatModeChange?: (mode: 'building' | 'chatting') => void;
}
export function GlobalChatPane({ embedded = false }: GlobalChatPaneProps) {
export function GlobalChatPane({ embedded = false, mobileChatMode, onMobileChatModeChange }: GlobalChatPaneProps) {
const { t } = useTranslation();
const {
messages,
@@ -272,17 +275,8 @@ export function GlobalChatPane({ embedded = false }: GlobalChatPaneProps) {
)}
{/* 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">
<div className="border-t p-4 pb-safe">
<div className="flex flex-col rounded-2xl border border-input bg-background shadow-sm focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2">
<Textarea
ref={textareaRef}
value={input}
@@ -296,23 +290,72 @@ export function GlobalChatPane({ embedded = false }: GlobalChatPaneProps) {
onKeyDown={handleKeyDown}
placeholder={hasProviders ? t('typeMessage') : t('configureAIFirst')}
disabled={!hasProviders || isLoading}
className="resize-none min-h-[44px] max-h-32"
className="flex-1 resize-none border-0 bg-transparent px-4 py-3 text-sm focus-visible:ring-0 focus-visible:ring-offset-0 placeholder:text-muted-foreground min-h-[80px]"
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>
)}
{/* Bottom Controls Row */}
<div className="flex items-center gap-4 px-2 py-2">
{/* Mobile Chat Mode Toggle */}
{mobileChatMode && onMobileChatModeChange && (
<div className="flex items-center rounded-full bg-muted p-0.5">
<button
onClick={() => onMobileChatModeChange('building')}
className={cn(
'flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium transition-all',
mobileChatMode === 'building'
? 'bg-background text-foreground shadow-sm'
: 'text-muted-foreground hover:text-foreground'
)}
>
<Hammer className="h-3 w-3" />
{t('building')}
</button>
<button
onClick={() => onMobileChatModeChange('chatting')}
className={cn(
'flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium transition-all',
mobileChatMode === 'chatting'
? 'bg-background text-foreground shadow-sm'
: 'text-muted-foreground hover:text-foreground'
)}
>
<MessageCircle className="h-3 w-3" />
{t('chatting')}
</button>
</div>
)}
{/* Model Selector */}
<div className="flex-1 max-w-72 ml-auto overflow-hidden">
<ModelSelector
value={providerModel}
onChange={setProviderModel}
disabled={isLoading}
placeholder={t('chooseModel')}
/>
</div>
{/* Send/Stop Button */}
{isLoading ? (
<Button
onClick={stopGeneration}
size="sm"
variant="ghost"
className="size-8 rounded-full p-0 bg-foreground/10 [&_svg]:size-3.5 [&_svg]:fill-foreground hover:bg-foreground/20"
>
<Square />
</Button>
) : (
<Button
onClick={handleSend}
size="sm"
disabled={!input.trim() || !providerModel || !hasProviders}
className="size-8 [&_svg]:size-5 rounded-full p-0"
>
<ArrowUp />
</Button>
)}
</div>
</div>
</div>
</div>
+37 -1
View File
@@ -5,8 +5,9 @@ import { Textarea } from '@/components/ui/textarea';
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
import { CircularProgress } from '@/components/ui/circular-progress';
import { FileAttachment } from '@/components/ui/file-attachment';
import { Square, ArrowUp } from 'lucide-react';
import { Square, ArrowUp, Hammer, MessageCircle } from 'lucide-react';
import { ModelSelector } from '@/components/ModelSelector';
import { cn } from '@/lib/utils';
interface ChatInputProps {
isLoading: boolean;
@@ -28,6 +29,9 @@ interface ChatInputProps {
onDragOver: (e: React.DragEvent) => void;
onDragLeave: (e: React.DragEvent) => void;
onDrop: (e: React.DragEvent) => void;
/** Mobile chat mode toggle - only shown on mobile when global chat is enabled */
mobileChatMode?: 'building' | 'chatting';
onMobileChatModeChange?: (mode: 'building' | 'chatting') => void;
}
export const ChatInput = memo(function ChatInput({
@@ -50,6 +54,8 @@ export const ChatInput = memo(function ChatInput({
onDragOver,
onDragLeave,
onDrop,
mobileChatMode,
onMobileChatModeChange,
}: ChatInputProps) {
const { t } = useTranslation();
const [input, setInput] = useState('');
@@ -167,6 +173,36 @@ export const ChatInput = memo(function ChatInput({
multiple={true}
/>
{/* Mobile Chat Mode Toggle - shown on mobile when global chat is enabled */}
{mobileChatMode && onMobileChatModeChange && (
<div className="flex items-center rounded-full bg-muted p-0.5">
<button
onClick={() => onMobileChatModeChange('building')}
className={cn(
'flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium transition-all',
mobileChatMode === 'building'
? 'bg-background text-foreground shadow-sm'
: 'text-muted-foreground hover:text-foreground'
)}
>
<Hammer className="h-3 w-3" />
{t('building')}
</button>
<button
onClick={() => onMobileChatModeChange('chatting')}
className={cn(
'flex items-center gap-1 px-2 py-1 rounded-full text-xs font-medium transition-all',
mobileChatMode === 'chatting'
? 'bg-background text-foreground shadow-sm'
: 'text-muted-foreground hover:text-foreground'
)}
>
<MessageCircle className="h-3 w-3" />
{t('chatting')}
</button>
</div>
)}
{/* Context Usage Wheel */}
{contextUsagePercentage >= 10 && currentModelContextLength && lastInputTokens && lastInputTokens > 0 && (
<TooltipProvider>
+7
View File
@@ -59,6 +59,9 @@ interface ChatPaneProps {
isBuildLoading?: boolean;
consoleError?: ProjectPreviewConsoleError | null;
onDismissConsoleError?: () => void;
/** Mobile chat mode toggle - only shown on mobile when global chat is enabled */
mobileChatMode?: 'building' | 'chatting';
onMobileChatModeChange?: (mode: 'building' | 'chatting') => void;
}
export interface ChatPaneRef {
@@ -74,6 +77,8 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
isBuildLoading: externalIsBuildLoading,
consoleError,
onDismissConsoleError,
mobileChatMode,
onMobileChatModeChange,
}, ref) => {
const { t } = useTranslation();
const [searchParams, setSearchParams] = useSearchParams();
@@ -729,6 +734,8 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
onDragOver={handleDragOver}
onDragLeave={handleDragLeave}
onDrop={handleDrop}
mobileChatMode={mobileChatMode}
onMobileChatModeChange={onMobileChatModeChange}
/>
{/* Onboarding Dialog */}
+32 -56
View File
@@ -224,63 +224,39 @@ export function ProjectView() {
<div className="flex-1 overflow-hidden flex flex-col">
{mobileView === 'chat' && (
<>
{/* 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>
)
/* Chat content based on mode - toggle is inside the compose area */
<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}
mobileChatMode={config.globalChatEnabled !== false ? mobileChatMode : undefined}
onMobileChatModeChange={config.globalChatEnabled !== false ? setMobileChatMode : undefined}
/>
) : (
<GlobalChatPane embedded />
)}
</div>
</>
<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
mobileChatMode={mobileChatMode}
onMobileChatModeChange={setMobileChatMode}
/>
)}
</div>
)}
{(mobileView === 'preview' || mobileView === 'code') && (
project ? (