Move nsite project settings into a dedicated edit modal

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) <[email protected]>
This commit is contained in:
hzrd149andClaude Opus 4.7 committed 2026-05-15 13:29:53 -05:00
1 parent d1e71184e6
commit a588509ec6
2 files changed
+366 -179

No files matched your search

+140 -179
View File
@@ -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<NsiteVfsConfig> {
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<string | null>(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<NsiteVfsConfig | null>(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<ShakespeareFormData>({
subdomain: projectId,
});
const [nsiteForm, setNsiteForm] = useState<NsiteFormData>({
siteTitle: '',
siteDescription: '',
dTag: '',
publishSnapshotOnDeploy: false,
});
const [netlifyForm, setNetlifyForm] = useState<NetlifyFormData>({
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 (
<div className="space-y-3">
<div className="rounded-md border bg-muted/30 p-3 space-y-2 text-sm">
{nsiteVfsConfig.title && (
<div className="flex justify-between">
<span className="text-muted-foreground">Title</span>
<span className="font-medium">{nsiteVfsConfig.title}</span>
</div>
)}
<div className="flex justify-between">
<span className="text-muted-foreground">Relays</span>
<span className="font-medium">{relayCount} configured</span>
</div>
<div className="flex justify-between">
<span className="text-muted-foreground">Blossom servers</span>
<span className="font-medium">{serverCount} configured</span>
</div>
<div className="flex justify-between">
<span className="text-muted-foreground">Version history</span>
<span className="font-medium">{nsiteVfsConfig.publishSnapshotOnDeploy ? 'Enabled' : 'Disabled'}</span>
</div>
</div>
<button
type="button"
className="text-xs text-muted-foreground underline hover:text-foreground transition-colors"
onClick={() => setNsiteShowFullForm(true)}
>
Edit site settings
</button>
</div>
);
}
// 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 (
<div className="space-y-3">
<NsiteDeployForm
key={selectedProviderId}
projectName={projectName || projectId}
savedNsec={legacy?.nsec}
savedSiteTitle={savedSiteTitle}
savedSiteDescription={savedSiteDescription}
savedPublishSnapshotOnDeploy={savedPublishSnapshotOnDeploy}
onSiteTitleChange={handleNsiteSiteTitleChange}
onSiteDescriptionChange={handleNsiteSiteDescriptionChange}
onPublishSnapshotOnDeployChange={handleNsitePublishSnapshotOnDeployChange}
/>
{nsiteVfsConfig && (
<button
type="button"
className="text-xs text-muted-foreground underline hover:text-foreground transition-colors"
onClick={() => setNsiteShowFullForm(false)}
>
Back to summary
</button>
)}
<div className="rounded-md border bg-muted/30 p-3 space-y-2 text-sm">
{nsiteVfsConfig.title && (
<div className="flex justify-between">
<span className="text-muted-foreground">Title</span>
<span className="font-medium">{nsiteVfsConfig.title}</span>
</div>
)}
<div className="flex justify-between">
<span className="text-muted-foreground">Relays</span>
<span className="font-medium">{relayCount} configured</span>
</div>
<div className="flex justify-between">
<span className="text-muted-foreground">Blossom servers</span>
<span className="font-medium">{serverCount} configured</span>
</div>
</div>
<button
type="button"
className="text-xs text-muted-foreground underline hover:text-foreground transition-colors"
onClick={() => setNsiteSettingsOpen(true)}
>
Edit site settings
</button>
</div>
);
}
@@ -817,6 +767,16 @@ export function DeploySteps({ projectId, projectName, onClose }: DeployStepsProp
return (
<div className="space-y-4">
{nsiteVfsConfig && (
<NsiteSettingsDialog
open={nsiteSettingsOpen}
onOpenChange={setNsiteSettingsOpen}
projectName={projectName || projectId}
initialConfig={nsiteVfsConfig}
onSave={handleNsiteSettingsSave}
/>
)}
<div>
<h3 className="font-semibold mb-1">Deploy your project</h3>
<p className="text-sm text-muted-foreground">
@@ -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) ||