mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Simplify project actions
This commit is contained in:
1 parent
1739921a40
commit
179e0fc090
4 files changed
+401
-201
No files matched your search
@@ -0,0 +1,142 @@
|
||||
import { useState } from 'react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/components/ui/dropdown-menu';
|
||||
import {
|
||||
MoreHorizontal,
|
||||
MessageSquarePlus,
|
||||
Play,
|
||||
CloudUpload,
|
||||
Settings,
|
||||
Loader2,
|
||||
GitBranch
|
||||
} from 'lucide-react';
|
||||
import { GitHistoryDialog } from '@/components/ai/GitHistoryDialog';
|
||||
import { AISettingsDialog } from '@/components/ai/AISettingsDialog';
|
||||
|
||||
interface ActionsMenuProps {
|
||||
projectId: string;
|
||||
onNewChat: () => void;
|
||||
onBuild: () => void;
|
||||
onDeploy: () => void;
|
||||
isLoading?: boolean;
|
||||
isBuildLoading?: boolean;
|
||||
isDeployLoading?: boolean;
|
||||
disabled?: boolean;
|
||||
onFirstInteraction?: () => void;
|
||||
}
|
||||
|
||||
export function ActionsMenu({
|
||||
projectId,
|
||||
onNewChat,
|
||||
onBuild,
|
||||
onDeploy,
|
||||
isLoading = false,
|
||||
isBuildLoading = false,
|
||||
isDeployLoading = false,
|
||||
disabled = false,
|
||||
onFirstInteraction
|
||||
}: ActionsMenuProps) {
|
||||
const [gitHistoryOpen, setGitHistoryOpen] = useState(false);
|
||||
const [aiSettingsOpen, setAISettingsOpen] = useState(false);
|
||||
|
||||
const isAnyLoading = isLoading || isBuildLoading || isDeployLoading;
|
||||
|
||||
return (
|
||||
<>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-8 w-8 p-0"
|
||||
disabled={disabled}
|
||||
>
|
||||
<MoreHorizontal className="h-4 w-4" />
|
||||
<span className="sr-only">Open menu</span>
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" className="w-48">
|
||||
<DropdownMenuItem
|
||||
onClick={onNewChat}
|
||||
disabled={isLoading}
|
||||
className="gap-2"
|
||||
>
|
||||
<MessageSquarePlus className="h-4 w-4" />
|
||||
New Chat
|
||||
</DropdownMenuItem>
|
||||
|
||||
<DropdownMenuItem
|
||||
onClick={() => setGitHistoryOpen(true)}
|
||||
disabled={isAnyLoading}
|
||||
className="gap-2"
|
||||
>
|
||||
<GitBranch className="h-4 w-4" />
|
||||
Git History
|
||||
</DropdownMenuItem>
|
||||
|
||||
<DropdownMenuSeparator />
|
||||
|
||||
<DropdownMenuItem
|
||||
onClick={() => {
|
||||
if (onFirstInteraction) onFirstInteraction();
|
||||
onBuild();
|
||||
}}
|
||||
disabled={isAnyLoading}
|
||||
className="gap-2"
|
||||
>
|
||||
{isBuildLoading ? (
|
||||
<Loader2 className="h-4 w-4 animate-spin" />
|
||||
) : (
|
||||
<Play className="h-4 w-4" />
|
||||
)}
|
||||
{isBuildLoading ? 'Building...' : 'Build'}
|
||||
</DropdownMenuItem>
|
||||
|
||||
<DropdownMenuItem
|
||||
onClick={() => {
|
||||
if (onFirstInteraction) onFirstInteraction();
|
||||
onDeploy();
|
||||
}}
|
||||
disabled={isAnyLoading}
|
||||
className="gap-2"
|
||||
>
|
||||
{isDeployLoading ? (
|
||||
<Loader2 className="h-4 w-4 animate-spin" />
|
||||
) : (
|
||||
<CloudUpload className="h-4 w-4" />
|
||||
)}
|
||||
{isDeployLoading ? 'Deploying...' : 'Deploy'}
|
||||
</DropdownMenuItem>
|
||||
|
||||
<DropdownMenuSeparator />
|
||||
|
||||
<DropdownMenuItem
|
||||
onClick={() => setAISettingsOpen(true)}
|
||||
className="gap-2"
|
||||
>
|
||||
<Settings className="h-4 w-4" />
|
||||
AI Settings
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
{/* Dialogs */}
|
||||
<GitHistoryDialog
|
||||
projectId={projectId}
|
||||
open={gitHistoryOpen}
|
||||
onOpenChange={setGitHistoryOpen}
|
||||
/>
|
||||
|
||||
<AISettingsDialog
|
||||
open={aiSettingsOpen}
|
||||
onOpenChange={setAISettingsOpen}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -3,18 +3,17 @@ import { useSearchParams } from 'react-router-dom';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { Send, Settings, Play, CloudUpload, Loader2, MessageSquarePlus, Square } from 'lucide-react';
|
||||
import { Send, Square, Loader2 } from 'lucide-react';
|
||||
import { useAISettings } from '@/hooks/useAISettings';
|
||||
import { useFS } from '@/hooks/useFS';
|
||||
import { useJSRuntime } from '@/hooks/useJSRuntime';
|
||||
|
||||
import { useKeepAlive } from '@/hooks/useKeepAlive';
|
||||
import { useAIChat } from '@/hooks/useAIChat';
|
||||
import { ModelSelector } from '@/components/ModelSelector';
|
||||
import { copyDirectory } from '@/lib/copyFiles';
|
||||
import { generateSecretKey, getPublicKey, nip19 } from 'nostr-tools';
|
||||
import { bytesToHex } from 'nostr-tools/utils';
|
||||
|
||||
|
||||
import { AIMessageItem } from '@/components/AIMessageItem';
|
||||
import { GitHistoryDialog } from '@/components/ai/GitHistoryDialog';
|
||||
|
||||
import { TextEditorViewTool } from '@/lib/tools/TextEditorViewTool';
|
||||
import { TextEditorWriteTool } from '@/lib/tools/TextEditorWriteTool';
|
||||
import { TextEditorStrReplaceTool } from '@/lib/tools/TextEditorStrReplaceTool';
|
||||
@@ -25,26 +24,48 @@ import { BuildProjectTool } from '@/lib/tools/BuildProjectTool';
|
||||
import { toolToOpenAI } from '@/lib/tools/openai-adapter';
|
||||
import { Tool } from '@/lib/tools/Tool';
|
||||
import OpenAI from 'openai';
|
||||
import { buildProject } from "@/lib/build";
|
||||
|
||||
|
||||
interface ChatPaneProps {
|
||||
projectId: string;
|
||||
projectName: string;
|
||||
onNewChat?: () => void;
|
||||
onBuild?: () => void;
|
||||
onDeploy?: () => void;
|
||||
onFirstInteraction?: () => void;
|
||||
onLoadingChange?: (isLoading: boolean) => void;
|
||||
isLoading?: boolean;
|
||||
isBuildLoading?: boolean;
|
||||
isDeployLoading?: boolean;
|
||||
}
|
||||
|
||||
export function ChatPane({ projectId, projectName }: ChatPaneProps) {
|
||||
export function ChatPane({
|
||||
projectId,
|
||||
projectName,
|
||||
onNewChat,
|
||||
onBuild: _onBuild,
|
||||
onDeploy: _onDeploy,
|
||||
onFirstInteraction,
|
||||
onLoadingChange,
|
||||
isLoading: externalIsLoading,
|
||||
isBuildLoading: externalIsBuildLoading,
|
||||
isDeployLoading: externalIsDeployLoading
|
||||
}: ChatPaneProps) {
|
||||
const [input, setInput] = useState('');
|
||||
const [isBuildLoading, setIsBuildLoading] = useState(false);
|
||||
const [isDeployLoading, setIsDeployLoading] = useState(false);
|
||||
|
||||
|
||||
// Use external state if provided, otherwise default to false
|
||||
const isBuildLoading = externalIsBuildLoading || false;
|
||||
const isDeployLoading = externalIsDeployLoading || false;
|
||||
const scrollAreaRef = useRef<HTMLDivElement>(null);
|
||||
const { isConfigured, settings, addRecentlyUsedModel } = useAISettings();
|
||||
const [providerModel, setProviderModel] = useState(() => {
|
||||
// Initialize with first recently used model if available, otherwise empty
|
||||
return settings.recentlyUsedModels?.[0] || '';
|
||||
});
|
||||
const { fs: browserFS } = useFS();
|
||||
const { runtime } = useJSRuntime();
|
||||
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
const { fs: browserFS } = useFS();
|
||||
|
||||
// Initialize AI chat with tools
|
||||
const cwd = `/projects/${projectId}`;
|
||||
@@ -94,14 +115,16 @@ The project uses:
|
||||
|
||||
When creating new components or pages, follow the existing patterns in the codebase.`;
|
||||
|
||||
|
||||
|
||||
const {
|
||||
messages,
|
||||
streamingMessage,
|
||||
isLoading,
|
||||
isLoading: internalIsLoading,
|
||||
sendMessage,
|
||||
startGeneration,
|
||||
stopGeneration,
|
||||
startNewSession,
|
||||
startNewSession: internalStartNewSession,
|
||||
} = useAIChat({
|
||||
projectId,
|
||||
projectName,
|
||||
@@ -113,6 +136,16 @@ When creating new components or pages, follow the existing patterns in the codeb
|
||||
}
|
||||
});
|
||||
|
||||
// Use external loading state if provided, otherwise use internal state
|
||||
const isLoading = externalIsLoading !== undefined ? externalIsLoading : internalIsLoading;
|
||||
|
||||
// Notify parent of loading state changes
|
||||
useEffect(() => {
|
||||
if (onLoadingChange) {
|
||||
onLoadingChange(internalIsLoading);
|
||||
}
|
||||
}, [internalIsLoading, onLoadingChange]);
|
||||
|
||||
// Check for autostart parameter and trigger AI generation
|
||||
useEffect(() => {
|
||||
const autostart = searchParams.get('autostart');
|
||||
@@ -160,90 +193,7 @@ When creating new components or pages, follow the existing patterns in the codeb
|
||||
]
|
||||
});
|
||||
|
||||
const runBuild = async () => {
|
||||
if (isBuildLoading) return;
|
||||
|
||||
setIsBuildLoading(true);
|
||||
updateMetadata('Shakespeare', `Building ${projectName}...`);
|
||||
|
||||
const dist = await buildProject({
|
||||
fs: browserFS,
|
||||
projectPath: `/projects/${projectId}`,
|
||||
domParser: new DOMParser(),
|
||||
target: "esnext",
|
||||
});
|
||||
|
||||
console.log(dist);
|
||||
|
||||
// Delete all existing files in "dist" directory
|
||||
try {
|
||||
for (const file of await browserFS.readdir(`/projects/${projectId}/dist`)) {
|
||||
await browserFS.unlink(`/projects/${projectId}/dist/${file}`);
|
||||
}
|
||||
} catch {
|
||||
// Ignore errors (e.g., directory doesn't exist)
|
||||
}
|
||||
|
||||
await browserFS.mkdir(`/projects/${projectId}/dist`, { recursive: true });
|
||||
|
||||
for (const [path, contents] of Object.entries(dist)) {
|
||||
await browserFS.writeFile(`/projects/${projectId}/dist/${path}`, contents);
|
||||
}
|
||||
|
||||
setIsBuildLoading(false);
|
||||
};
|
||||
|
||||
const runDeploy = async () => {
|
||||
if (isDeployLoading) return;
|
||||
|
||||
setIsDeployLoading(true);
|
||||
updateMetadata('Shakespeare', `Deploying ${projectName}...`);
|
||||
try {
|
||||
const runtimeFS = await runtime.fs();
|
||||
|
||||
const sk = generateSecretKey();
|
||||
const pubkey = getPublicKey(sk);
|
||||
const npub = nip19.npubEncode(pubkey);
|
||||
|
||||
const projectUrl = `https://${npub}.nostrdeploy.com`;
|
||||
console.log('Running deploy for project:', projectId, 'at', projectUrl);
|
||||
|
||||
await runtimeFS.mkdir('dist', { recursive: true });
|
||||
|
||||
await runtimeFS.writeFile('.env.nostr-deploy.local', `# Nostr Deploy CLI Configuration
|
||||
# This file contains sensitive information - do not commit to version control
|
||||
|
||||
# Nostr Authentication
|
||||
NOSTR_PRIVATE_KEY=${bytesToHex(sk)}
|
||||
NOSTR_PUBLIC_KEY=${pubkey}
|
||||
NOSTR_RELAYS=wss://relay.nostr.band,wss://nostrue.com,wss://purplerelay.com,wss://relay.primal.net,wss://ditto.pub/relay
|
||||
|
||||
# Blossom File Storage
|
||||
BLOSSOM_SERVERS=https://cdn.hzrd149.com,https://blossom.primal.net,https://blossom.band,https://blossom.f7z.io
|
||||
|
||||
# Deployment Settings
|
||||
BASE_DOMAIN=nostrdeploy.com`);
|
||||
|
||||
// Copy "dist" files to runtime filesystem
|
||||
const distPath = `/projects/${projectId}/dist`;
|
||||
try {
|
||||
await copyDirectory(browserFS, runtimeFS, distPath, 'dist');
|
||||
console.log('Successfully copied dist to runtime');
|
||||
} catch (error) {
|
||||
console.error('Failed to copy dist to runtime:', error);
|
||||
return;
|
||||
}
|
||||
|
||||
const proc = await runtime.spawn('npx', ["-y", "nostr-deploy-cli", "deploy"]);
|
||||
await proc.exit;
|
||||
|
||||
console.log('Project deployed:', projectUrl);
|
||||
} catch (error) {
|
||||
console.error('Deploy failed:', error);
|
||||
} finally {
|
||||
setIsDeployLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (scrollAreaRef.current && (messages || streamingMessage)) {
|
||||
@@ -288,31 +238,22 @@ BASE_DOMAIN=nostrdeploy.com`);
|
||||
const handleFirstInteraction = () => {
|
||||
// This will be handled automatically by the useKeepAlive hook
|
||||
// when isLoading becomes true after user interaction
|
||||
if (onFirstInteraction) {
|
||||
onFirstInteraction();
|
||||
}
|
||||
};
|
||||
|
||||
const _startNewSession = () => {
|
||||
if (onNewChat) {
|
||||
onNewChat();
|
||||
} else {
|
||||
internalStartNewSession();
|
||||
}
|
||||
};
|
||||
|
||||
if (!isConfigured) {
|
||||
return (
|
||||
<div className="h-full flex flex-col">
|
||||
<div className="border-b bg-gradient-to-r from-primary/5 to-accent/5 px-4 py-3 flex justify-between items-center">
|
||||
<div>
|
||||
<h2 className="font-semibold bg-gradient-to-r from-primary to-accent bg-clip-text text-transparent">AI Assistant</h2>
|
||||
<p className="text-sm text-muted-foreground">Chat to build your project</p>
|
||||
</div>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="gap-2 hover:bg-primary/10 hover:border-primary/20"
|
||||
onClick={() => {
|
||||
// This will be handled by the AISettingsDialog component
|
||||
const event = new CustomEvent('openAISettings');
|
||||
window.dispatchEvent(event);
|
||||
}}
|
||||
>
|
||||
<Settings className="h-4 w-4" />
|
||||
Settings
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="flex-1 flex items-center justify-center bg-gradient-to-br from-primary/5 to-accent/5">
|
||||
<div className="text-center space-y-4 max-w-md mx-auto p-6">
|
||||
<div className="text-4xl mb-4">🤖</div>
|
||||
@@ -321,18 +262,9 @@ BASE_DOMAIN=nostrdeploy.com`);
|
||||
<p className="text-sm text-muted-foreground mb-4">
|
||||
Please configure your AI settings to start building with AI assistance.
|
||||
</p>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="gap-2 hover:bg-primary/10 hover:border-primary/20"
|
||||
onClick={() => {
|
||||
const event = new CustomEvent('openAISettings');
|
||||
window.dispatchEvent(event);
|
||||
}}
|
||||
>
|
||||
<Settings className="h-4 w-4" />
|
||||
Configure AI Settings
|
||||
</Button>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Use the menu in the top bar to access AI Settings.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -344,60 +276,6 @@ BASE_DOMAIN=nostrdeploy.com`);
|
||||
|
||||
return (
|
||||
<div className="h-full flex flex-col">
|
||||
<div className="border-b bg-gradient-to-r from-primary/5 to-accent/5 px-4 py-3 flex justify-between items-center">
|
||||
<div className="min-w-0 flex-1">
|
||||
<h2 className="font-semibold bg-gradient-to-r from-primary to-accent bg-clip-text text-transparent">AI Assistant</h2>
|
||||
<p className="text-sm text-muted-foreground hidden sm:block">Chat to build your project</p>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="gap-1 sm:gap-2 hover:bg-secondary/10 hover:border-secondary/20"
|
||||
onClick={startNewSession}
|
||||
disabled={isLoading}
|
||||
title="Start a new chat session"
|
||||
>
|
||||
<MessageSquarePlus className="h-4 w-4" />
|
||||
<span className="hidden sm:inline">New Chat</span>
|
||||
</Button>
|
||||
<GitHistoryDialog projectId={projectId} />
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="gap-1 sm:gap-2 hover:bg-primary/10 hover:border-primary/20"
|
||||
onClick={runBuild}
|
||||
onMouseDown={handleFirstInteraction}
|
||||
disabled={isBuildLoading || isDeployLoading || isLoading}
|
||||
>
|
||||
{isBuildLoading ? (
|
||||
<Loader2 className="h-4 w-4 animate-spin" />
|
||||
) : (
|
||||
<Play className="h-4 w-4" />
|
||||
)}
|
||||
<span className="hidden sm:inline">
|
||||
{isBuildLoading ? 'Building...' : 'Build'}
|
||||
</span>
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="gap-1 sm:gap-2 hover:bg-accent/10 hover:border-accent/20"
|
||||
onClick={runDeploy}
|
||||
onMouseDown={handleFirstInteraction}
|
||||
disabled={isDeployLoading || isBuildLoading || isLoading}
|
||||
>
|
||||
{isDeployLoading ? (
|
||||
<Loader2 className="h-4 w-4 animate-spin" />
|
||||
) : (
|
||||
<CloudUpload className="h-4 w-4" />
|
||||
)}
|
||||
<span className="hidden sm:inline">
|
||||
{isDeployLoading ? 'Deploying...' : 'Deploy'}
|
||||
</span>
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex-1 overflow-y-scroll overflow-x-hidden" ref={scrollAreaRef}>
|
||||
<div className="p-4 space-y-4">
|
||||
|
||||
@@ -28,13 +28,19 @@ interface GitCommit {
|
||||
|
||||
interface GitHistoryDialogProps {
|
||||
projectId: string;
|
||||
open?: boolean;
|
||||
onOpenChange?: (open: boolean) => void;
|
||||
}
|
||||
|
||||
export function GitHistoryDialog({ projectId }: GitHistoryDialogProps) {
|
||||
export function GitHistoryDialog({ projectId, open: controlledOpen, onOpenChange }: GitHistoryDialogProps) {
|
||||
const [commits, setCommits] = useState<GitCommit[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
const [internalOpen, setInternalOpen] = useState(false);
|
||||
|
||||
// Use controlled or internal state
|
||||
const isOpen = controlledOpen !== undefined ? controlledOpen : internalOpen;
|
||||
const setIsOpen = onOpenChange || setInternalOpen;
|
||||
const [isRollingBack, setIsRollingBack] = useState<string | null>(null);
|
||||
const [expandedCommits, setExpandedCommits] = useState<Set<string>>(new Set());
|
||||
const { fs } = useFS();
|
||||
@@ -280,16 +286,19 @@ ${commitsToRevert.map(c => {
|
||||
|
||||
return (
|
||||
<Dialog open={isOpen} onOpenChange={setIsOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="gap-1 sm:gap-2 hover:bg-secondary/10 hover:border-secondary/20"
|
||||
>
|
||||
<History className="h-4 w-4" />
|
||||
<span className="hidden sm:inline">History</span>
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
{/* Only show trigger if not controlled externally */}
|
||||
{controlledOpen === undefined && (
|
||||
<DialogTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="gap-1 sm:gap-2 hover:bg-secondary/10 hover:border-secondary/20"
|
||||
>
|
||||
<History className="h-4 w-4" />
|
||||
<span className="hidden sm:inline">History</span>
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
)}
|
||||
<DialogContent className="max-w-4xl max-h-[80vh]">
|
||||
<DialogHeader>
|
||||
<DialogTitle className="flex items-center gap-2">
|
||||
|
||||
+177
-6
@@ -9,8 +9,15 @@ import { ResizablePanelGroup, ResizablePanel, ResizableHandle } from '@/componen
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { ArrowLeft, MessageSquare, Eye, Code, Menu, Columns2 } from 'lucide-react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { AISettingsDialog } from '@/components/ai/AISettingsDialog';
|
||||
import { ActionsMenu } from '@/components/ActionsMenu';
|
||||
import { useIsMobile } from '@/hooks/useIsMobile';
|
||||
import { useFS } from '@/hooks/useFS';
|
||||
import { useJSRuntime } from '@/hooks/useJSRuntime';
|
||||
import { useKeepAlive } from '@/hooks/useKeepAlive';
|
||||
import { generateSecretKey, getPublicKey, nip19 } from 'nostr-tools';
|
||||
import { bytesToHex } from 'nostr-tools/utils';
|
||||
import { buildProject } from "@/lib/build";
|
||||
import { copyDirectory } from '@/lib/copyFiles';
|
||||
|
||||
export function ProjectView() {
|
||||
const { projectId } = useParams<{ projectId: string }>();
|
||||
@@ -18,9 +25,14 @@ export function ProjectView() {
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [activeTab, setActiveTab] = useState<'preview' | 'code'>('preview');
|
||||
const [mobileView, setMobileView] = useState<'chat' | 'preview' | 'code'>('chat');
|
||||
const [isBuildLoading, setIsBuildLoading] = useState(false);
|
||||
const [isDeployLoading, setIsDeployLoading] = useState(false);
|
||||
const [isAILoading, setIsAILoading] = useState(false);
|
||||
const projectsManager = useProjectsManager();
|
||||
const navigate = useNavigate();
|
||||
const isMobile = useIsMobile();
|
||||
const { fs: browserFS } = useFS();
|
||||
const { runtime } = useJSRuntime();
|
||||
const [isSidebarVisible, setIsSidebarVisible] = useState(() => {
|
||||
// Check if we're on mobile immediately to set correct initial state
|
||||
if (typeof window !== 'undefined') {
|
||||
@@ -29,6 +41,20 @@ export function ProjectView() {
|
||||
return false; // Default to closed for SSR
|
||||
});
|
||||
|
||||
// Keep-alive functionality to prevent tab throttling during AI processing
|
||||
const { updateMetadata } = useKeepAlive({
|
||||
enabled: isAILoading || isBuildLoading || isDeployLoading,
|
||||
title: 'Shakespeare',
|
||||
artist: project ? `Working on ${project.name}...` : 'Working...',
|
||||
artwork: [
|
||||
{
|
||||
src: '/favicon.png',
|
||||
sizes: '512x512',
|
||||
type: 'image/png'
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
const loadProject = useCallback(async () => {
|
||||
if (!projectId) return;
|
||||
|
||||
@@ -46,6 +72,111 @@ export function ProjectView() {
|
||||
loadProject();
|
||||
}, [loadProject]);
|
||||
|
||||
const runBuild = async () => {
|
||||
if (isBuildLoading || !project || !browserFS) return;
|
||||
|
||||
setIsBuildLoading(true);
|
||||
updateMetadata('Shakespeare', `Building ${project.name}...`);
|
||||
|
||||
try {
|
||||
const dist = await buildProject({
|
||||
fs: browserFS,
|
||||
projectPath: `/projects/${project.id}`,
|
||||
domParser: new DOMParser(),
|
||||
target: "esnext",
|
||||
});
|
||||
|
||||
console.log(dist);
|
||||
|
||||
// Delete all existing files in "dist" directory
|
||||
try {
|
||||
for (const file of await browserFS.readdir(`/projects/${project.id}/dist`)) {
|
||||
await browserFS.unlink(`/projects/${project.id}/dist/${file}`);
|
||||
}
|
||||
} catch {
|
||||
// Ignore errors (e.g., directory doesn't exist)
|
||||
}
|
||||
|
||||
await browserFS.mkdir(`/projects/${project.id}/dist`, { recursive: true });
|
||||
|
||||
for (const [path, contents] of Object.entries(dist)) {
|
||||
await browserFS.writeFile(`/projects/${project.id}/dist/${path}`, contents);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Build failed:', error);
|
||||
} finally {
|
||||
setIsBuildLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const runDeploy = async () => {
|
||||
if (isDeployLoading || !project || !browserFS || !runtime) return;
|
||||
|
||||
setIsDeployLoading(true);
|
||||
updateMetadata('Shakespeare', `Deploying ${project.name}...`);
|
||||
|
||||
try {
|
||||
const runtimeFS = await runtime.fs();
|
||||
|
||||
const sk = generateSecretKey();
|
||||
const pubkey = getPublicKey(sk);
|
||||
const npub = nip19.npubEncode(pubkey);
|
||||
|
||||
const projectUrl = `https://${npub}.nostrdeploy.com`;
|
||||
console.log('Running deploy for project:', project.id, 'at', projectUrl);
|
||||
|
||||
await runtimeFS.mkdir('dist', { recursive: true });
|
||||
|
||||
await runtimeFS.writeFile('.env.nostr-deploy.local', `# Nostr Deploy CLI Configuration
|
||||
# This file contains sensitive information - do not commit to version control
|
||||
|
||||
# Nostr Authentication
|
||||
NOSTR_PRIVATE_KEY=${bytesToHex(sk)}
|
||||
NOSTR_PUBLIC_KEY=${pubkey}
|
||||
NOSTR_RELAYS=wss://relay.nostr.band,wss://nostrue.com,wss://purplerelay.com,wss://relay.primal.net,wss://ditto.pub/relay
|
||||
|
||||
# Blossom File Storage
|
||||
BLOSSOM_SERVERS=https://cdn.hzrd149.com,https://blossom.primal.net,https://blossom.band,https://blossom.f7z.io
|
||||
|
||||
# Deployment Settings
|
||||
BASE_DOMAIN=nostrdeploy.com`);
|
||||
|
||||
// Copy "dist" files to runtime filesystem
|
||||
const distPath = `/projects/${project.id}/dist`;
|
||||
try {
|
||||
await copyDirectory(browserFS, runtimeFS, distPath, 'dist');
|
||||
console.log('Successfully copied dist to runtime');
|
||||
} catch (error) {
|
||||
console.error('Failed to copy dist to runtime:', error);
|
||||
return;
|
||||
}
|
||||
|
||||
const proc = await runtime.spawn('npx', ["-y", "nostr-deploy-cli", "deploy"]);
|
||||
await proc.exit;
|
||||
|
||||
console.log('Project deployed:', projectUrl);
|
||||
} catch (error) {
|
||||
console.error('Deploy failed:', error);
|
||||
} finally {
|
||||
setIsDeployLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleNewChat = () => {
|
||||
// This will be handled by the ChatPane's internal logic
|
||||
console.log('New chat requested');
|
||||
};
|
||||
|
||||
const handleAILoadingChange = (loading: boolean) => {
|
||||
setIsAILoading(loading);
|
||||
};
|
||||
|
||||
// Handle first user interaction to enable audio context
|
||||
const handleFirstInteraction = () => {
|
||||
// This will be handled automatically by the useKeepAlive hook
|
||||
// when isAILoading becomes true after user interaction
|
||||
};
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="min-h-screen bg-background flex items-center justify-center">
|
||||
@@ -85,7 +216,16 @@ export function ProjectView() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<AISettingsDialog />
|
||||
<ActionsMenu
|
||||
projectId={project.id}
|
||||
onNewChat={handleNewChat}
|
||||
onBuild={runBuild}
|
||||
onDeploy={runDeploy}
|
||||
isLoading={isAILoading}
|
||||
isBuildLoading={isBuildLoading}
|
||||
isDeployLoading={isDeployLoading}
|
||||
onFirstInteraction={handleFirstInteraction}
|
||||
/>
|
||||
</header>
|
||||
|
||||
{/* Mobile Sidebar Overlay */}
|
||||
@@ -117,7 +257,18 @@ export function ProjectView() {
|
||||
|
||||
<div className="flex-1 overflow-hidden">
|
||||
{mobileView === 'chat' && (
|
||||
<ChatPane projectId={project.id} projectName={project.name} />
|
||||
<ChatPane
|
||||
projectId={project.id}
|
||||
projectName={project.name}
|
||||
onNewChat={handleNewChat}
|
||||
onBuild={runBuild}
|
||||
onDeploy={runDeploy}
|
||||
onFirstInteraction={handleFirstInteraction}
|
||||
onLoadingChange={handleAILoadingChange}
|
||||
isLoading={isAILoading}
|
||||
isBuildLoading={isBuildLoading}
|
||||
isDeployLoading={isDeployLoading}
|
||||
/>
|
||||
)}
|
||||
{(mobileView === 'preview' || mobileView === 'code') && (
|
||||
<PreviewPane
|
||||
@@ -212,16 +363,36 @@ export function ProjectView() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Right side - AI Settings */}
|
||||
{/* Right side - Actions Menu */}
|
||||
<div className="flex items-center gap-2">
|
||||
<AISettingsDialog />
|
||||
<ActionsMenu
|
||||
projectId={project.id}
|
||||
onNewChat={handleNewChat}
|
||||
onBuild={runBuild}
|
||||
onDeploy={runDeploy}
|
||||
isLoading={isAILoading}
|
||||
isBuildLoading={isBuildLoading}
|
||||
isDeployLoading={isDeployLoading}
|
||||
onFirstInteraction={handleFirstInteraction}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Chat Content */}
|
||||
<div className="flex-1 overflow-hidden">
|
||||
<ChatPane projectId={project.id} projectName={project.name} />
|
||||
<ChatPane
|
||||
projectId={project.id}
|
||||
projectName={project.name}
|
||||
onNewChat={handleNewChat}
|
||||
onBuild={runBuild}
|
||||
onDeploy={runDeploy}
|
||||
onFirstInteraction={handleFirstInteraction}
|
||||
onLoadingChange={handleAILoadingChange}
|
||||
isLoading={isAILoading}
|
||||
isBuildLoading={isBuildLoading}
|
||||
isDeployLoading={isDeployLoading}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</ResizablePanel>
|
||||
|
||||
Reference in new issue
Block a user