From a588509ec6927cf0d10e00ada26bd2185afd76cb Mon Sep 17 00:00:00 2001 From: hzrd149 Date: Fri, 15 May 2026 13:29:53 -0500 Subject: [PATCH] Move nsite project settings into a dedicated edit modal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaces the inline nsite config form in the deploy popover with a NsiteSettingsDialog that owns the full .nsite/config.json: title, description, version history toggle, and (under an "Advanced" collapsible) relays and Blossom servers. When a project has no .nsite/config.json yet, the deploy popover auto-seeds one from the selected nsite provider so the summary card appears immediately and deploy works out of the box. The Deploy button now reads relays/servers/title/description/dTag/version history directly from .nsite/config.json; only the gateway still comes from the provider since it is host-level, not manifest-level. The summary card hides the version-history state — it stays accessible via the settings modal only. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/components/deploy/DeploySteps.tsx | 319 ++++++++---------- src/components/deploy/NsiteSettingsDialog.tsx | 226 +++++++++++++ 2 files changed, 366 insertions(+), 179 deletions(-) create mode 100644 src/components/deploy/NsiteSettingsDialog.tsx diff --git a/src/components/deploy/DeploySteps.tsx b/src/components/deploy/DeploySteps.tsx index f21a0d43..17349286 100644 --- a/src/components/deploy/DeploySteps.tsx +++ b/src/components/deploy/DeploySteps.tsx @@ -23,7 +23,7 @@ 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 { CloudflareDeployForm } from '@/components/deploy/CloudflareDeployForm'; import { DenoDeployForm } from '@/components/deploy/DenoDeployForm'; import { RailwayDeployForm } from '@/components/deploy/RailwayDeployForm'; @@ -39,6 +39,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,11 +105,25 @@ interface ShakespeareFormData { subdomain: string; } -interface NsiteFormData { - siteTitle: string; - siteDescription: string; - dTag: string; - publishSnapshotOnDeploy: boolean; +/** + * 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 { @@ -155,12 +170,13 @@ 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); useEffect(() => { if (!projectId) { @@ -168,23 +184,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 : '', - publishSnapshotOnDeploy: cfg.publishSnapshotOnDeploy ?? false, - }); - setNsiteShowFullForm(false); - } else { - setNsiteShowFullForm(true); - } - }) + .then((cfg) => setNsiteVfsConfig(cfg)) .finally(() => setNsiteVfsConfigLoading(false)); }, [fs, projectsPath, projectId]); @@ -192,12 +194,6 @@ export function DeploySteps({ projectId, projectName, onClose }: DeployStepsProp const [shakespeareForm, setShakespeareForm] = useState({ subdomain: projectId, }); - const [nsiteForm, setNsiteForm] = useState({ - siteTitle: '', - siteDescription: '', - dTag: '', - publishSnapshotOnDeploy: false, - }); const [netlifyForm, setNetlifyForm] = useState({ siteId: '', siteName: '', @@ -236,6 +232,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; @@ -268,22 +304,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, - publishSnapshotOnDeploy: nsiteForm.publishSnapshotOnDeploy, + siteIdentifier: (nsiteVfsConfig.id != null && nsiteVfsConfig.id !== '') ? nsiteVfsConfig.id : undefined, + publishSnapshotOnDeploy: nsiteVfsConfig.publishSnapshotOnDeploy ?? false, }); } else if (selectedProvider.type === 'netlify') { const netlifyProvider = selectedProvider; @@ -392,29 +434,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], - publishSnapshotOnDeploy: nsiteForm.publishSnapshotOnDeploy, - }; - 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', @@ -522,14 +558,12 @@ export function DeploySteps({ projectId, projectName, onClose }: DeployStepsProp setError(null); // Reset forms setShakespeareForm({ subdomain: projectId }); - setNsiteForm({ siteTitle: '', siteDescription: '', dTag: '', publishSnapshotOnDeploy: false }); 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(); }; @@ -541,56 +575,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 handleNsitePublishSnapshotOnDeployChange = useCallback(async (publishSnapshotOnDeploy: boolean) => { - setNsiteForm(prev => ({ ...prev, publishSnapshotOnDeploy })); - - // Persist immediately so the choice survives closing the dialog without - // deploying. We assemble the full config from the currently-selected - // provider + form values so the file is valid even on first toggle - // (before any deploy has run). + const handleNsiteSettingsSave = useCallback(async (cfg: NsiteVfsConfig) => { if (!projectId) return; - if (selectedProvider?.type !== 'nsite') return; - const projectPath = `${projectsPath}/${projectId}`; - const cfg: NsiteVfsConfig = { - relays: selectedProvider.relayUrls, - servers: selectedProvider.blossomServers, - id: nsiteForm.dTag || undefined, - title: nsiteForm.siteTitle || undefined, - description: nsiteForm.siteDescription || undefined, - fallback: '/index.html', - gatewayHostnames: [selectedProvider.gateway], - publishSnapshotOnDeploy, - }; - - try { - await writeNsiteVfsConfig(fs, projectPath, cfg); - setNsiteVfsConfig(cfg); - } catch (err) { - console.warn('Failed to persist publishSnapshotOnDeploy to .nsite/config.json:', err); - } - }, [ - projectId, - projectsPath, - selectedProvider, - fs, - nsiteForm.dTag, - nsiteForm.siteTitle, - nsiteForm.siteDescription, - ]); + await writeNsiteVfsConfig(fs, projectPath, cfg); + setNsiteVfsConfig(cfg); + }, [projectId, projectsPath, fs]); const handleNetlifySiteChange = useCallback((siteId: string, siteName: string) => { setNetlifyForm({ siteId, siteName }); @@ -638,79 +628,39 @@ 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 -
-
- Version history - {nsiteVfsConfig.publishSnapshotOnDeploy ? 'Enabled' : 'Disabled'} -
-
- -
- ); - } - - // 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 savedPublishSnapshotOnDeploy = nsiteVfsConfig?.publishSnapshotOnDeploy ?? false; + 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 +
+
+
); } @@ -817,6 +767,16 @@ export function DeploySteps({ projectId, projectName, onClose }: DeployStepsProp return (
+ {nsiteVfsConfig && ( + + )} +

Deploy your project

@@ -1003,7 +963,8 @@ export function DeploySteps({ projectId, projectName, onClose }: DeployStepsProp (selectedProvider.type === 'shakespeare' && !user) || (selectedProvider.type === 'shakespeare' && !isShakespeareFormValid) || (selectedProvider.type === 'nsite' && !user) || - (selectedProvider.type === 'nsite' && !nsiteForm.dTag) || + (selectedProvider.type === 'nsite' && !nsiteVfsConfig) || + (selectedProvider.type === 'nsite' && (!nsiteVfsConfig?.relays?.length || !nsiteVfsConfig?.servers?.length)) || (selectedProvider.type === 'netlify' && !netlifyForm.siteId && !netlifyForm.siteName) || (selectedProvider.type === 'cloudflare' && !cloudflareForm.projectName) || (selectedProvider.type === 'deno' && !denoDeployForm.projectName) || diff --git a/src/components/deploy/NsiteSettingsDialog.tsx b/src/components/deploy/NsiteSettingsDialog.tsx new file mode 100644 index 00000000..1fa14244 --- /dev/null +++ b/src/components/deploy/NsiteSettingsDialog.tsx @@ -0,0 +1,226 @@ +import { useEffect, useState } from 'react'; +import { ChevronDown } from 'lucide-react'; +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, +} from '@/components/ui/dialog'; +import { Button } from '@/components/ui/button'; +import { Input } from '@/components/ui/input'; +import { Label } from '@/components/ui/label'; +import { Textarea } from '@/components/ui/textarea'; +import { Checkbox } from '@/components/ui/checkbox'; +import { + Collapsible, + CollapsibleContent, + CollapsibleTrigger, +} from '@/components/ui/collapsible'; +import { UrlListEditor } from '@/components/UrlListEditor'; +import { projectNameToDTag } from '@/lib/utils/nsite'; +import type { NsiteVfsConfig } from '@/lib/nsiteConfig'; + +interface NsiteSettingsDialogProps { + open: boolean; + onOpenChange: (open: boolean) => void; + /** Used to default the title when blank */ + projectName: string; + /** Current persisted config — controls initial field values */ + initialConfig: NsiteVfsConfig; + /** Called with the new config when the user clicks Save. May throw. */ + onSave: (cfg: NsiteVfsConfig) => Promise; +} + +/** + * Per-project nsite settings editor. + * + * Edits the full `.nsite/config.json` for a project: title, description, + * relays, blossom servers, and the "publish version history" flag. The `d` + * tag identifier is auto-derived from the title on save and never surfaced + * in the UI. + * + * The `gatewayHostnames` and `fallback` fields are preserved untouched so + * provider/CLI-managed metadata isn't clobbered. + */ +export function NsiteSettingsDialog({ + open, + onOpenChange, + projectName, + initialConfig, + onSave, +}: NsiteSettingsDialogProps) { + const [title, setTitle] = useState(initialConfig.title ?? ''); + const [description, setDescription] = useState(initialConfig.description ?? ''); + const [relays, setRelays] = useState(initialConfig.relays ?? []); + const [servers, setServers] = useState(initialConfig.servers ?? []); + const [publishSnapshotOnDeploy, setPublishSnapshotOnDeploy] = useState( + initialConfig.publishSnapshotOnDeploy ?? false, + ); + const [saving, setSaving] = useState(false); + const [error, setError] = useState(null); + const [advancedOpen, setAdvancedOpen] = useState(false); + + // Reset local state whenever the dialog re-opens with a different config + // (e.g. after a save from another tab, or when switching projects). + useEffect(() => { + if (!open) return; + setTitle(initialConfig.title ?? ''); + setDescription(initialConfig.description ?? ''); + setRelays(initialConfig.relays ?? []); + setServers(initialConfig.servers ?? []); + setPublishSnapshotOnDeploy(initialConfig.publishSnapshotOnDeploy ?? false); + setError(null); + setAdvancedOpen(false); + }, [open, initialConfig]); + + const hasRelays = relays.length > 0; + const hasServers = servers.length > 0; + const canSave = hasRelays && hasServers && !saving; + + const handleSave = async () => { + if (!canSave) return; + setSaving(true); + setError(null); + + try { + const effectiveTitle = title.trim() || projectName; + const dTag = await projectNameToDTag(effectiveTitle); + + const cfg: NsiteVfsConfig = { + ...initialConfig, + relays, + servers, + id: dTag, + title: title.trim() || undefined, + description: description.trim() || undefined, + fallback: initialConfig.fallback ?? '/index.html', + publishSnapshotOnDeploy, + }; + + await onSave(cfg); + onOpenChange(false); + } catch (err) { + setError(err instanceof Error ? err.message : 'Failed to save settings'); + } finally { + setSaving(false); + } + }; + + return ( +

+ + + nsite settings + + Per-project configuration for this nsite deployment. Saved to .nsite/config.json. + + + +
+ {/* Title */} +
+ + setTitle(e.target.value)} + placeholder={projectName} + /> +

+ Shown by nsite gateways and directories. Defaults to the project name when blank. +

+
+ + {/* Description */} +
+ +