mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
161 lines
5.8 KiB
TypeScript
161 lines
5.8 KiB
TypeScript
import { useState, useEffect, useCallback } from 'react';
|
|
import { useNavigate } from 'react-router-dom';
|
|
import { type Project } from '@/lib/ProjectsManager';
|
|
import { useProjectsManager } from '@/hooks/useProjectsManager';
|
|
import { Button } from '@/components/ui/button';
|
|
import { Textarea } from '@/components/ui/textarea';
|
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
|
import { Skeleton } from '@/components/ui/skeleton';
|
|
import { Plus, Folder } from 'lucide-react';
|
|
import { useSeoMeta } from '@unhead/react';
|
|
|
|
export default function Index() {
|
|
const [prompt, setPrompt] = useState('');
|
|
const [projects, setProjects] = useState<Project[]>([]);
|
|
const [isLoading, setIsLoading] = useState(true);
|
|
const [isCreating, setIsCreating] = useState(false);
|
|
const navigate = useNavigate();
|
|
const projectsManager = useProjectsManager();
|
|
|
|
useSeoMeta({
|
|
title: 'Shakespeare - AI-Powered Nostr Development',
|
|
description: 'Build custom Nostr websites with AI assistance using Shakespeare, an AI-powered development environment.',
|
|
});
|
|
|
|
const loadProjects = useCallback(async () => {
|
|
try {
|
|
await projectsManager.init();
|
|
const projectList = await projectsManager.getProjects();
|
|
setProjects(projectList);
|
|
} catch (error) {
|
|
console.error('Failed to load projects:', error);
|
|
} finally {
|
|
setIsLoading(false);
|
|
}
|
|
}, [projectsManager]);
|
|
|
|
useEffect(() => {
|
|
loadProjects();
|
|
}, [loadProjects]);
|
|
|
|
const handleCreateProject = async () => {
|
|
if (!prompt.trim()) return;
|
|
|
|
setIsCreating(true);
|
|
try {
|
|
const project = await projectsManager.createProject(prompt.trim());
|
|
navigate(`/project/${project.id}`);
|
|
} catch (error) {
|
|
console.error('Failed to create project:', error);
|
|
} finally {
|
|
setIsCreating(false);
|
|
}
|
|
};
|
|
|
|
const handleProjectClick = (projectId: string) => {
|
|
navigate(`/project/${projectId}`);
|
|
};
|
|
|
|
return (
|
|
<div className="min-h-screen bg-background">
|
|
<div className="container mx-auto px-4 py-8">
|
|
<div className="max-w-4xl mx-auto">
|
|
<div className="text-center mb-12">
|
|
<h1 className="text-4xl font-bold mb-4">Shakespeare</h1>
|
|
<p className="text-xl text-muted-foreground mb-2">
|
|
Build custom Nostr websites with AI assistance
|
|
</p>
|
|
<p className="text-sm text-muted-foreground">
|
|
<a href="https://soapbox.pub/mkstack" className="hover:underline">
|
|
Vibed with MKStack
|
|
</a>
|
|
</p>
|
|
</div>
|
|
|
|
<div className="mb-12">
|
|
<Card>
|
|
<CardHeader>
|
|
<CardTitle>Create a New Project</CardTitle>
|
|
<CardDescription>
|
|
Describe what kind of Nostr website you want to build
|
|
</CardDescription>
|
|
</CardHeader>
|
|
<CardContent className="space-y-4">
|
|
<Textarea
|
|
placeholder="e.g., Create a farming equipment marketplace for local farmers to buy and sell tractors, tools, and supplies..."
|
|
value={prompt}
|
|
onChange={(e) => setPrompt(e.target.value)}
|
|
className="min-h-[100px]"
|
|
disabled={isCreating}
|
|
/>
|
|
<Button
|
|
onClick={handleCreateProject}
|
|
disabled={!prompt.trim() || isCreating}
|
|
className="w-full"
|
|
size="lg"
|
|
>
|
|
{isCreating ? (
|
|
<>
|
|
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-white mr-2"></div>
|
|
Creating Project...
|
|
</>
|
|
) : (
|
|
<>
|
|
<Plus className="mr-2 h-4 w-4" />
|
|
Create Project
|
|
</>
|
|
)}
|
|
</Button>
|
|
</CardContent>
|
|
</Card>
|
|
</div>
|
|
|
|
<div>
|
|
<h2 className="text-2xl font-semibold mb-6">Your Projects</h2>
|
|
|
|
{isLoading ? (
|
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
|
{[...Array(6)].map((_, i) => (
|
|
<Card key={i}>
|
|
<CardContent className="p-6">
|
|
<Skeleton className="h-4 w-3/4 mb-2" />
|
|
<Skeleton className="h-3 w-1/2" />
|
|
</CardContent>
|
|
</Card>
|
|
))}
|
|
</div>
|
|
) : projects.length === 0 ? (
|
|
<div className="text-center py-12">
|
|
<Folder className="mx-auto h-12 w-12 text-muted-foreground mb-4" />
|
|
<p className="text-muted-foreground">No projects yet. Create your first project above!</p>
|
|
</div>
|
|
) : (
|
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
|
{projects.map((project) => (
|
|
<Card
|
|
key={project.id}
|
|
className="cursor-pointer hover:shadow-lg transition-shadow"
|
|
onClick={() => handleProjectClick(project.id)}
|
|
>
|
|
<CardHeader>
|
|
<CardTitle className="text-lg">{project.name}</CardTitle>
|
|
<CardDescription>
|
|
Created {project.createdAt.toLocaleDateString()}
|
|
</CardDescription>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<p className="text-sm text-muted-foreground">
|
|
Last modified {project.lastModified.toLocaleDateString()}
|
|
</p>
|
|
</CardContent>
|
|
</Card>
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|