diff --git a/src/components/deploy/DeploySteps.tsx b/src/components/deploy/DeploySteps.tsx index 004c3745..b28880b0 100644 --- a/src/components/deploy/DeploySteps.tsx +++ b/src/components/deploy/DeploySteps.tsx @@ -1,6 +1,6 @@ import { useState, useEffect, useCallback } from 'react'; import { useTranslation } from 'react-i18next'; -import { Rocket, ExternalLink, AlertCircle, Settings, Cloud } from 'lucide-react'; +import { Rocket, ExternalLink, AlertCircle, Settings, Cloud, History } from 'lucide-react'; import { ExternalFavicon } from '@/components/ExternalFavicon'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; @@ -23,7 +23,8 @@ import { PRESET_DEPLOY_PROVIDERS } from '@/lib/deployProviderPresets'; import { ShakespeareDeployForm } from '@/components/deploy/ShakespeareDeployForm'; import { NetlifyDeployForm } from '@/components/deploy/NetlifyDeployForm'; import { VercelDeployForm } from '@/components/deploy/VercelDeployForm'; -import { NsiteDeployForm } from '@/components/deploy/NsiteDeployForm'; +import { NsiteSettingsDialog } from '@/components/deploy/NsiteSettingsDialog'; +import { NsiteVersionsDialog } from '@/components/deploy/NsiteVersionsDialog'; import { CloudflareDeployForm } from '@/components/deploy/CloudflareDeployForm'; import { DenoDeployForm } from '@/components/deploy/DenoDeployForm'; import { RailwayDeployForm } from '@/components/deploy/RailwayDeployForm'; @@ -39,6 +40,7 @@ import { RailwayAdapter } from '@/lib/deploy/RailwayAdapter'; import { readNsiteVfsConfig, writeNsiteVfsConfig } from '@/lib/nsiteConfig'; import type { NsiteVfsConfig } from '@/lib/nsiteConfig'; import { projectNameToDTag } from '@/lib/utils/nsite'; +import type { NsiteProvider } from '@/contexts/DeploySettingsContext'; /** * Normalize a URL string to ensure it has a protocol @@ -104,10 +106,25 @@ interface ShakespeareFormData { subdomain: string; } -interface NsiteFormData { - siteTitle: string; - siteDescription: string; - dTag: string; +/** + * Build a complete NsiteVfsConfig from provider defaults — used when the + * project has no .nsite/config.json yet. The dTag is derived from the + * project name so the very first deploy already has a stable identifier. + */ +async function buildSeedNsiteConfig( + nsiteProvider: NsiteProvider, + projectName: string, +): Promise { + const dTag = await projectNameToDTag(projectName); + return { + relays: nsiteProvider.relayUrls, + servers: nsiteProvider.blossomServers, + id: dTag, + title: projectName, + fallback: '/index.html', + gatewayHostnames: [nsiteProvider.gateway], + publishSnapshotOnDeploy: false, + }; } interface NetlifyFormData { @@ -154,12 +171,14 @@ export function DeploySteps({ projectId, projectName, onClose }: DeployStepsProp const [error, setError] = useState(null); const [isShakespeareFormValid, setIsShakespeareFormValid] = useState(true); - // .nsite/config.json state — loaded once on mount, used to skip config form on re-deploy + // .nsite/config.json state — loaded once on mount. Source of truth for all + // per-project site settings (relays, servers, title, etc.). Editable via the + // NsiteSettingsDialog. When the project has no config yet, we auto-seed one + // from the selected nsite provider so deploy works out of the box. const [nsiteVfsConfig, setNsiteVfsConfig] = useState(null); const [nsiteVfsConfigLoading, setNsiteVfsConfigLoading] = useState(true); - // When a .nsite/config.json already exists, hide the full form and show a summary instead. - // The user can click "Edit" to expand it. - const [nsiteShowFullForm, setNsiteShowFullForm] = useState(false); + const [nsiteSettingsOpen, setNsiteSettingsOpen] = useState(false); + const [nsiteVersionsOpen, setNsiteVersionsOpen] = useState(false); useEffect(() => { if (!projectId) { @@ -167,22 +186,9 @@ export function DeploySteps({ projectId, projectName, onClose }: DeployStepsProp return; } const projectPath = `${projectsPath}/${projectId}`; + setNsiteVfsConfigLoading(true); readNsiteVfsConfig(fs, projectPath) - .then((cfg) => { - setNsiteVfsConfig(cfg); - // If a config already exists, seed the form from it and stay in summary mode. - // If not, show the full form so the user can configure for the first time. - if (cfg) { - setNsiteForm({ - siteTitle: cfg.title ?? '', - siteDescription: cfg.description ?? '', - dTag: (cfg.id != null && cfg.id !== '') ? cfg.id : '', - }); - setNsiteShowFullForm(false); - } else { - setNsiteShowFullForm(true); - } - }) + .then((cfg) => setNsiteVfsConfig(cfg)) .finally(() => setNsiteVfsConfigLoading(false)); }, [fs, projectsPath, projectId]); @@ -190,11 +196,6 @@ export function DeploySteps({ projectId, projectName, onClose }: DeployStepsProp const [shakespeareForm, setShakespeareForm] = useState({ subdomain: projectId, }); - const [nsiteForm, setNsiteForm] = useState({ - siteTitle: '', - siteDescription: '', - dTag: '', - }); const [netlifyForm, setNetlifyForm] = useState({ siteId: '', siteName: '', @@ -233,6 +234,46 @@ export function DeploySteps({ projectId, projectName, onClose }: DeployStepsProp const selectedProvider = settings.providers.find(p => p.id === selectedProviderId); + // Auto-seed .nsite/config.json from the provider when: + // - an nsite provider is selected, + // - the load effect has finished, + // - and the project has no config yet. + // This means a fresh project immediately surfaces a summary card with sane + // defaults and the user can edit anytime via the settings dialog. + useEffect(() => { + if (!projectId) return; + if (nsiteVfsConfigLoading) return; + if (nsiteVfsConfig) return; + if (selectedProvider?.type !== 'nsite') return; + + const projectPath = `${projectsPath}/${projectId}`; + let cancelled = false; + + buildSeedNsiteConfig(selectedProvider, projectName || projectId) + .then(async (cfg) => { + if (cancelled) return; + try { + await writeNsiteVfsConfig(fs, projectPath, cfg); + if (cancelled) return; + setNsiteVfsConfig(cfg); + } catch (err) { + console.warn('Failed to auto-seed .nsite/config.json:', err); + } + }); + + return () => { + cancelled = true; + }; + }, [ + projectId, + projectsPath, + nsiteVfsConfig, + nsiteVfsConfigLoading, + selectedProvider, + fs, + projectName, + ]); + const handleDeploy = async () => { if (!selectedProvider) return; @@ -265,21 +306,28 @@ export function DeploySteps({ projectId, projectName, onClose }: DeployStepsProp throw new Error('You must be logged in to deploy to nsite.'); } + if (!nsiteVfsConfig) { + throw new Error('nsite settings are not configured for this project yet.'); + } + const sourceUrl = await resolveNsiteSourceUrl( await git.getRemoteURL(projectPath, 'origin') ); + // Source of truth is .nsite/config.json — provider only contributes the + // gateway (host-level, not a manifest field). adapter = new NsiteAdapter({ fs, nostr, signer: user.signer, gateway: nsiteProvider.gateway, - relayUrls: nsiteProvider.relayUrls, - blossomServers: nsiteProvider.blossomServers, - siteTitle: nsiteForm.siteTitle || undefined, - siteDescription: nsiteForm.siteDescription || undefined, + relayUrls: nsiteVfsConfig.relays, + blossomServers: nsiteVfsConfig.servers, + siteTitle: nsiteVfsConfig.title || undefined, + siteDescription: nsiteVfsConfig.description || undefined, sourceUrl, - siteIdentifier: nsiteForm.dTag || undefined, + siteIdentifier: (nsiteVfsConfig.id != null && nsiteVfsConfig.id !== '') ? nsiteVfsConfig.id : undefined, + publishSnapshotOnDeploy: nsiteVfsConfig.publishSnapshotOnDeploy ?? false, }); } else if (selectedProvider.type === 'netlify') { const netlifyProvider = selectedProvider; @@ -388,28 +436,23 @@ export function DeploySteps({ projectId, projectName, onClose }: DeployStepsProp type: 'nsite', url: result.url, data: { - siteTitle: nsiteForm.siteTitle || undefined, - siteDescription: nsiteForm.siteDescription || undefined, - dTag: nsiteForm.dTag || undefined, + siteTitle: nsiteVfsConfig?.title || undefined, + siteDescription: nsiteVfsConfig?.description || undefined, + dTag: nsiteVfsConfig?.id || undefined, }, }); - // Write .nsite/config.json for nsyte CLI interoperability. - // This file is safe to commit — it never contains the nsec. - const nsiteProvider = selectedProvider; - const newNsiteVfsConfig: NsiteVfsConfig = { - relays: nsiteProvider.relayUrls, - servers: nsiteProvider.blossomServers, - id: nsiteForm.dTag || undefined, - title: nsiteForm.siteTitle || undefined, - description: nsiteForm.siteDescription || undefined, - fallback: '/index.html', - gatewayHostnames: [nsiteProvider.gateway], - }; - await writeNsiteVfsConfig(fs, projectPath, newNsiteVfsConfig); - // Update in-memory state so summary view reflects new values immediately - setNsiteVfsConfig(newNsiteVfsConfig); - setNsiteShowFullForm(false); + // Refresh .nsite/config.json's gatewayHostnames so the file reflects + // the most recent provider the project actually deployed through. + // All other fields are already authoritative on disk. + if (nsiteVfsConfig) { + const refreshed: NsiteVfsConfig = { + ...nsiteVfsConfig, + gatewayHostnames: [selectedProvider.gateway], + }; + await writeNsiteVfsConfig(fs, projectPath, refreshed); + setNsiteVfsConfig(refreshed); + } } else if (selectedProvider.type === 'netlify') { await updateProjectSettings(selectedProviderId, { type: 'netlify', @@ -517,14 +560,12 @@ export function DeploySteps({ projectId, projectName, onClose }: DeployStepsProp setError(null); // Reset forms setShakespeareForm({ subdomain: projectId }); - setNsiteForm({ siteTitle: '', siteDescription: '', dTag: '' }); setNetlifyForm({ siteId: '', siteName: '' }); setVercelForm({ projectName: projectName || projectId, teamId: '' }); setCloudflareForm({ projectName: projectName || projectId }); setDenoDeployForm({ projectName: projectName || projectId }); setRailwayForm({ workspaceId: '', projectId: '', environmentId: '', serviceId: '', projectName: projectName || projectId }); - // Return to summary mode so next open shows the compact view (if config exists) - setNsiteShowFullForm(false); + setNsiteSettingsOpen(false); onClose(); }; @@ -536,18 +577,12 @@ export function DeploySteps({ projectId, projectName, onClose }: DeployStepsProp setIsShakespeareFormValid(isValid); }, []); - const handleNsiteSiteTitleChange = useCallback((siteTitle: string) => { - setNsiteForm(prev => ({ ...prev, siteTitle })); - // Derive the dTag from the title so the user never has to think about it. - // Falls back to projectName when the title is blank. - projectNameToDTag(siteTitle || projectName).then(dTag => { - setNsiteForm(prev => ({ ...prev, dTag })); - }); - }, [projectName]); - - const handleNsiteSiteDescriptionChange = useCallback((siteDescription: string) => { - setNsiteForm(prev => ({ ...prev, siteDescription })); - }, []); + const handleNsiteSettingsSave = useCallback(async (cfg: NsiteVfsConfig) => { + if (!projectId) return; + const projectPath = `${projectsPath}/${projectId}`; + await writeNsiteVfsConfig(fs, projectPath, cfg); + setNsiteVfsConfig(cfg); + }, [projectId, projectsPath, fs]); const handleNetlifySiteChange = useCallback((siteId: string, siteName: string) => { setNetlifyForm({ siteId, siteName }); @@ -595,72 +630,30 @@ export function DeploySteps({ projectId, projectName, onClose }: DeployStepsProp } if (selectedProvider.type === 'nsite') { - // While the .nsite/config.json load is still in flight, render nothing to avoid flicker - if (nsiteVfsConfigLoading) return null; + // While the .nsite/config.json load + auto-seed is still in flight, + // render nothing to avoid flicker. + if (nsiteVfsConfigLoading || !nsiteVfsConfig) return null; - // Summary view: shown when .nsite/config.json already exists and user hasn't clicked Edit - if (nsiteVfsConfig && !nsiteShowFullForm) { - const relayCount = nsiteVfsConfig.relays?.length ?? 0; - const serverCount = nsiteVfsConfig.servers?.length ?? 0; - - return ( -
-
- {nsiteVfsConfig.title && ( -
- Title - {nsiteVfsConfig.title} -
- )} - -
- Relays - {relayCount} configured -
-
- Blossom servers - {serverCount} configured -
-
- -
- ); - } - - // Full config form: shown on first deploy or when user clicks "Edit site settings" - const savedConfig = projectSettings.providers[selectedProviderId]; - const legacy = savedConfig?.type === 'nsite' ? savedConfig.data : undefined; - - // .nsite/config.json wins; .git/shakespeare/deploy.json is the legacy fallback - const savedSiteTitle = nsiteVfsConfig?.title ?? legacy?.siteTitle; - const savedSiteDescription = nsiteVfsConfig?.description ?? legacy?.siteDescription; + const relayCount = nsiteVfsConfig.relays?.length ?? 0; + const serverCount = nsiteVfsConfig.servers?.length ?? 0; return ( -
- - {nsiteVfsConfig && ( - +
+ {nsiteVfsConfig.title && ( +
+ Title + {nsiteVfsConfig.title} +
)} + +
+ Relays + {relayCount} configured +
+
+ Blossom servers + {serverCount} configured +
); } @@ -767,6 +760,27 @@ export function DeploySteps({ projectId, projectName, onClose }: DeployStepsProp return (
+ {nsiteVfsConfig && ( + + )} + + {nsiteVfsConfig && user && selectedProvider?.type === 'nsite' && ( + + )} +

Deploy your project

@@ -946,33 +960,62 @@ export function DeploySteps({ projectId, projectName, onClose }: DeployStepsProp )} {selectedProvider && ( - )} - + + + + {selectedProvider.type === 'nsite' && nsiteVfsConfig?.publishSnapshotOnDeploy && user && ( + + )} +

)} )} diff --git a/src/components/deploy/NsiteDeployForm.tsx b/src/components/deploy/NsiteDeployForm.tsx index 3f070fd9..fba13ef2 100644 --- a/src/components/deploy/NsiteDeployForm.tsx +++ b/src/components/deploy/NsiteDeployForm.tsx @@ -1,105 +1,161 @@ -import { useState, useEffect, useRef, useCallback } from 'react'; -import { AlertCircle } from 'lucide-react'; -import { Label } from '@/components/ui/label'; -import { Input } from '@/components/ui/input'; -import { Textarea } from '@/components/ui/textarea'; -import { Alert, AlertDescription } from '@/components/ui/alert'; +import { useState, useEffect, useRef, useCallback } from "react"; +import { AlertCircle } from "lucide-react"; +import { Label } from "@/components/ui/label"; +import { Input } from "@/components/ui/input"; +import { Textarea } from "@/components/ui/textarea"; +import { Alert, AlertDescription } from "@/components/ui/alert"; +import { Checkbox } from "@/components/ui/checkbox"; interface NsiteDeployFormProps { - /** Human-readable project name — used to default the title */ - projectName: string; - /** Persisted values from a previous deployment */ - savedSiteTitle?: string; - savedSiteDescription?: string; - /** Present only when the project was previously deployed with a dedicated keypair (v1) */ - savedNsec?: string; - onSiteTitleChange: (title: string) => void; - onSiteDescriptionChange: (description: string) => void; + /** Human-readable project name — used to default the title */ + projectName: string; + /** Persisted values from a previous deployment */ + savedSiteTitle?: string; + savedSiteDescription?: string; + savedPublishSnapshotOnDeploy?: boolean; + /** Present only when the project was previously deployed with a dedicated keypair (v1) */ + savedNsec?: string; + onSiteTitleChange: (title: string) => void; + onSiteDescriptionChange: (description: string) => void; + onPublishSnapshotOnDeployChange: (enabled: boolean) => void; } export function NsiteDeployForm({ - projectName, - savedSiteTitle, - savedSiteDescription, - savedNsec, - onSiteTitleChange, - onSiteDescriptionChange, + projectName, + savedSiteTitle, + savedSiteDescription, + savedPublishSnapshotOnDeploy, + savedNsec, + onSiteTitleChange, + onSiteDescriptionChange, + onPublishSnapshotOnDeployChange, }: NsiteDeployFormProps) { - const [siteTitle, setSiteTitle] = useState(savedSiteTitle ?? projectName); - const [siteDescription, setSiteDescription] = useState(savedSiteDescription ?? ''); + const [siteTitle, setSiteTitle] = useState(savedSiteTitle ?? projectName); + const [siteDescription, setSiteDescription] = useState( + savedSiteDescription ?? "", + ); + const [publishSnapshotOnDeploy, setPublishSnapshotOnDeploy] = useState( + savedPublishSnapshotOnDeploy ?? false, + ); - // On mount: sync all saved values to parent and set defaults. - // The component is keyed by selectedProviderId in DeploySteps, so this always - // runs with fresh props — no initialized guard needed. - const initializedRef = useRef(false); - const stableSyncToParent = useCallback(() => { - if (initializedRef.current) return; - initializedRef.current = true; + // On mount: sync all saved values to parent and set defaults. + // The component is keyed by selectedProviderId in DeploySteps, so this always + // runs with fresh props — no initialized guard needed. + const initializedRef = useRef(false); + const stableSyncToParent = useCallback(() => { + if (initializedRef.current) return; + initializedRef.current = true; - if (savedSiteDescription) onSiteDescriptionChange(savedSiteDescription); + if (savedSiteDescription) onSiteDescriptionChange(savedSiteDescription); - const initialTitle = savedSiteTitle ?? projectName; - if (initialTitle !== siteTitle) setSiteTitle(initialTitle); - onSiteTitleChange(initialTitle); - }, [savedSiteDescription, savedSiteTitle, siteTitle, projectName, onSiteDescriptionChange, onSiteTitleChange]); + const initialTitle = savedSiteTitle ?? projectName; + if (initialTitle !== siteTitle) setSiteTitle(initialTitle); + onSiteTitleChange(initialTitle); - useEffect(() => { - stableSyncToParent(); - }, [stableSyncToParent]); + onPublishSnapshotOnDeployChange(savedPublishSnapshotOnDeploy ?? false); + }, [ + savedSiteDescription, + savedSiteTitle, + savedPublishSnapshotOnDeploy, + siteTitle, + projectName, + onSiteDescriptionChange, + onSiteTitleChange, + onPublishSnapshotOnDeployChange, + ]); - const handleSiteTitleChange = (value: string) => { - setSiteTitle(value); - onSiteTitleChange(value); - }; + useEffect(() => { + stableSyncToParent(); + }, [stableSyncToParent]); - const handleSiteDescriptionChange = (value: string) => { - setSiteDescription(value); - onSiteDescriptionChange(value); - }; + const handleSiteTitleChange = (value: string) => { + setSiteTitle(value); + onSiteTitleChange(value); + }; - return ( -
+ const handleSiteDescriptionChange = (value: string) => { + setSiteDescription(value); + onSiteDescriptionChange(value); + }; - {/* Migration notice */} - {savedNsec && ( - - - - Site identity is changing. This project was previously deployed with a - dedicated private key. Going forward, it will deploy under your Nostr identity. The old - site will remain at its original address until overwritten. - - - )} + const handlePublishSnapshotOnDeployChange = (value: boolean) => { + setPublishSnapshotOnDeploy(value); + onPublishSnapshotOnDeployChange(value); + }; - {/* Site title */} -
- - handleSiteTitleChange(e.target.value)} - placeholder="My Nostr Site" - /> -

- Shown by nsite gateways and directories. Included as a title tag in the manifest. -

-
+ return ( +
+ {/* Migration notice */} + {savedNsec && ( + + + + Site identity is changing. This project was + previously deployed with a dedicated private key. Going forward, it + will deploy under your Nostr identity. The old site will remain at + its original address until overwritten. + + + )} - {/* Site description */} -
- -