diff --git a/src/components/Act1Dialog.test.tsx b/src/components/Act1Dialog.test.tsx new file mode 100644 index 00000000..ee953390 --- /dev/null +++ b/src/components/Act1Dialog.test.tsx @@ -0,0 +1,181 @@ +import { describe, it, expect, beforeEach, vi } from 'vitest'; +import { render, screen, fireEvent, waitFor } from '@testing-library/react'; +import { TestApp } from '@/test/TestApp'; +import { Act1Dialog } from './Act1Dialog'; + +// Mock localStorage +const mockLocalStorage = { + getItem: vi.fn(), + setItem: vi.fn(), + removeItem: vi.fn(), + clear: vi.fn(), +}; + +Object.defineProperty(window, 'localStorage', { + value: mockLocalStorage, +}); + +// Mock window.open +Object.defineProperty(window, 'open', { + value: vi.fn(), +}); + +describe('Act1Dialog', () => { + beforeEach(() => { + vi.clearAllMocks(); + }); + + it('renders welcome step correctly', () => { + render( + + {}} /> + + ); + + expect(screen.getByText(/Welcome to Shakespeare: Act 2!/)).toBeInTheDocument(); + expect(screen.getByText('Welcome to Act 2!')).toBeInTheDocument(); + expect(screen.getByText("What's Changed")).toBeInTheDocument(); + expect(screen.getByText('Enhanced AI Capabilities')).toBeInTheDocument(); + expect(screen.getByText('Improved Git Integration')).toBeInTheDocument(); + expect(screen.getByText('Project Import/Export')).toBeInTheDocument(); + expect(screen.getByText('Act 2 is in Development')).toBeInTheDocument(); + expect(screen.getByText('Configure Act 2')).toBeInTheDocument(); + }); + + it('navigates to migration step when Configure Act 2 is clicked', async () => { + render( + + {}} /> + + ); + + const configureButton = screen.getByText('Configure Act 2'); + fireEvent.click(configureButton); + + await waitFor(() => { + expect(screen.getByText('Migrating Your Projects')).toBeInTheDocument(); + }); + + expect(screen.getByText('Your Act 1 Projects & Credits')).toBeInTheDocument(); + expect(screen.getByText('Access Act 1')).toBeInTheDocument(); + expect(screen.getByText('Export from Act 1')).toBeInTheDocument(); + expect(screen.getByText('Import to Act 2')).toBeInTheDocument(); + expect(screen.getByText('Your Credits')).toBeInTheDocument(); + }); + + it('navigates to conclusion step when Continue is clicked', async () => { + render( + + {}} /> + + ); + + // Navigate to migration step first + const configureButton = screen.getByText('Configure Act 2'); + fireEvent.click(configureButton); + + await waitFor(() => { + expect(screen.getByText('Continue')).toBeInTheDocument(); + }); + + // Click continue to go to conclusion + const continueButton = screen.getByText('Continue'); + fireEvent.click(continueButton); + + await waitFor(() => { + expect(screen.getByText('Start Building in Act 2')).toBeInTheDocument(); + }); + + expect(screen.getByText('Remember: You can always access Act 1 at')).toBeInTheDocument(); + }); + + it('opens Act 1 in new tab when Visit Act 1 is clicked', async () => { + render( + + {}} /> + + ); + + // Navigate to migration step + const configureButton = screen.getByText('Configure Act 2'); + fireEvent.click(configureButton); + + await waitFor(() => { + expect(screen.getByText('Visit Act 1')).toBeInTheDocument(); + }); + + const visitAct1Button = screen.getByText('Visit Act 1'); + fireEvent.click(visitAct1Button); + + expect(window.open).toHaveBeenCalledWith('https://act1.shakespeare.diy', '_blank'); + }); + + it('removes selectedNSPAddr from localStorage when dialog is finished', async () => { + const onOpenChange = vi.fn(); + + render( + + + + ); + + // Navigate through all steps to conclusion + const configureButton = screen.getByText('Configure Act 2'); + fireEvent.click(configureButton); + + await waitFor(() => { + expect(screen.getByText('Continue')).toBeInTheDocument(); + }); + + const continueButton = screen.getByText('Continue'); + fireEvent.click(continueButton); + + await waitFor(() => { + expect(screen.getByText('Start Building in Act 2')).toBeInTheDocument(); + }); + + const finishButton = screen.getByText('Start Building in Act 2'); + fireEvent.click(finishButton); + + expect(mockLocalStorage.removeItem).toHaveBeenCalledWith('selectedNSPAddr'); + expect(onOpenChange).toHaveBeenCalledWith(false); + }); + + it('allows navigation back through steps', async () => { + render( + + {}} /> + + ); + + // Go to migration step + const configureButton = screen.getByText('Configure Act 2'); + fireEvent.click(configureButton); + + await waitFor(() => { + expect(screen.getByText('Migrating Your Projects')).toBeInTheDocument(); + }); + + // Go to conclusion step + const continueButton = screen.getByText('Continue'); + fireEvent.click(continueButton); + + await waitFor(() => { + expect(screen.getByText('Start Building in Act 2')).toBeInTheDocument(); + }); + + // Go back to migration step + const backButtons = screen.getAllByRole('button'); + const backButton = backButtons.find(button => + button.querySelector('svg') && button.getAttribute('class')?.includes('ghost') + ); + + if (backButton) { + fireEvent.click(backButton); + + await waitFor(() => { + expect(screen.getByText('Migrating Your Projects')).toBeInTheDocument(); + }); + } + }); +}); \ No newline at end of file diff --git a/src/components/Act1Dialog.tsx b/src/components/Act1Dialog.tsx new file mode 100644 index 00000000..508c883c --- /dev/null +++ b/src/components/Act1Dialog.tsx @@ -0,0 +1,331 @@ +import { useState, useEffect } from 'react'; +import { ArrowRight, ArrowLeft, Download, Upload, ExternalLink, Sparkles } from 'lucide-react'; +import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'; +import { Button } from '@/components/ui/button'; +import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; +import { Badge } from '@/components/ui/badge'; +import { useAISettings } from '@/hooks/useAISettings'; +import { useLocalStorage } from '@/hooks/useLocalStorage'; + +interface Act1DialogProps { + open: boolean; + onOpenChange: (open: boolean) => void; +} + +type DialogStep = 'welcome' | 'migration' | 'conclusion'; + +const SHAKESPEARE_PROVIDER = { + id: "shakespeare", + baseURL: "https://ai.shakespeare.diy/v1", + nostr: true, +}; + +const MKSTACK_NSP_ADDR = '31999:4bcaa7b5606e3c14df05cd497e588f5d3fe559b4e9a425e8b418a43af1ffb015:mkstack'; +const MKSTACK_NSP_FREE_ADDR = '31999:8c68ce13a4a4a178ba95cbca8a759b31fe95c4b6e61fa1a7f6ad2e751458f49:mkstack'; + +export function Act1Dialog({ open, onOpenChange }: Act1DialogProps) { + const [step, setStep] = useState('welcome'); + const [isSettingUp, setIsSettingUp] = useState(false); + const { setProvider, updateSettings } = useAISettings(); + + // Get the selectedNSPAddr from localStorage + const [selectedNSPAddr] = useLocalStorage('selectedNSPAddr', null); + + const handleGetStarted = async () => { + setIsSettingUp(true); + + try { + // Add Shakespeare provider to their config + setProvider(SHAKESPEARE_PROVIDER); + + // Configure recently used models based on their Act 1 NSP + if (selectedNSPAddr === MKSTACK_NSP_ADDR) { + // MKStack NSP - set to shakespeare model + updateSettings({ recentlyUsedModels: ['shakespeare/shakespeare'] }); + } else if (selectedNSPAddr === MKSTACK_NSP_FREE_ADDR) { + // MKStack NSP Free - set to tybalt model + updateSettings({ recentlyUsedModels: ['shakespeare/tybalt'] }); + } + + // Move to migration step + setStep('migration'); + } catch (error) { + console.error('Failed to configure Shakespeare provider:', error); + } finally { + setIsSettingUp(false); + } + }; + + const handleContinue = () => { + setStep('conclusion'); + }; + + const handleFinish = () => { + // Remove the selectedNSPAddr from localStorage + localStorage.removeItem('selectedNSPAddr'); + onOpenChange(false); + }; + + const handleVisitAct1 = () => { + window.open('https://act1.shakespeare.diy', '_blank'); + }; + + // Reset state when dialog opens/closes + useEffect(() => { + if (open) { + setStep('welcome'); + setIsSettingUp(false); + } + }, [open]); + + return ( + + + + + {step === 'migration' && ( + + )} + {step === 'conclusion' && ( + + )} + + {step === 'welcome' && 'Welcome to Shakespeare: Act 2! 🎭'} + {step === 'migration' && 'Migrating Your Projects'} + {step === 'conclusion' && "You're All Set!"} + + + + +
+ {step === 'welcome' && ( +
+
🎭✨
+
+

+ Welcome to Act 2! +

+

+ We're excited to see you again! Shakespeare has been completely rebuilt + with new features, improved performance, and a better development experience. +

+
+ + + + + 🔄 + What's Changed + + + +
+ New +
+

Enhanced AI Capabilities

+

More powerful models and better code generation

+
+
+
+ New +
+

Improved Git Integration

+

Better version control with credential management

+
+
+
+ New +
+

Project Import/Export

+

Easily migrate your projects between versions

+
+
+
+
+ +
+
+ ⚠️ +
+

Act 2 is in Development

+

+ While we're working hard to make Act 2 stable, you may encounter bugs. + Your Act 1 projects remain safe and accessible. +

+
+
+
+ + +
+ )} + + {step === 'migration' && ( +
+
+

Your Act 1 Projects & Credits

+

+ All your Act 1 projects and credits are safe and still accessible. + Here's how to work with them in Act 2. +

+
+ +
+ + + + + Access Act 1 + + + +

+ Your original Shakespeare (Act 1) is still available with all your projects and data intact. +

+ +
+
+ + + + + + Export from Act 1 + + + +

+ In Act 1, you can export your projects as ZIP files using the project menu or settings. +

+
+ 💡 Tip: Export projects you want to continue working on in Act 2 +
+
+
+ + + + + + Import to Act 2 + + + +

+ In Act 2, use the "Import Project" option in the sidebar to upload your exported ZIP files. +

+
+ 💡 Tip: Look for the import button in the project sidebar +
+
+
+ + + + + 💳 + Your Credits + + + +

+ Your Act 1 credits are still available through the Shakespeare AI provider. + We've automatically configured this for you! +

+ + Credits Available + +
+
+
+ +
+ +
+
+ )} + + {step === 'conclusion' && ( +
+
🎉
+
+

Welcome to the Future!

+

+ You're all set up with Act 2! Your AI assistant is configured + and ready to help you build amazing Nostr applications. +

+
+ +
+

+ "Create a decentralized social media app with custom feeds and real-time messaging..." +

+
+ +
+ + +
+ Remember: You can always access Act 1 at{' '} + +
+
+
+ )} +
+
+
+ ); +} \ No newline at end of file diff --git a/src/pages/Index.tsx b/src/pages/Index.tsx index a0c39678..f15589b1 100644 --- a/src/pages/Index.tsx +++ b/src/pages/Index.tsx @@ -10,6 +10,7 @@ import { useAISettings } from '@/hooks/useAISettings'; import { useToast } from '@/hooks/useToast'; import { AppLayout } from '@/components/AppLayout'; import { OnboardingDialog } from '@/components/OnboardingDialog'; +import { Act1Dialog } from '@/components/Act1Dialog'; import { DotAI } from '@/lib/DotAI'; import { parseProviderModel } from '@/lib/parseProviderModel'; import type { AIMessage } from '@/lib/SessionManager'; @@ -29,6 +30,7 @@ export default function Index() { const [isCreating, setIsCreating] = useState(false); const [storedPrompt, setStoredPrompt] = useLocalStorage('shakespeare-draft-prompt', ''); const [showOnboarding, setShowOnboarding] = useState(false); + const [showAct1Dialog, setShowAct1Dialog] = useState(false); const navigate = useNavigate(); const projectsManager = useProjectsManager(); const { fs } = useFS(); @@ -99,6 +101,13 @@ export default function Index() { } }, [storedPrompt]); + // Check for Act 1 users and show welcome dialog + useEffect(() => { + if (localStorage.getItem('selectedNSPAddr')) { + setShowAct1Dialog(true); + } + }, []); + // Sync prompt with local storage const handlePromptChange = (e: React.ChangeEvent) => { const newPrompt = e.target.value; @@ -383,6 +392,12 @@ export default function Index() { open={showOnboarding} onOpenChange={setShowOnboarding} /> + + {/* Act 1 Welcome Dialog */} + ); } \ No newline at end of file