mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
Merge in from upstream and resolve conflicts
This commit is contained in:
commit
5e352e60e9
147 files changed
+10132
-3041
No files matched your search
@@ -11,10 +11,13 @@ vi.mock('@/hooks/useCurrentUser', () => ({
|
||||
|
||||
vi.mock('@/hooks/useAISettings', () => ({
|
||||
useAISettings: vi.fn(() => ({
|
||||
settings: { providers: {} },
|
||||
addProvider: vi.fn(),
|
||||
settings: { providers: [] },
|
||||
setProvider: vi.fn(),
|
||||
removeProvider: vi.fn(),
|
||||
updateProvider: vi.fn(),
|
||||
setProviders: vi.fn(),
|
||||
updateSettings: vi.fn(),
|
||||
addRecentlyUsedModel: vi.fn(),
|
||||
isConfigured: false,
|
||||
})),
|
||||
}));
|
||||
|
||||
|
||||
+213
-117
@@ -1,11 +1,29 @@
|
||||
import { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Check, Bot, ArrowLeft, Trash2 } from 'lucide-react';
|
||||
import { Check, Bot, ArrowLeft, Trash2, GripVertical } from 'lucide-react';
|
||||
import {
|
||||
DndContext,
|
||||
closestCenter,
|
||||
KeyboardSensor,
|
||||
PointerSensor,
|
||||
useSensor,
|
||||
useSensors,
|
||||
type DragEndEvent,
|
||||
} from '@dnd-kit/core';
|
||||
import {
|
||||
arrayMove,
|
||||
SortableContext,
|
||||
sortableKeyboardCoordinates,
|
||||
verticalListSortingStrategy,
|
||||
} from '@dnd-kit/sortable';
|
||||
import {
|
||||
useSortable,
|
||||
} from '@dnd-kit/sortable';
|
||||
import { CSS } from '@dnd-kit/utilities';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { PasswordInput } from '@/components/ui/password-input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion';
|
||||
import { CreditsBadge } from '@/components/CreditsBadge';
|
||||
import { CreditsDialog } from '@/components/CreditsDialog';
|
||||
@@ -14,7 +32,7 @@ import { useAISettings } from '@/hooks/useAISettings';
|
||||
import { useIsMobile } from '@/hooks/useIsMobile';
|
||||
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||
import { useNavigate, Link } from 'react-router-dom';
|
||||
import type { AIConnection } from '@/contexts/AISettingsContext';
|
||||
import type { AIProvider } from '@/contexts/AISettingsContext';
|
||||
|
||||
interface PresetProvider {
|
||||
id: string;
|
||||
@@ -55,12 +73,6 @@ const PRESET_PROVIDERS: PresetProvider[] = [
|
||||
baseURL: "https://api.z.ai/api/paas/v4",
|
||||
apiKeysURL: "https://z.ai/manage-apikey/apikey-list",
|
||||
},
|
||||
{
|
||||
id: "moonshot",
|
||||
name: "Moonshot",
|
||||
baseURL: "https://api.moonshot.ai/v1",
|
||||
apiKeysURL: "https://platform.moonshot.ai/console/api-keys",
|
||||
},
|
||||
{
|
||||
id: "openai",
|
||||
name: "OpenAI",
|
||||
@@ -81,9 +93,124 @@ const PRESET_PROVIDERS: PresetProvider[] = [
|
||||
},
|
||||
];
|
||||
|
||||
interface SortableProviderItemProps {
|
||||
provider: AIProvider;
|
||||
preset?: PresetProvider;
|
||||
onRemove: (id: string) => void;
|
||||
onSetProvider: (provider: AIProvider) => void;
|
||||
onOpenCreditsDialog: (providerId: string) => void;
|
||||
showDragHandle: boolean;
|
||||
}
|
||||
|
||||
function SortableProviderItem({ provider, preset, onRemove, onSetProvider, onOpenCreditsDialog, showDragHandle }: SortableProviderItemProps) {
|
||||
const { t } = useTranslation();
|
||||
const {
|
||||
attributes,
|
||||
listeners,
|
||||
setNodeRef,
|
||||
transform,
|
||||
transition,
|
||||
isDragging,
|
||||
} = useSortable({ id: provider.id });
|
||||
|
||||
const style = {
|
||||
transform: CSS.Transform.toString(transform),
|
||||
transition,
|
||||
opacity: isDragging ? 0.5 : 1,
|
||||
};
|
||||
|
||||
return (
|
||||
<AccordionItem
|
||||
ref={setNodeRef}
|
||||
style={style}
|
||||
value={provider.id}
|
||||
className="border rounded-lg"
|
||||
>
|
||||
<AccordionTrigger className="px-4 py-3 hover:no-underline">
|
||||
<div className="flex items-center justify-between w-full mr-3">
|
||||
<div className="flex items-center gap-2">
|
||||
{showDragHandle && (
|
||||
<div
|
||||
{...attributes}
|
||||
{...listeners}
|
||||
className="cursor-grab active:cursor-grabbing p-1 -ml-1 text-muted-foreground hover:text-foreground"
|
||||
>
|
||||
<GripVertical className="h-4 w-4" />
|
||||
</div>
|
||||
)}
|
||||
<span className="font-medium">
|
||||
{preset?.name || provider.id}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<CreditsBadge
|
||||
provider={provider}
|
||||
onOpenDialog={() => onOpenCreditsDialog(provider.id)}
|
||||
/>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
onRemove(provider.id);
|
||||
}}
|
||||
className="h-8 w-8 p-0 text-muted-foreground hover:text-destructive hover:bg-transparent"
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-4 pb-4">
|
||||
<div className="space-y-3">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor={`${provider.id}-baseURL`}>{t('baseUrl')}</Label>
|
||||
<Input
|
||||
id={`${provider.id}-baseURL`}
|
||||
placeholder="https://api.example.com/v1"
|
||||
value={provider.baseURL || ''}
|
||||
onChange={(e) => onSetProvider({ ...provider, baseURL: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor={`${provider.id}-auth`}>{t('authentication')}</Label>
|
||||
<Select
|
||||
value={provider.nostr ? 'nostr' : 'api-key'}
|
||||
onValueChange={(value: 'api-key' | 'nostr') => onSetProvider({
|
||||
...provider,
|
||||
nostr: value === 'nostr' || undefined,
|
||||
apiKey: value === 'nostr' ? undefined : provider.apiKey
|
||||
})}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="api-key">{t('apiKey')}</SelectItem>
|
||||
<SelectItem value="nostr">Nostr</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
{!provider.nostr && (
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor={`${provider.id}-apiKey`}>{t('apiKey')}</Label>
|
||||
<PasswordInput
|
||||
id={`${provider.id}-apiKey`}
|
||||
placeholder={t('enterApiKey')}
|
||||
value={provider.apiKey || ''}
|
||||
onChange={(e) => onSetProvider({ ...provider, apiKey: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
);
|
||||
}
|
||||
|
||||
export function AISettings() {
|
||||
const { t } = useTranslation();
|
||||
const { settings, addProvider, removeProvider, updateProvider } = useAISettings();
|
||||
const { settings, setProvider, removeProvider, setProviders } = useAISettings();
|
||||
const isMobile = useIsMobile();
|
||||
const navigate = useNavigate();
|
||||
const { user } = useCurrentUser();
|
||||
@@ -94,10 +221,18 @@ export function AISettings() {
|
||||
const [presetApiKeys, setPresetApiKeys] = useState<Record<string, string>>({});
|
||||
const [activeCreditsDialog, setActiveCreditsDialog] = useState<string | null>(null);
|
||||
|
||||
const sensors = useSensors(
|
||||
useSensor(PointerSensor),
|
||||
useSensor(KeyboardSensor, {
|
||||
coordinateGetter: sortableKeyboardCoordinates,
|
||||
})
|
||||
);
|
||||
|
||||
const handleAddPresetProvider = (preset: PresetProvider) => {
|
||||
const apiKey = presetApiKeys[preset.id] as string | undefined;
|
||||
|
||||
const newProvider: AIConnection = {
|
||||
const newProvider: AIProvider = {
|
||||
id: preset.id,
|
||||
baseURL: preset.baseURL,
|
||||
};
|
||||
|
||||
@@ -109,7 +244,7 @@ export function AISettings() {
|
||||
}
|
||||
|
||||
// Auto-save: Add provider immediately to persistent storage
|
||||
addProvider(preset.id, newProvider);
|
||||
setProvider(newProvider);
|
||||
|
||||
// Clear the API key input for this preset
|
||||
setPresetApiKeys(prev => ({
|
||||
@@ -121,14 +256,15 @@ export function AISettings() {
|
||||
const handleAddCustomProvider = () => {
|
||||
if (!customProviderName.trim() || !customBaseURL.trim()) return;
|
||||
|
||||
const newProvider: AIConnection = {
|
||||
const newProvider: AIProvider = {
|
||||
id: customProviderName.trim(),
|
||||
baseURL: customBaseURL.trim(),
|
||||
apiKey: customAuthMethod === 'nostr' ? undefined : customApiKey.trim(),
|
||||
nostr: customAuthMethod === 'nostr' || undefined,
|
||||
};
|
||||
|
||||
// Auto-save: Add provider immediately to persistent storage
|
||||
addProvider(customProviderName.trim(), newProvider);
|
||||
setProvider(newProvider);
|
||||
|
||||
setCustomProviderName('');
|
||||
setCustomBaseURL('');
|
||||
@@ -136,14 +272,14 @@ export function AISettings() {
|
||||
setCustomAuthMethod('api-key');
|
||||
};
|
||||
|
||||
const handleRemoveProvider = (name: string) => {
|
||||
const handleRemoveProvider = (id: string) => {
|
||||
// Auto-save: Remove provider immediately from persistent storage
|
||||
removeProvider(name);
|
||||
removeProvider(id);
|
||||
};
|
||||
|
||||
const handleUpdateProvider = (name: string, connection: Partial<AIConnection>) => {
|
||||
const handleSetProvider = (provider: AIProvider) => {
|
||||
// Auto-save: Update provider immediately in persistent storage
|
||||
updateProvider(name, connection);
|
||||
setProvider(provider);
|
||||
};
|
||||
|
||||
const handleOpenCreditsDialog = (providerId: string) => {
|
||||
@@ -154,7 +290,21 @@ export function AISettings() {
|
||||
setActiveCreditsDialog(null);
|
||||
};
|
||||
|
||||
const configuredProviderIds = Object.keys(settings.providers);
|
||||
const handleDragEnd = (event: DragEndEvent) => {
|
||||
const { active, over } = event;
|
||||
|
||||
if (active.id !== over?.id) {
|
||||
const oldIndex = settings.providers.findIndex(provider => provider.id === active.id);
|
||||
const newIndex = settings.providers.findIndex(provider => provider.id === over?.id);
|
||||
|
||||
if (oldIndex !== -1 && newIndex !== -1) {
|
||||
const newProviders = arrayMove(settings.providers, oldIndex, newIndex);
|
||||
setProviders(newProviders);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const configuredProviderIds = settings.providers.map(p => p.id);
|
||||
const availablePresets = PRESET_PROVIDERS.filter(preset => !configuredProviderIds.includes(preset.id));
|
||||
|
||||
return (
|
||||
@@ -196,94 +346,40 @@ export function AISettings() {
|
||||
|
||||
<div className="space-y-6">
|
||||
{/* Configured Providers */}
|
||||
{configuredProviderIds.length > 0 && (
|
||||
{settings.providers.length > 0 && (
|
||||
<div className="space-y-3">
|
||||
<h4 className="text-sm font-medium">{t('configuredProviders')}</h4>
|
||||
<Accordion type="multiple" className="w-full space-y-2">
|
||||
{configuredProviderIds.map((providerId) => {
|
||||
const preset = PRESET_PROVIDERS.find(p => p.id === providerId);
|
||||
const provider = settings.providers[providerId];
|
||||
<DndContext
|
||||
sensors={sensors}
|
||||
collisionDetection={closestCenter}
|
||||
onDragEnd={handleDragEnd}
|
||||
>
|
||||
<SortableContext
|
||||
items={settings.providers.map(p => p.id)}
|
||||
strategy={verticalListSortingStrategy}
|
||||
>
|
||||
<Accordion type="multiple" className="w-full space-y-2">
|
||||
{settings.providers.map((provider) => {
|
||||
const preset = PRESET_PROVIDERS.find(p => p.id === provider.id);
|
||||
|
||||
return (
|
||||
<AccordionItem key={providerId} value={providerId} className="border rounded-lg">
|
||||
<AccordionTrigger className="px-4 py-3 hover:no-underline">
|
||||
<div className="flex items-center justify-between w-full mr-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="font-medium">
|
||||
{preset?.name || providerId}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<CreditsBadge
|
||||
providerId={providerId}
|
||||
connection={provider}
|
||||
onOpenDialog={() => handleOpenCreditsDialog(providerId)}
|
||||
/>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
handleRemoveProvider(providerId);
|
||||
}}
|
||||
className="h-8 w-8 p-0 text-muted-foreground hover:text-destructive hover:bg-transparent"
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-4 pb-4">
|
||||
<div className="space-y-3">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor={`${providerId}-baseURL`}>{t('baseUrl')}</Label>
|
||||
<Input
|
||||
id={`${providerId}-baseURL`}
|
||||
placeholder="https://api.example.com/v1"
|
||||
value={provider?.baseURL || ''}
|
||||
onChange={(e) => handleUpdateProvider(providerId, { baseURL: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor={`${providerId}-auth`}>{t('authentication')}</Label>
|
||||
<Select
|
||||
value={provider?.nostr ? 'nostr' : 'api-key'}
|
||||
onValueChange={(value: 'api-key' | 'nostr') => handleUpdateProvider(providerId, {
|
||||
nostr: value === 'nostr' || undefined,
|
||||
apiKey: value === 'nostr' ? undefined : provider?.apiKey
|
||||
})}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="api-key">{t('apiKey')}</SelectItem>
|
||||
<SelectItem value="nostr">Nostr</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
{!provider?.nostr && (
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor={`${providerId}-apiKey`}>{t('apiKey')}</Label>
|
||||
<PasswordInput
|
||||
id={`${providerId}-apiKey`}
|
||||
placeholder={t('enterApiKey')}
|
||||
value={provider?.apiKey || ''}
|
||||
onChange={(e) => handleUpdateProvider(providerId, { apiKey: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
);
|
||||
})}
|
||||
</Accordion>
|
||||
return (
|
||||
<SortableProviderItem
|
||||
key={provider.id}
|
||||
provider={provider}
|
||||
preset={preset}
|
||||
onRemove={handleRemoveProvider}
|
||||
onSetProvider={handleSetProvider}
|
||||
onOpenCreditsDialog={handleOpenCreditsDialog}
|
||||
showDragHandle={settings.providers.length > 1}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</Accordion>
|
||||
</SortableContext>
|
||||
</DndContext>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{configuredProviderIds.length > 0 && availablePresets.length > 0 && <Separator />}
|
||||
|
||||
{/* Available Preset Providers */}
|
||||
{availablePresets.length > 0 && (
|
||||
<div className="space-y-3">
|
||||
@@ -357,8 +453,6 @@ export function AISettings() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{availablePresets.length > 0 && <Separator />}
|
||||
|
||||
{/* Custom Provider */}
|
||||
<div className="space-y-3">
|
||||
<Accordion type="single" collapsible className="w-full">
|
||||
@@ -422,14 +516,14 @@ export function AISettings() {
|
||||
disabled={
|
||||
!customProviderName.trim() ||
|
||||
!customBaseURL.trim() ||
|
||||
customProviderName.trim() in settings.providers
|
||||
settings.providers.some(p => p.id === customProviderName.trim())
|
||||
}
|
||||
className="gap-2 ml-auto"
|
||||
>
|
||||
<Check className="h-4 w-4" />
|
||||
{t('addCustomProviderButton')}
|
||||
</Button>
|
||||
{customProviderName.trim() in settings.providers && (
|
||||
{settings.providers.some(p => p.id === customProviderName.trim()) && (
|
||||
<p className="text-sm text-destructive">
|
||||
{t('providerExists')}
|
||||
</p>
|
||||
@@ -442,18 +536,20 @@ export function AISettings() {
|
||||
</div>
|
||||
|
||||
{/* Render credits dialog outside of accordion structure */}
|
||||
{activeCreditsDialog && (
|
||||
<CreditsDialog
|
||||
open={true}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) {
|
||||
handleCloseCreditsDialog();
|
||||
}
|
||||
}}
|
||||
providerId={activeCreditsDialog}
|
||||
connection={settings.providers[activeCreditsDialog]}
|
||||
/>
|
||||
)}
|
||||
{activeCreditsDialog && (() => {
|
||||
const provider = settings.providers.find(p => p.id === activeCreditsDialog);
|
||||
return provider && (
|
||||
<CreditsDialog
|
||||
open={true}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) {
|
||||
handleCloseCreditsDialog();
|
||||
}
|
||||
}}
|
||||
provider={provider}
|
||||
/>
|
||||
);
|
||||
})()}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
+39
-10
@@ -1,13 +1,17 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Info, ExternalLink, Loader2, AlertTriangle } from 'lucide-react';
|
||||
import { Info, ExternalLink, Loader2, AlertTriangle, ArrowLeft } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||
import { Alert, AlertDescription } from '@/components/ui/alert';
|
||||
import { useIsMobile } from '@/hooks/useIsMobile';
|
||||
|
||||
export function AboutSettings() {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const isMobile = useIsMobile();
|
||||
const [license, setLicense] = useState<string | null>(null);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
@@ -39,15 +43,40 @@ export function AboutSettings() {
|
||||
|
||||
return (
|
||||
<div className="p-6 space-y-6">
|
||||
<div className="space-y-2">
|
||||
<h1 className="text-2xl font-bold flex items-center gap-3">
|
||||
<Info className="h-6 w-6 text-primary" />
|
||||
{t('aboutShakespeare')}
|
||||
</h1>
|
||||
<p className="text-muted-foreground">
|
||||
{t('aboutShakespeareDescription')}
|
||||
</p>
|
||||
</div>
|
||||
{isMobile && (
|
||||
<div className="space-y-3">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => navigate('/settings')}
|
||||
className="h-8 w-auto px-2 -ml-2"
|
||||
>
|
||||
<ArrowLeft className="h-4 w-4 mr-2" />
|
||||
{t('backToSettings')}
|
||||
</Button>
|
||||
<div className="space-y-2">
|
||||
<h1 className="text-2xl font-bold flex items-center gap-3">
|
||||
<Info className="h-6 w-6 text-primary" />
|
||||
{t('aboutShakespeare')}
|
||||
</h1>
|
||||
<p className="text-muted-foreground">
|
||||
{t('aboutShakespeareDescription')}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!isMobile && (
|
||||
<div className="space-y-2">
|
||||
<h1 className="text-2xl font-bold flex items-center gap-3">
|
||||
<Info className="h-6 w-6 text-primary" />
|
||||
{t('aboutShakespeare')}
|
||||
</h1>
|
||||
<p className="text-muted-foreground">
|
||||
{t('aboutShakespeareDescription')}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="space-y-4">
|
||||
{/* Project Information */}
|
||||
|
||||
+36
-174
@@ -1,4 +1,4 @@
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { useState, useEffect, useCallback, useRef } from 'react';
|
||||
import { useNavigate, useSearchParams } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { AppLayout } from '@/components/AppLayout';
|
||||
@@ -7,19 +7,9 @@ import { Input } from '@/components/ui/input';
|
||||
import { GitBranch, Loader2, AlertCircle } from 'lucide-react';
|
||||
import { useProjectsManager } from '@/hooks/useProjectsManager';
|
||||
import { useToast } from '@/hooks/useToast';
|
||||
import { NIP05 } from '@nostrify/nostrify';
|
||||
import { useNostr } from '@nostrify/react';
|
||||
import { nip19 } from 'nostr-tools';
|
||||
import type { Project } from '@/lib/ProjectsManager';
|
||||
|
||||
import { useSeoMeta } from '@unhead/react';
|
||||
|
||||
interface NostrCloneUri {
|
||||
pubkey: string;
|
||||
dTag: string;
|
||||
relay?: string;
|
||||
}
|
||||
|
||||
export default function Clone() {
|
||||
const { t } = useTranslation();
|
||||
const [repoUrl, setRepoUrl] = useState('');
|
||||
@@ -29,7 +19,7 @@ export default function Clone() {
|
||||
const [searchParams] = useSearchParams();
|
||||
const projectsManager = useProjectsManager();
|
||||
const { toast } = useToast();
|
||||
const { nostr } = useNostr();
|
||||
const autoCloneInitiatedRef = useRef(false);
|
||||
|
||||
useSeoMeta({
|
||||
title: `${t('importRepository')} - Shakespeare`,
|
||||
@@ -38,9 +28,20 @@ export default function Clone() {
|
||||
|
||||
const extractRepoName = (url: string): string => {
|
||||
try {
|
||||
// Handle different URL formats
|
||||
const cleanUrl = url.trim();
|
||||
|
||||
// Handle Nostr clone URIs
|
||||
if (cleanUrl.startsWith('nostr://')) {
|
||||
const path = cleanUrl.slice(8); // Remove 'nostr://' prefix
|
||||
const parts = path.split('/');
|
||||
|
||||
// Return the d-tag (last part) as the repo name
|
||||
if (parts.length >= 2) {
|
||||
return parts[parts.length - 1] || 'nostr-repo';
|
||||
}
|
||||
return 'nostr-repo';
|
||||
}
|
||||
|
||||
// Extract from GitHub URLs, GitLab URLs, etc.
|
||||
const match = cleanUrl.match(/\/([^/]+?)(?:\.git)?(?:\/)?$/);
|
||||
if (match && match[1]) {
|
||||
@@ -56,70 +57,12 @@ export default function Clone() {
|
||||
}
|
||||
};
|
||||
|
||||
const parseNostrCloneUri = async (uri: string): Promise<NostrCloneUri | null> => {
|
||||
try {
|
||||
if (!uri.startsWith('nostr://')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const path = uri.slice(8); // Remove 'nostr://' prefix
|
||||
const parts = path.split('/');
|
||||
|
||||
if (parts.length < 2) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const identifier = parts[0];
|
||||
let pubkey: string;
|
||||
|
||||
// Try to decode as npub first, otherwise assume it's already a hex pubkey
|
||||
try {
|
||||
const decoded = nip19.decode(identifier);
|
||||
if (decoded.type === 'npub') {
|
||||
pubkey = decoded.data;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch {
|
||||
// If decoding fails, check if it's a NIP-05 identifier
|
||||
if (identifier.split('@').length === 2) {
|
||||
const pointer = await NIP05.lookup(identifier, {
|
||||
signal: AbortSignal.timeout(3000),
|
||||
});
|
||||
pubkey = pointer.pubkey;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if we have relay and d-tag or just d-tag
|
||||
if (parts.length === 3) {
|
||||
// Format: nostr://npub/relay/dtag
|
||||
return {
|
||||
pubkey,
|
||||
relay: parts[1],
|
||||
dTag: parts[2],
|
||||
};
|
||||
} else if (parts.length === 2) {
|
||||
// Format: nostr://npub/dtag
|
||||
return {
|
||||
pubkey,
|
||||
dTag: parts[1],
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
const validateGitUrl = useCallback((url: string): boolean => {
|
||||
if (!url.trim()) return false;
|
||||
|
||||
// Check if it's a Nostr clone URI
|
||||
if (url.startsWith('nostr://')) {
|
||||
return parseNostrCloneUri(url) !== null;
|
||||
return true; // Git class will handle validation
|
||||
}
|
||||
|
||||
// Basic URL validation
|
||||
@@ -134,73 +77,6 @@ export default function Clone() {
|
||||
return gitUrlPattern.test(url) || url.includes('github.com') || url.includes('gitlab.com');
|
||||
}, []);
|
||||
|
||||
const fetchNostrRepository = useCallback(async (nostrUri: NostrCloneUri): Promise<string[]> => {
|
||||
const signal = AbortSignal.timeout(10000); // 10 second timeout
|
||||
|
||||
// Build the filter for the NIP-34 repository announcement
|
||||
const filter = {
|
||||
kinds: [30617],
|
||||
authors: [nostrUri.pubkey],
|
||||
'#d': [nostrUri.dTag],
|
||||
limit: 1,
|
||||
};
|
||||
|
||||
// Use a specific relay if provided
|
||||
const client = nostrUri.relay
|
||||
? nostr.relay(nostrUri.relay)
|
||||
: nostr.group(['wss://relay.ngit.dev/', 'wss://gitnostr.com/']);
|
||||
|
||||
// Query for the repository announcement event
|
||||
const events = await client.query([filter], { signal });
|
||||
|
||||
if (events.length === 0) {
|
||||
throw new Error('Repository not found on Nostr network');
|
||||
}
|
||||
|
||||
const repoEvent = events[0];
|
||||
|
||||
// Extract clone URLs from the event tags
|
||||
const cloneUrls: string[] = [];
|
||||
for (const tag of repoEvent.tags) {
|
||||
if (tag[0] === 'clone' && tag[1]) {
|
||||
cloneUrls.push(tag[1]);
|
||||
}
|
||||
}
|
||||
|
||||
if (cloneUrls.length === 0) {
|
||||
throw new Error('No clone URLs found in repository announcement');
|
||||
}
|
||||
|
||||
return cloneUrls;
|
||||
}, [nostr]);
|
||||
|
||||
const tryCloneUrls = useCallback(async (cloneUrls: string[], repoName: string): Promise<Project> => {
|
||||
let lastError: Error | null = null;
|
||||
|
||||
for (const cloneUrl of cloneUrls) {
|
||||
try {
|
||||
console.log(`Attempting to clone from: ${cloneUrl}`);
|
||||
|
||||
// Try cloning with a timeout
|
||||
const project = await Promise.race([
|
||||
projectsManager.cloneProject(repoName, cloneUrl),
|
||||
new Promise<never>((_, reject) =>
|
||||
setTimeout(() => reject(new Error('Clone timeout')), 30000)
|
||||
)
|
||||
]);
|
||||
|
||||
return project; // Success!
|
||||
} catch (error) {
|
||||
console.warn(`Failed to clone from ${cloneUrl}:`, error);
|
||||
lastError = error instanceof Error ? error : new Error('Unknown error');
|
||||
continue; // Try the next URL
|
||||
}
|
||||
}
|
||||
|
||||
// If we get here, all clone attempts failed
|
||||
throw lastError || new Error('All clone attempts failed');
|
||||
}, [projectsManager]);
|
||||
|
||||
const handleClone = useCallback(async (url?: string) => {
|
||||
const targetUrl = url || repoUrl;
|
||||
|
||||
@@ -220,43 +96,28 @@ export default function Clone() {
|
||||
try {
|
||||
await projectsManager.init();
|
||||
|
||||
// Check if it's a Nostr clone URI
|
||||
const nostrUri = await parseNostrCloneUri(targetUrl.trim());
|
||||
// Extract repository name
|
||||
const repoName = extractRepoName(targetUrl);
|
||||
|
||||
if (nostrUri) {
|
||||
// Handle Nostr clone URI
|
||||
console.log('Parsing Nostr clone URI:', nostrUri);
|
||||
// Clone the repository (Git class handles both regular Git URLs and Nostr URIs)
|
||||
const project = await projectsManager.cloneProject(repoName, targetUrl.trim());
|
||||
|
||||
// Fetch the repository announcement from Nostr
|
||||
const cloneUrls = await fetchNostrRepository(nostrUri);
|
||||
console.log('Found clone URLs:', cloneUrls);
|
||||
// Determine success message based on URL type
|
||||
const isNostrUri = targetUrl.startsWith('nostr://');
|
||||
const successTitle = isNostrUri
|
||||
? t('nostrRepositoryImportedSuccessfully')
|
||||
: t('repositoryImportedSuccessfully');
|
||||
const successDescription = isNostrUri
|
||||
? t('repositoryClonedFromNostr', { repoName })
|
||||
: t('repositoryClonedReady', { repoName });
|
||||
|
||||
// Extract repository name from d-tag
|
||||
const repoName = nostrUri.dTag;
|
||||
toast({
|
||||
title: successTitle,
|
||||
description: successDescription,
|
||||
});
|
||||
|
||||
// Try cloning from each URL in order
|
||||
const project = await tryCloneUrls(cloneUrls, repoName);
|
||||
|
||||
toast({
|
||||
title: t('nostrRepositoryImportedSuccessfully'),
|
||||
description: t('repositoryClonedFromNostr', { repoName }),
|
||||
});
|
||||
|
||||
// Navigate to the new project
|
||||
navigate(`/project/${project.id}`);
|
||||
} else {
|
||||
// Handle regular Git URL
|
||||
const repoName = extractRepoName(targetUrl);
|
||||
const project = await projectsManager.cloneProject(repoName, targetUrl.trim());
|
||||
|
||||
toast({
|
||||
title: t('repositoryImportedSuccessfully'),
|
||||
description: t('repositoryClonedReady', { repoName }),
|
||||
});
|
||||
|
||||
// Navigate to the new project
|
||||
navigate(`/project/${project.id}`);
|
||||
}
|
||||
// Navigate to the new project with build parameter
|
||||
navigate(`/project/${project.id}?build`);
|
||||
} catch (error) {
|
||||
console.error('Failed to clone repository:', error);
|
||||
|
||||
@@ -289,7 +150,7 @@ export default function Clone() {
|
||||
} finally {
|
||||
setIsCloning(false);
|
||||
}
|
||||
}, [fetchNostrRepository, navigate, projectsManager, repoUrl, t, toast, tryCloneUrls, validateGitUrl]);
|
||||
}, [navigate, projectsManager, repoUrl, t, toast, validateGitUrl]);
|
||||
|
||||
const handleKeyDown = (e: React.KeyboardEvent) => {
|
||||
if (e.key === 'Enter' && !isCloning) {
|
||||
@@ -300,9 +161,10 @@ export default function Clone() {
|
||||
// Initialize repoUrl from URL parameters and auto-import if URL is provided
|
||||
useEffect(() => {
|
||||
const urlParam = searchParams.get('url');
|
||||
if (urlParam) {
|
||||
if (urlParam && !autoCloneInitiatedRef.current) {
|
||||
const decodedUrl = decodeURIComponent(urlParam);
|
||||
setRepoUrl(decodedUrl);
|
||||
autoCloneInitiatedRef.current = true;
|
||||
|
||||
// Automatically start the clone process with the URL directly
|
||||
handleClone(decodedUrl);
|
||||
|
||||
+37
-10
@@ -1,13 +1,14 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Download, Trash2, AlertTriangle, Loader2, Database, Info } from 'lucide-react';
|
||||
import { Download, Trash2, AlertTriangle, Loader2, Database, Info, ArrowLeft } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, AlertDialogTrigger } from '@/components/ui/alert-dialog';
|
||||
import { Progress } from '@/components/ui/progress';
|
||||
import { useToast } from '@/hooks/useToast';
|
||||
import { useFS } from '@/hooks/useFS';
|
||||
import { useIsMobile } from '@/hooks/useIsMobile';
|
||||
import JSZip from 'jszip';
|
||||
|
||||
interface StorageUsageDetails {
|
||||
@@ -32,6 +33,7 @@ export function DataSettings() {
|
||||
const { toast } = useToast();
|
||||
const { fs } = useFS();
|
||||
const navigate = useNavigate();
|
||||
const isMobile = useIsMobile();
|
||||
|
||||
// Format bytes to human readable format
|
||||
const formatBytes = (bytes: number): string => {
|
||||
@@ -196,15 +198,40 @@ export function DataSettings() {
|
||||
|
||||
return (
|
||||
<div className="p-6 space-y-6">
|
||||
<div className="space-y-2">
|
||||
<h1 className="text-2xl font-bold flex items-center gap-3">
|
||||
<Database className="h-6 w-6 text-primary" />
|
||||
{t('dataSettings')}
|
||||
</h1>
|
||||
<p className="text-muted-foreground">
|
||||
{t('dataSettingsDescriptionLong')}
|
||||
</p>
|
||||
</div>
|
||||
{isMobile && (
|
||||
<div className="space-y-3">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => navigate('/settings')}
|
||||
className="h-8 w-auto px-2 -ml-2"
|
||||
>
|
||||
<ArrowLeft className="h-4 w-4 mr-2" />
|
||||
{t('backToSettings')}
|
||||
</Button>
|
||||
<div className="space-y-2">
|
||||
<h1 className="text-2xl font-bold flex items-center gap-3">
|
||||
<Database className="h-6 w-6 text-primary" />
|
||||
{t('dataSettings')}
|
||||
</h1>
|
||||
<p className="text-muted-foreground">
|
||||
{t('dataSettingsDescriptionLong')}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!isMobile && (
|
||||
<div className="space-y-2">
|
||||
<h1 className="text-2xl font-bold flex items-center gap-3">
|
||||
<Database className="h-6 w-6 text-primary" />
|
||||
{t('dataSettings')}
|
||||
</h1>
|
||||
<p className="text-muted-foreground">
|
||||
{t('dataSettingsDescriptionLong')}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="space-y-4">
|
||||
{/* Storage Information */}
|
||||
|
||||
@@ -0,0 +1,301 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { ArrowLeft, Mail, CheckCircle } from 'lucide-react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { useIsMobile } from '@/hooks/useIsMobile';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||
import { useToast } from '@/hooks/useToast';
|
||||
import { nip19 } from 'nostr-tools';
|
||||
|
||||
export function EmailSettings() {
|
||||
const { t } = useTranslation();
|
||||
const isMobile = useIsMobile();
|
||||
const navigate = useNavigate();
|
||||
const { user } = useCurrentUser();
|
||||
const { toast } = useToast();
|
||||
|
||||
const [email, setEmail] = useState('');
|
||||
const [isSubmitting, setIsSubmitting] = useState(false);
|
||||
const [isSubmitted, setIsSubmitted] = useState(false);
|
||||
|
||||
// Check localStorage on component mount
|
||||
useEffect(() => {
|
||||
const hasSubscribed = localStorage.getItem('shakespeare-email-subscribed');
|
||||
if (hasSubscribed === 'true') {
|
||||
setIsSubmitted(true);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
|
||||
if (!email.trim()) {
|
||||
toast({
|
||||
title: "Email required",
|
||||
description: "Please enter your email address",
|
||||
variant: "destructive",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Basic email validation
|
||||
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
||||
if (!emailRegex.test(email)) {
|
||||
toast({
|
||||
title: "Invalid email",
|
||||
description: "Please enter a valid email address",
|
||||
variant: "destructive",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
setIsSubmitting(true);
|
||||
|
||||
try {
|
||||
// Prepare form data
|
||||
const formData = new FormData();
|
||||
formData.append('email', email.trim());
|
||||
formData.append('tag_id', '8982396');
|
||||
|
||||
// Include npub if user is signed in
|
||||
if (user?.pubkey) {
|
||||
const npub = nip19.npubEncode(user.pubkey);
|
||||
formData.append('npub', npub);
|
||||
}
|
||||
|
||||
// Submit to Mailchimp using the same setup as soapbox2
|
||||
const form = document.createElement('form');
|
||||
form.method = 'POST';
|
||||
form.action = 'https://pub.us7.list-manage.com/subscribe/post?u=f1f718a93795f42a604d558d8&id=f7271442a0&f_id=00ffa3e4f0';
|
||||
form.target = '_blank'; // Open in new tab
|
||||
form.style.display = 'none';
|
||||
|
||||
// Add email field
|
||||
const emailInput = document.createElement('input');
|
||||
emailInput.type = 'email';
|
||||
emailInput.name = 'EMAIL';
|
||||
emailInput.value = email.trim();
|
||||
form.appendChild(emailInput);
|
||||
|
||||
// Add tag field with the new Shakespeare tag ID
|
||||
const tagInput = document.createElement('input');
|
||||
tagInput.type = 'hidden';
|
||||
tagInput.name = 'tags';
|
||||
tagInput.value = '8982396';
|
||||
form.appendChild(tagInput);
|
||||
|
||||
// Add npub if available
|
||||
if (user?.pubkey) {
|
||||
const npubInput = document.createElement('input');
|
||||
npubInput.type = 'text';
|
||||
npubInput.name = 'NPUB';
|
||||
npubInput.value = nip19.npubEncode(user.pubkey);
|
||||
npubInput.style.display = 'none';
|
||||
form.appendChild(npubInput);
|
||||
}
|
||||
|
||||
// Add honeypot field
|
||||
const honeypotInput = document.createElement('input');
|
||||
honeypotInput.type = 'text';
|
||||
honeypotInput.name = 'b_f1f718a93795f42a604d558d8_f7271442a0';
|
||||
honeypotInput.tabIndex = -1;
|
||||
honeypotInput.style.position = 'absolute';
|
||||
honeypotInput.style.left = '-5000px';
|
||||
form.appendChild(honeypotInput);
|
||||
|
||||
// Add form to document and submit
|
||||
document.body.appendChild(form);
|
||||
form.submit();
|
||||
|
||||
// Clean up after a short delay
|
||||
setTimeout(() => {
|
||||
document.body.removeChild(form);
|
||||
}, 1000);
|
||||
|
||||
// Save subscription status to localStorage
|
||||
localStorage.setItem('shakespeare-email-subscribed', 'true');
|
||||
|
||||
setIsSubmitted(true);
|
||||
toast({
|
||||
title: "Successfully subscribed!",
|
||||
description: "You'll receive Shakespeare updates and resources occasionally.",
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Email signup error:', error);
|
||||
toast({
|
||||
title: "Subscription failed",
|
||||
description: "There was an error subscribing you to updates. Please try again.",
|
||||
variant: "destructive",
|
||||
});
|
||||
} finally {
|
||||
setIsSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (isSubmitted) {
|
||||
return (
|
||||
<div className="p-6 space-y-6">
|
||||
{isMobile && (
|
||||
<div className="space-y-3">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => navigate('/settings')}
|
||||
className="h-8 w-auto px-2 -ml-2"
|
||||
>
|
||||
<ArrowLeft className="h-4 w-4 mr-2" />
|
||||
{t('backToSettings')}
|
||||
</Button>
|
||||
<div className="space-y-2">
|
||||
<h1 className="text-2xl font-bold flex items-center gap-3">
|
||||
<Mail className="h-6 w-6 text-primary" />
|
||||
{t('emailUpdates')}
|
||||
</h1>
|
||||
<p className="text-muted-foreground">
|
||||
{t('emailUpdatesDescriptionLong')}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!isMobile && (
|
||||
<div className="space-y-2">
|
||||
<h1 className="text-2xl font-bold flex items-center gap-3">
|
||||
<Mail className="h-6 w-6 text-primary" />
|
||||
{t('emailUpdates')}
|
||||
</h1>
|
||||
<p className="text-muted-foreground">
|
||||
{t('emailUpdatesDescriptionLong')}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="max-w-md">
|
||||
<Card>
|
||||
<CardContent className="pt-6">
|
||||
<div className="text-center space-y-4">
|
||||
<CheckCircle className="h-12 w-12 mx-auto text-green-500" />
|
||||
<div className="space-y-2">
|
||||
<h3 className="text-lg font-semibold">
|
||||
Thanks for subscribing!
|
||||
</h3>
|
||||
<p className="text-muted-foreground text-sm">
|
||||
You can opt out at any time using the unsubscribe link in our emails.
|
||||
</p>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Button
|
||||
onClick={() => navigate('/settings')}
|
||||
className="w-full"
|
||||
>
|
||||
Back to Settings
|
||||
</Button>
|
||||
<Button
|
||||
onClick={() => {
|
||||
localStorage.removeItem('shakespeare-email-subscribed');
|
||||
setIsSubmitted(false);
|
||||
setEmail('');
|
||||
}}
|
||||
variant="outline"
|
||||
className="w-full text-xs"
|
||||
>
|
||||
Subscribe with different email
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="p-6 space-y-6">
|
||||
{isMobile && (
|
||||
<div className="space-y-3">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => navigate('/settings')}
|
||||
className="h-8 w-auto px-2 -ml-2"
|
||||
>
|
||||
<ArrowLeft className="h-4 w-4 mr-2" />
|
||||
{t('backToSettings')}
|
||||
</Button>
|
||||
<div className="space-y-2">
|
||||
<h1 className="text-2xl font-bold flex items-center gap-3">
|
||||
<Mail className="h-6 w-6 text-primary" />
|
||||
{t('emailUpdates')}
|
||||
</h1>
|
||||
<p className="text-muted-foreground">
|
||||
{t('emailUpdatesDescriptionLong')}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!isMobile && (
|
||||
<div className="space-y-2">
|
||||
<h1 className="text-2xl font-bold flex items-center gap-3">
|
||||
<Mail className="h-6 w-6 text-primary" />
|
||||
{t('emailUpdates')}
|
||||
</h1>
|
||||
<p className="text-muted-foreground">
|
||||
{t('emailUpdatesDescriptionLong')}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="max-w-md">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-lg">
|
||||
Stay Updated with Shakespeare
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<form onSubmit={handleSubmit} className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<Label htmlFor="email">
|
||||
Email Address
|
||||
</Label>
|
||||
<Input
|
||||
id="email"
|
||||
type="email"
|
||||
placeholder="[email protected]"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
disabled={isSubmitting}
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div className="space-y-3">
|
||||
<Button
|
||||
type="submit"
|
||||
className="w-full"
|
||||
disabled={isSubmitting}
|
||||
>
|
||||
{isSubmitting ? 'Subscribing...' : 'Subscribe to Updates'}
|
||||
</Button>
|
||||
|
||||
<p className="text-xs text-muted-foreground text-center">
|
||||
You can opt out at any time using the unsubscribe link in our emails.
|
||||
</p>
|
||||
</div>
|
||||
</form>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default EmailSettings;
|
||||
+15
-25
@@ -4,7 +4,6 @@ import { Check, GitBranch, ArrowLeft, Github, Trash2 } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion';
|
||||
import { useGitSettings } from '@/hooks/useGitSettings';
|
||||
@@ -12,6 +11,7 @@ import { useGitHubOAuth } from '@/hooks/useGitHubOAuth';
|
||||
import { useIsMobile } from '@/hooks/useIsMobile';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import type { GitCredential } from '@/contexts/GitSettingsContext';
|
||||
import { PasswordInput } from '@/components/ui/password-input';
|
||||
|
||||
interface PresetProvider {
|
||||
id: string;
|
||||
@@ -192,9 +192,8 @@ export function GitSettings() {
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor={`${origin}-password`}>{t('password')}</Label>
|
||||
<Input
|
||||
<PasswordInput
|
||||
id={`${origin}-password`}
|
||||
type="password"
|
||||
placeholder={t('enterPassword')}
|
||||
value={credential?.password || ''}
|
||||
onChange={(e) => handleUpdateCredential(origin, { password: e.target.value })}
|
||||
@@ -209,8 +208,6 @@ export function GitSettings() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{configuredOrigins.length > 0 && availablePresets.length > 0 && <Separator />}
|
||||
|
||||
{/* Available Preset Providers */}
|
||||
{availablePresets.length > 0 && (
|
||||
<div className="space-y-3">
|
||||
@@ -263,9 +260,8 @@ export function GitSettings() {
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex gap-2">
|
||||
<Input
|
||||
<PasswordInput
|
||||
placeholder={t('enterToken')}
|
||||
type="password"
|
||||
className="flex-1"
|
||||
value={presetTokens[preset.id] || ''}
|
||||
onChange={(e) => setPresetTokens(prev => ({
|
||||
@@ -290,9 +286,8 @@ export function GitSettings() {
|
||||
) : (
|
||||
// Standard rendering for other providers
|
||||
<div className="flex gap-2">
|
||||
<Input
|
||||
<PasswordInput
|
||||
placeholder={t('enterToken')}
|
||||
type="password"
|
||||
className="flex-1"
|
||||
value={presetTokens[preset.id] || ''}
|
||||
onChange={(e) => setPresetTokens(prev => ({
|
||||
@@ -320,8 +315,6 @@ export function GitSettings() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Separator />
|
||||
|
||||
{/* Custom Provider */}
|
||||
<div className="space-y-3">
|
||||
<Accordion type="single" collapsible className="w-full">
|
||||
@@ -351,9 +344,8 @@ export function GitSettings() {
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-password">{t('password')}</Label>
|
||||
<Input
|
||||
<PasswordInput
|
||||
id="custom-password"
|
||||
type="password"
|
||||
placeholder={t('enterPassword')}
|
||||
value={customPassword}
|
||||
onChange={(e) => setCustomPassword(e.target.value)}
|
||||
@@ -390,18 +382,16 @@ export function GitSettings() {
|
||||
<h4 className="text-sm font-medium">{t('corsProxy')}</h4>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-4 pb-4">
|
||||
<div className="space-y-3">
|
||||
<div className="grid gap-2">
|
||||
<Input
|
||||
id="cors-proxy"
|
||||
placeholder="https://cors.isomorphic-git.org"
|
||||
value={settings.corsProxy}
|
||||
onChange={(e) => updateSettings({ corsProxy: e.target.value })}
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{t('corsProxyDescription')}
|
||||
</p>
|
||||
</div>
|
||||
<div className="py-1 space-y-2">
|
||||
<Input
|
||||
id="cors-proxy"
|
||||
placeholder="https://proxy.shakespeare.diy/?url={href}"
|
||||
value={settings.corsProxy}
|
||||
onChange={(e) => updateSettings({ corsProxy: e.target.value })}
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{t('corsProxyDescription')}
|
||||
</p>
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
|
||||
+185
-14
@@ -9,12 +9,17 @@ import { useIsMobile } from '@/hooks/useIsMobile';
|
||||
import { useAISettings } from '@/hooks/useAISettings';
|
||||
import { useToast } from '@/hooks/useToast';
|
||||
import { AppLayout } from '@/components/AppLayout';
|
||||
import { OnboardingDialog } from '@/components/OnboardingDialog';
|
||||
import { DotAI } from '@/lib/DotAI';
|
||||
import { parseProviderModel } from '@/lib/parseProviderModel';
|
||||
import type { AIMessage } from '@/lib/SessionManager';
|
||||
|
||||
import { saveFileToTmp } from '@/lib/fileUtils';
|
||||
import type OpenAI from 'openai';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Textarea } from '@/components/ui/textarea';
|
||||
import { ModelSelector } from '@/components/ModelSelector';
|
||||
import { FileAttachment } from '@/components/ui/file-attachment';
|
||||
import { ToastAction } from '@/components/ui/toast';
|
||||
import { Plus } from 'lucide-react';
|
||||
import { useSeoMeta } from '@unhead/react';
|
||||
|
||||
@@ -23,10 +28,11 @@ export default function Index() {
|
||||
const [prompt, setPrompt] = useState('');
|
||||
const [isCreating, setIsCreating] = useState(false);
|
||||
const [storedPrompt, setStoredPrompt] = useLocalStorage('shakespeare-draft-prompt', '');
|
||||
const [showOnboarding, setShowOnboarding] = useState(false);
|
||||
const navigate = useNavigate();
|
||||
const projectsManager = useProjectsManager();
|
||||
const { fs } = useFS();
|
||||
const { generateProjectId, isLoading: isGeneratingId, isConfigured: isAIConfigured } = useAIProjectId();
|
||||
const { generateProjectId, isLoading: isGeneratingId } = useAIProjectId();
|
||||
const { settings, addRecentlyUsedModel } = useAISettings();
|
||||
const { toast } = useToast();
|
||||
const [providerModel, setProviderModel] = useState(() => {
|
||||
@@ -34,6 +40,46 @@ export default function Index() {
|
||||
return settings.recentlyUsedModels?.[0] || '';
|
||||
});
|
||||
const isMobile = useIsMobile();
|
||||
const [attachedFiles, setAttachedFiles] = useState<File[]>([]);
|
||||
const [isDragOver, setIsDragOver] = useState(false);
|
||||
|
||||
// Check if any providers are configured
|
||||
const hasProvidersConfigured = settings.providers.length > 0;
|
||||
|
||||
// Check for API key failures and show appropriate toast
|
||||
const checkForKeyFailure = (error: unknown): boolean => {
|
||||
// Check for authentication errors
|
||||
// Note: useAIProjectId re-throws OpenAI errors as generic Error objects
|
||||
const isAuthError = error instanceof Error && error.message === '401 No auth credentials found';
|
||||
|
||||
if (isAuthError) {
|
||||
// Get provider name inline
|
||||
let providerName = 'Provider';
|
||||
try {
|
||||
const { provider } = parseProviderModel(providerModel, settings.providers);
|
||||
providerName = provider.id.charAt(0).toUpperCase() + provider.id.slice(1);
|
||||
} catch {
|
||||
// Keep default 'Provider'
|
||||
}
|
||||
|
||||
toast({
|
||||
title: t('apiAuthenticationFailed'),
|
||||
description: t('invalidApiKey', { provider: providerName }),
|
||||
variant: 'destructive',
|
||||
action: (
|
||||
<ToastAction
|
||||
altText={t('checkApiKeySettings')}
|
||||
onClick={() => navigate('/settings/ai')}
|
||||
>
|
||||
{t('checkApiKeySettings')}
|
||||
</ToastAction>
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
return isAuthError;
|
||||
};
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if (!providerModel && settings.recentlyUsedModels?.length) {
|
||||
@@ -60,6 +106,57 @@ export default function Index() {
|
||||
setStoredPrompt(newPrompt);
|
||||
};
|
||||
|
||||
const handleFileSelect = (file: File) => {
|
||||
setAttachedFiles(prev => [...prev, file]);
|
||||
};
|
||||
|
||||
const handleFileRemove = (fileToRemove: File) => {
|
||||
setAttachedFiles(prev => prev.filter(file => file !== fileToRemove));
|
||||
};
|
||||
|
||||
// Drag and drop handlers
|
||||
const handleDragEnter = (e: React.DragEvent) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
setIsDragOver(true);
|
||||
};
|
||||
|
||||
const handleDragOver = (e: React.DragEvent) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
if (!isDragOver) {
|
||||
setIsDragOver(true);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDragLeave = (e: React.DragEvent) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
// Only reset drag state if we're actually leaving the container
|
||||
// This prevents flickering when dragging over child elements
|
||||
const container = e.currentTarget;
|
||||
const relatedTarget = e.relatedTarget as Node;
|
||||
|
||||
if (!container.contains(relatedTarget)) {
|
||||
setIsDragOver(false);
|
||||
}
|
||||
};
|
||||
|
||||
const handleDrop = (e: React.DragEvent) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
setIsDragOver(false);
|
||||
|
||||
if (isCreating || isGeneratingId || !providerModel.trim()) return;
|
||||
|
||||
const files = Array.from(e.dataTransfer.files);
|
||||
if (files.length === 0) return;
|
||||
|
||||
// Add all files without validation
|
||||
setAttachedFiles(prev => [...prev, ...files]);
|
||||
};
|
||||
|
||||
// Handle keyboard shortcuts (physical keyboards only)
|
||||
const handleKeyDown = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
||||
if (e.key === 'Enter') {
|
||||
@@ -83,6 +180,13 @@ export default function Index() {
|
||||
}
|
||||
};
|
||||
|
||||
// Handle textarea click - show onboarding if no providers configured
|
||||
const handleTextareaClick = () => {
|
||||
if (!hasProvidersConfigured) {
|
||||
setShowOnboarding(true);
|
||||
}
|
||||
};
|
||||
|
||||
const handleCreateProject = async () => {
|
||||
if (!prompt.trim() || !providerModel.trim()) return;
|
||||
|
||||
@@ -100,28 +204,69 @@ export default function Index() {
|
||||
// Create project with AI-generated ID
|
||||
const project = await projectsManager.createProject(prompt.trim(), projectId);
|
||||
|
||||
// Build message content as text parts (same as ChatPane)
|
||||
const contentParts: Array<OpenAI.Chat.Completions.ChatCompletionContentPartText> = [];
|
||||
|
||||
// Add user input as text part if present
|
||||
if (prompt.trim()) {
|
||||
contentParts.push({
|
||||
type: 'text',
|
||||
text: prompt.trim()
|
||||
});
|
||||
}
|
||||
|
||||
// Process attached files and add as separate text parts
|
||||
if (attachedFiles.length > 0) {
|
||||
const filePromises = attachedFiles.map(async (file) => {
|
||||
try {
|
||||
const savedPath = await saveFileToTmp(fs, file);
|
||||
return `Added file: ${savedPath}`;
|
||||
} catch (error) {
|
||||
console.error('Failed to save file:', error);
|
||||
return `Failed to save file: ${file.name}`;
|
||||
}
|
||||
});
|
||||
|
||||
const fileResults = await Promise.all(filePromises);
|
||||
|
||||
// Add each file as a separate text part
|
||||
fileResults.forEach(fileResult => {
|
||||
contentParts.push({
|
||||
type: 'text',
|
||||
text: fileResult
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Store the initial message in chat history using DotAI
|
||||
const dotAI = new DotAI(fs, `/projects/${project.id}`);
|
||||
const sessionName = DotAI.generateSessionName();
|
||||
|
||||
// Create initial message with content parts (same format as ChatPane)
|
||||
const initialMessage: AIMessage = {
|
||||
role: 'user',
|
||||
content: prompt.trim()
|
||||
content: contentParts.length === 1 ? contentParts[0].text : contentParts
|
||||
};
|
||||
await dotAI.setHistory(sessionName, [initialMessage]);
|
||||
|
||||
// Clear attached files after successful creation
|
||||
setAttachedFiles([]);
|
||||
|
||||
// Navigate to the project with autostart parameter and model
|
||||
const searchParams = new URLSearchParams({
|
||||
autostart: 'true',
|
||||
build: 'true',
|
||||
...(providerModel.trim() && { model: providerModel.trim() })
|
||||
});
|
||||
navigate(`/project/${project.id}?${searchParams.toString()}`);
|
||||
} catch (error) {
|
||||
console.error('Failed to create project:', error);
|
||||
toast({
|
||||
title: "Project Creation Failed",
|
||||
description: error instanceof Error ? error.message : "An unexpected error occurred",
|
||||
variant: "destructive",
|
||||
});
|
||||
checkForKeyFailure(error) ||
|
||||
toast({
|
||||
title: "Project Creation Failed",
|
||||
description: error instanceof Error ? error.message : "An unexpected error occurred",
|
||||
variant: "destructive",
|
||||
});
|
||||
} finally {
|
||||
setIsCreating(false);
|
||||
}
|
||||
@@ -145,18 +290,28 @@ export default function Index() {
|
||||
|
||||
<div className="mb-8 md:mb-12">
|
||||
{/* Chat Input Container - matching the ChatPane style */}
|
||||
<div className="relative rounded-2xl border border-input bg-background shadow-sm focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2 transition-all">
|
||||
<div
|
||||
className={`relative rounded-2xl border border-input bg-background shadow-sm focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2 transition-all ${isDragOver ? 'border-primary bg-primary/5 ring-2 ring-primary/20' : ''
|
||||
}`}
|
||||
onDragEnter={handleDragEnter}
|
||||
onDragOver={handleDragOver}
|
||||
onDragLeave={handleDragLeave}
|
||||
onDrop={handleDrop}
|
||||
>
|
||||
<Textarea
|
||||
placeholder={
|
||||
!providerModel.trim()
|
||||
? t('selectModelToDescribe')
|
||||
: t('examplePrompt')
|
||||
!hasProvidersConfigured
|
||||
? t('examplePrompt')
|
||||
: !providerModel.trim()
|
||||
? t('selectModelToDescribe')
|
||||
: t('examplePrompt')
|
||||
}
|
||||
value={prompt}
|
||||
onChange={handlePromptChange}
|
||||
onKeyDown={handleKeyDown}
|
||||
onClick={handleTextareaClick}
|
||||
className="min-h-[120px] max-h-64 resize-none border-0 bg-transparent px-4 py-3 pb-16 text-sm focus-visible:ring-0 focus-visible:ring-offset-0 placeholder:text-muted-foreground"
|
||||
disabled={isCreating || isGeneratingId || !providerModel.trim()}
|
||||
disabled={isCreating || isGeneratingId || (hasProvidersConfigured && !providerModel.trim())}
|
||||
rows={4}
|
||||
style={{
|
||||
height: 'auto',
|
||||
@@ -171,6 +326,16 @@ export default function Index() {
|
||||
|
||||
{/* Bottom Controls Row */}
|
||||
<div className="absolute bottom-3 left-3 right-3 flex items-center justify-end gap-2 overflow-hidden">
|
||||
{/* File Attachment */}
|
||||
<FileAttachment
|
||||
className="mr-auto"
|
||||
onFileSelect={handleFileSelect}
|
||||
onFileRemove={handleFileRemove}
|
||||
selectedFiles={attachedFiles}
|
||||
disabled={isCreating || isGeneratingId}
|
||||
multiple={true}
|
||||
/>
|
||||
|
||||
{/* Model Selector - always show to allow configuration */}
|
||||
<div className="overflow-hidden">
|
||||
<ModelSelector
|
||||
@@ -189,7 +354,7 @@ export default function Index() {
|
||||
!prompt.trim() ||
|
||||
isCreating ||
|
||||
isGeneratingId ||
|
||||
(isAIConfigured && !providerModel.trim())
|
||||
(hasProvidersConfigured && !providerModel.trim())
|
||||
}
|
||||
size="sm"
|
||||
className="h-8 rounded-lg"
|
||||
@@ -211,6 +376,12 @@ export default function Index() {
|
||||
</div>
|
||||
</div>
|
||||
</AppLayout>
|
||||
|
||||
{/* Onboarding Dialog */}
|
||||
<OnboardingDialog
|
||||
open={showOnboarding}
|
||||
onOpenChange={setShowOnboarding}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -6,8 +6,8 @@ import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { RelaySelector } from '@/components/RelaySelector';
|
||||
import LoginDialog from '@/components/auth/LoginDialog';
|
||||
import SignupDialog from '@/components/auth/SignupDialog';
|
||||
import SimpleLoginDialog from '@/components/auth/SimpleLoginDialog';
|
||||
import SimpleSignupDialog from '@/components/auth/SimpleSignupDialog';
|
||||
import { useIsMobile } from '@/hooks/useIsMobile';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useLoggedInAccounts, type Account } from '@/hooks/useLoggedInAccounts';
|
||||
@@ -207,7 +207,7 @@ export function NostrSettings() {
|
||||
</div>
|
||||
|
||||
{/* Login Dialog */}
|
||||
<LoginDialog
|
||||
<SimpleLoginDialog
|
||||
isOpen={showLoginDialog}
|
||||
onClose={() => setShowLoginDialog(false)}
|
||||
onLogin={handleLoginSuccess}
|
||||
@@ -218,10 +218,14 @@ export function NostrSettings() {
|
||||
/>
|
||||
|
||||
{/* Signup Dialog */}
|
||||
<SignupDialog
|
||||
<SimpleSignupDialog
|
||||
isOpen={showSignupDialog}
|
||||
onClose={() => setShowSignupDialog(false)}
|
||||
onComplete={handleSignupComplete}
|
||||
onLogin={() => {
|
||||
setShowSignupDialog(false);
|
||||
setShowLoginDialog(true);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
+85
-157
@@ -6,25 +6,20 @@ import { useProjectsManager } from '@/hooks/useProjectsManager';
|
||||
import { ChatPane, type ChatPaneRef } from '@/components/Shakespeare/ChatPane';
|
||||
import { PreviewPane } from '@/components/Shakespeare/PreviewPane';
|
||||
import { ProjectSidebar } from '@/components/ProjectSidebar';
|
||||
import { ProjectInfoDialog } from '@/components/ProjectInfoDialog';
|
||||
import { ProjectDetailsDialog } from '@/components/ProjectDetailsDialog';
|
||||
import { ResizablePanelGroup, ResizablePanel, ResizableHandle } from '@/components/ui/resizable';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { ArrowLeft, MessageSquare, Eye, Code, Menu } from 'lucide-react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { ActionsMenu } from '@/components/ActionsMenu';
|
||||
|
||||
import { useIsMobile } from '@/hooks/useIsMobile';
|
||||
import { useFS } from '@/hooks/useFS';
|
||||
import { useKeepAlive } from '@/hooks/useKeepAlive';
|
||||
import { GitStatusIndicator } from '@/components/GitStatusIndicator';
|
||||
import { StarButton } from '@/components/StarButton';
|
||||
|
||||
import { buildProject } from "@/lib/build";
|
||||
import { deployProject } from "@/lib/deploy";
|
||||
import { useCurrentUser } from "@/hooks/useCurrentUser";
|
||||
import { useAppContext } from "@/hooks/useAppContext";
|
||||
import { useToast } from "@/hooks/useToast";
|
||||
import { useBuildProject } from '@/hooks/useBuildProject';
|
||||
import { useIsProjectPreviewable } from '@/hooks/useIsProjectPreviewable';
|
||||
|
||||
export function ProjectView() {
|
||||
const { projectId } = useParams<{ projectId: string }>();
|
||||
@@ -33,23 +28,21 @@ 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 [isProjectInfoOpen, setIsProjectInfoOpen] = useState(false);
|
||||
const [isProjectDetailsOpen, setIsProjectDetailsOpen] = useState(false);
|
||||
const projectsManager = useProjectsManager();
|
||||
const chatPaneRef = useRef<ChatPaneRef>(null);
|
||||
const navigate = useNavigate();
|
||||
const isMobile = useIsMobile();
|
||||
const { fs } = useFS();
|
||||
const { user } = useCurrentUser();
|
||||
const { config } = useAppContext();
|
||||
const { toast } = useToast();
|
||||
|
||||
const [isSidebarVisible, setIsSidebarVisible] = useState(!isMobile);
|
||||
|
||||
const build = useBuildProject(projectId!);
|
||||
const { data: isPreviewable = false } = useIsProjectPreviewable(projectId!);
|
||||
|
||||
// Keep-alive functionality to prevent tab throttling during AI processing
|
||||
const { updateMetadata } = useKeepAlive({
|
||||
enabled: isAILoading || isBuildLoading || isDeployLoading,
|
||||
enabled: isAILoading || build.isPending,
|
||||
title: 'Shakespeare',
|
||||
artist: project ? `Working on ${project.name}...` : 'Working...',
|
||||
artwork: [
|
||||
@@ -78,72 +71,38 @@ export function ProjectView() {
|
||||
loadProject();
|
||||
}, [loadProject]);
|
||||
|
||||
const runBuild = async () => {
|
||||
if (isBuildLoading || !project) return;
|
||||
// Reset view state when projectId changes
|
||||
useEffect(() => {
|
||||
if (projectId) {
|
||||
// Reset to preview tab if the new project is previewable, otherwise code
|
||||
setActiveTab(isPreviewable ? 'preview' : 'code');
|
||||
// Reset mobile view to chat when switching projects
|
||||
setMobileView('chat');
|
||||
}
|
||||
}, [projectId, isPreviewable]);
|
||||
|
||||
setIsBuildLoading(true);
|
||||
// Switch away from preview mode if project is not previewable
|
||||
useEffect(() => {
|
||||
if (mobileView === 'preview' && !isPreviewable) {
|
||||
setMobileView('code');
|
||||
}
|
||||
if (activeTab === 'preview' && !isPreviewable) {
|
||||
setActiveTab('code');
|
||||
}
|
||||
}, [isPreviewable, mobileView, activeTab]);
|
||||
|
||||
const runBuild = async () => {
|
||||
if (build.isPending || !project) return;
|
||||
updateMetadata('Shakespeare', `Building ${project.name}...`);
|
||||
|
||||
try {
|
||||
const result = await buildProject({
|
||||
fs,
|
||||
projectPath: `/projects/${project.id}`,
|
||||
domParser: new DOMParser(),
|
||||
});
|
||||
|
||||
console.log('Build completed:', result);
|
||||
} catch (error) {
|
||||
console.error('Build failed:', error);
|
||||
} finally {
|
||||
setIsBuildLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const runDeploy = async () => {
|
||||
if (isDeployLoading || !project) return;
|
||||
|
||||
// Check if user is logged in
|
||||
if (!user || !user.signer) {
|
||||
toast({
|
||||
title: "Authentication required",
|
||||
description: "Please log in to deploy your project.",
|
||||
variant: "destructive",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
setIsDeployLoading(true);
|
||||
updateMetadata('Shakespeare', `Deploying ${project.name}...`);
|
||||
|
||||
try {
|
||||
const result = await deployProject({
|
||||
projectId: project.id,
|
||||
deployServer: config.deployServer,
|
||||
fs,
|
||||
projectPath: `/projects/${project.id}`,
|
||||
signer: user.signer,
|
||||
});
|
||||
|
||||
console.log('Project deployed:', result.url);
|
||||
|
||||
toast({
|
||||
title: "Deployment successful!",
|
||||
description: `Your project is now live at ${result.hostname}`,
|
||||
});
|
||||
|
||||
// Open the deployed site in a new tab
|
||||
window.open(result.url, '_blank');
|
||||
} catch (error) {
|
||||
console.error('Deploy failed:', error);
|
||||
|
||||
toast({
|
||||
title: "Deployment failed",
|
||||
description: error instanceof Error ? error.message : "An unexpected error occurred",
|
||||
variant: "destructive",
|
||||
});
|
||||
} finally {
|
||||
setIsDeployLoading(false);
|
||||
}
|
||||
await build.mutateAsync(undefined, {
|
||||
onSuccess(result) {
|
||||
console.log('Project built:', result);
|
||||
},
|
||||
onError(error) {
|
||||
console.error('Build failed:', error);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const handleNewChat = () => {
|
||||
@@ -203,7 +162,7 @@ export function ProjectView() {
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="block p-0 h-auto text-sm font-semibold truncate hover:bg-transparent hover:text-primary"
|
||||
onClick={() => setIsProjectInfoOpen(true)}
|
||||
onClick={() => setIsProjectDetailsOpen(true)}
|
||||
>
|
||||
{project.name}
|
||||
</Button>
|
||||
@@ -225,13 +184,10 @@ export function ProjectView() {
|
||||
projectId={project.id}
|
||||
projectName={project.name}
|
||||
onNewChat={handleNewChat}
|
||||
onBuild={runBuild}
|
||||
onDeploy={runDeploy}
|
||||
onProjectDetails={() => setIsProjectDetailsOpen(true)}
|
||||
isLoading={isAILoading}
|
||||
isBuildLoading={isBuildLoading}
|
||||
isDeployLoading={isDeployLoading}
|
||||
isBuildLoading={build.isPending}
|
||||
onFirstInteraction={handleFirstInteraction}
|
||||
onProjectDeleted={handleProjectDeleted}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
@@ -279,12 +235,10 @@ export function ProjectView() {
|
||||
projectId={project.id}
|
||||
onNewChat={handleNewChat}
|
||||
onBuild={runBuild}
|
||||
onDeploy={runDeploy}
|
||||
onFirstInteraction={handleFirstInteraction}
|
||||
onLoadingChange={handleAILoadingChange}
|
||||
isLoading={isAILoading}
|
||||
isBuildLoading={isBuildLoading}
|
||||
isDeployLoading={isDeployLoading}
|
||||
isBuildLoading={build.isPending}
|
||||
/>
|
||||
) : (
|
||||
<div className="h-full p-4 space-y-4">
|
||||
@@ -300,6 +254,8 @@ export function ProjectView() {
|
||||
<PreviewPane
|
||||
projectId={project.id}
|
||||
activeTab={mobileView}
|
||||
projectName={project.name}
|
||||
onFirstInteraction={handleFirstInteraction}
|
||||
/>
|
||||
) : (
|
||||
<div className="h-full p-4 space-y-4">
|
||||
@@ -322,16 +278,18 @@ export function ProjectView() {
|
||||
<MessageSquare className="h-4 w-4 mr-1" />
|
||||
{t('chat')}
|
||||
</Button>
|
||||
<Button
|
||||
variant={mobileView === 'preview' ? 'default' : 'ghost'}
|
||||
size="sm"
|
||||
onClick={() => setMobileView('preview')}
|
||||
className="flex-1 rounded-none"
|
||||
disabled={!project}
|
||||
>
|
||||
<Eye className="h-4 w-4 mr-1" />
|
||||
{t('preview')}
|
||||
</Button>
|
||||
{isPreviewable && (
|
||||
<Button
|
||||
variant={mobileView === 'preview' ? 'default' : 'ghost'}
|
||||
size="sm"
|
||||
onClick={() => setMobileView('preview')}
|
||||
className="flex-1 rounded-none"
|
||||
disabled={!project}
|
||||
>
|
||||
<Eye className="h-4 w-4 mr-1" />
|
||||
{t('preview')}
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
variant={mobileView === 'code' ? 'default' : 'ghost'}
|
||||
size="sm"
|
||||
@@ -348,12 +306,13 @@ export function ProjectView() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Project Info Dialog */}
|
||||
{/* Project Details Dialog */}
|
||||
{project && (
|
||||
<ProjectInfoDialog
|
||||
<ProjectDetailsDialog
|
||||
project={project}
|
||||
open={isProjectInfoOpen}
|
||||
onOpenChange={setIsProjectInfoOpen}
|
||||
open={isProjectDetailsOpen}
|
||||
onOpenChange={setIsProjectDetailsOpen}
|
||||
onProjectDeleted={handleProjectDeleted}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
@@ -409,7 +368,7 @@ export function ProjectView() {
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="block p-0 h-auto font-semibold text-lg truncate hover:bg-transparent hover:text-primary"
|
||||
onClick={() => setIsProjectInfoOpen(true)}
|
||||
onClick={() => setIsProjectDetailsOpen(true)}
|
||||
>
|
||||
{project.name}
|
||||
</Button>
|
||||
@@ -432,13 +391,10 @@ export function ProjectView() {
|
||||
projectId={project.id}
|
||||
projectName={project.name}
|
||||
onNewChat={handleNewChat}
|
||||
onBuild={runBuild}
|
||||
onDeploy={runDeploy}
|
||||
onProjectDetails={() => setIsProjectDetailsOpen(true)}
|
||||
isLoading={isAILoading}
|
||||
isBuildLoading={isBuildLoading}
|
||||
isDeployLoading={isDeployLoading}
|
||||
isBuildLoading={build.isPending}
|
||||
onFirstInteraction={handleFirstInteraction}
|
||||
onProjectDeleted={handleProjectDeleted}
|
||||
/>
|
||||
</>
|
||||
) : (
|
||||
@@ -459,12 +415,10 @@ export function ProjectView() {
|
||||
projectId={project.id}
|
||||
onNewChat={handleNewChat}
|
||||
onBuild={runBuild}
|
||||
onDeploy={runDeploy}
|
||||
onFirstInteraction={handleFirstInteraction}
|
||||
onLoadingChange={handleAILoadingChange}
|
||||
isLoading={isAILoading}
|
||||
isBuildLoading={isBuildLoading}
|
||||
isDeployLoading={isDeployLoading}
|
||||
isBuildLoading={build.isPending}
|
||||
/>
|
||||
) : (
|
||||
<div className="h-full p-4 space-y-4">
|
||||
@@ -483,61 +437,35 @@ export function ProjectView() {
|
||||
|
||||
{/* Preview/Code Panel */}
|
||||
<ResizablePanel defaultSize={60} minSize={30}>
|
||||
<div className="h-full flex flex-col">
|
||||
{/* Preview Header */}
|
||||
<div className="h-12 px-4 border-b flex-shrink-0">
|
||||
<div className="flex items-center justify-between h-12">
|
||||
<div className="flex space-x-2">
|
||||
<Button
|
||||
variant={activeTab === 'preview' ? 'default' : 'ghost'}
|
||||
size="sm"
|
||||
onClick={() => setActiveTab('preview')}
|
||||
disabled={!project}
|
||||
>
|
||||
{t('preview')}
|
||||
</Button>
|
||||
<Button
|
||||
variant={activeTab === 'code' ? 'default' : 'ghost'}
|
||||
size="sm"
|
||||
onClick={() => setActiveTab('code')}
|
||||
className="gap-2"
|
||||
disabled={!project}
|
||||
>
|
||||
{t('code')}
|
||||
{activeTab !== 'code' && project && (
|
||||
<GitStatusIndicator projectId={project.id} />
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
<div className="h-full">
|
||||
{project ? (
|
||||
<PreviewPane
|
||||
projectId={project.id}
|
||||
activeTab={isPreviewable ? activeTab : 'code'}
|
||||
onToggleView={isPreviewable ? () => setActiveTab(activeTab === 'preview' ? 'code' : 'preview') : undefined}
|
||||
projectName={project.name}
|
||||
onFirstInteraction={handleFirstInteraction}
|
||||
isPreviewable={isPreviewable}
|
||||
/>
|
||||
) : (
|
||||
<div className="h-full p-4 space-y-4">
|
||||
<Skeleton className="h-8 w-32" />
|
||||
<Skeleton className="h-full w-full" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Preview Content */}
|
||||
<div className="flex-1 overflow-hidden">
|
||||
{project ? (
|
||||
<PreviewPane
|
||||
projectId={project.id}
|
||||
activeTab={activeTab}
|
||||
/>
|
||||
) : (
|
||||
<div className="h-full p-4 space-y-4">
|
||||
<Skeleton className="h-8 w-32" />
|
||||
<Skeleton className="h-full w-full" />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</ResizablePanel>
|
||||
</ResizablePanelGroup>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Project Info Dialog */}
|
||||
{/* Project Details Dialog */}
|
||||
{project && (
|
||||
<ProjectInfoDialog
|
||||
<ProjectDetailsDialog
|
||||
project={project}
|
||||
open={isProjectInfoOpen}
|
||||
onOpenChange={setIsProjectInfoOpen}
|
||||
open={isProjectDetailsOpen}
|
||||
onOpenChange={setIsProjectDetailsOpen}
|
||||
onProjectDeleted={handleProjectDeleted}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Bot, GitBranch, Database, Wifi, Settings2, Info } from 'lucide-react';
|
||||
import { Bot, GitBranch, Database, Wifi, Settings2, Info, Mail } from 'lucide-react';
|
||||
import { useIsMobile } from '@/hooks/useIsMobile';
|
||||
|
||||
interface SettingsItem {
|
||||
@@ -48,6 +48,13 @@ const getSettingsItems = (t: (key: string) => string): SettingsItem[] => [
|
||||
icon: Database,
|
||||
href: '/settings/data',
|
||||
},
|
||||
{
|
||||
id: 'email',
|
||||
title: t('emailUpdates'),
|
||||
description: t('emailUpdatesDescription'),
|
||||
icon: Mail,
|
||||
href: '/settings/email',
|
||||
},
|
||||
{
|
||||
id: 'about',
|
||||
title: t('aboutShakespeare'),
|
||||
|
||||
Reference in new issue
Block a user