diff --git a/src/components/deploy/DeploySteps.tsx b/src/components/deploy/DeploySteps.tsx index 1ec83c3b..b1edf6dc 100644 --- a/src/components/deploy/DeploySteps.tsx +++ b/src/components/deploy/DeploySteps.tsx @@ -38,6 +38,7 @@ import { DenoDeployAdapter } from '@/lib/deploy/DenoDeployAdapter'; import { RailwayAdapter } from '@/lib/deploy/RailwayAdapter'; import { readNsiteVfsConfig, writeNsiteVfsConfig } from '@/lib/nsiteConfig'; import type { NsiteVfsConfig } from '@/lib/nsiteConfig'; +import { projectNameToDTag } from '@/lib/utils/nsite'; /** * Normalize a URL string to ensure it has a protocol @@ -522,16 +523,17 @@ export function DeploySteps({ projectId, projectName, onClose }: DeployStepsProp 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 handleNsiteDTagChange = useCallback((dTag: string) => { - setNsiteForm(prev => ({ ...prev, dTag })); - }, []); - const handleNsiteSiteTypeChange = useCallback((siteType: 'named' | 'root') => { setNsiteForm(prev => ({ ...prev, siteType })); }, []); @@ -636,9 +638,6 @@ export function DeploySteps({ projectId, projectName, onClose }: DeployStepsProp // .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 savedDTag = (nsiteVfsConfig?.id != null && nsiteVfsConfig.id !== '') - ? nsiteVfsConfig.id - : legacy?.dTag; const savedSiteType = nsiteVfsConfig ? (nsiteVfsConfig.id === null ? 'root' : 'named') : legacy?.siteType; @@ -647,17 +646,13 @@ export function DeploySteps({ projectId, projectName, onClose }: DeployStepsProp
{nsiteVfsConfig && ( diff --git a/src/components/deploy/NsiteDeployForm.tsx b/src/components/deploy/NsiteDeployForm.tsx index a846b02b..ab7e79d2 100644 --- a/src/components/deploy/NsiteDeployForm.tsx +++ b/src/components/deploy/NsiteDeployForm.tsx @@ -1,75 +1,51 @@ import { useState, useEffect, useRef } from 'react'; -import { nip19 } from 'nostr-tools'; import { AlertCircle, Globe, Tag } 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 { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'; -import { projectNameToDTag, isValidDTag, pubkeyToBase36 } from '@/lib/utils/nsite'; interface NsiteDeployFormProps { - gateway: string; - /** Human-readable project name — used to derive the default dTag and title */ + /** Human-readable project name — used to default the title for named sites */ projectName: string; - /** Hex pubkey of the logged-in user — used for URL preview */ - userPubkey?: string; /** Persisted values from a previous deployment */ savedSiteTitle?: string; savedSiteDescription?: string; - savedDTag?: string; savedSiteType?: 'named' | 'root'; /** Present only when the project was previously deployed with a dedicated keypair (v1) */ savedNsec?: string; onSiteTitleChange: (title: string) => void; onSiteDescriptionChange: (description: string) => void; - onDTagChange: (dTag: string) => void; onSiteTypeChange: (type: 'named' | 'root') => void; } export function NsiteDeployForm({ - gateway, projectName, - userPubkey, savedSiteTitle, savedSiteDescription, - savedDTag, savedSiteType, savedNsec, onSiteTitleChange, onSiteDescriptionChange, - onDTagChange, onSiteTypeChange, }: NsiteDeployFormProps) { const [siteType, setSiteType] = useState<'named' | 'root'>(savedSiteType ?? 'named'); - const [dTag, setDTag] = useState(savedDTag ?? ''); const [siteTitle, setSiteTitle] = useState( savedSiteTitle ?? (savedSiteType === 'root' ? '' : projectName), ); const [siteDescription, setSiteDescription] = useState(savedSiteDescription ?? ''); - const [previewUrl, setPreviewUrl] = useState(''); - // On mount: sync all saved values to parent; derive dTag and title defaults when absent. - // The component is keyed by selectedProviderId in DeploySteps, so this effect always + // 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. useEffect(() => { if (savedSiteType) onSiteTypeChange(savedSiteType); if (savedSiteDescription) onSiteDescriptionChange(savedSiteDescription); - // Title: use saved value, else default to projectName for named sites only const initialTitle = savedSiteTitle ?? (siteType === 'named' ? projectName : ''); if (initialTitle !== siteTitle) setSiteTitle(initialTitle); onSiteTitleChange(initialTitle); - - // dTag: use saved value, else derive from project name - if (savedDTag) { - onDTagChange(savedDTag); - } else { - projectNameToDTag(projectName).then(derived => { - setDTag(derived); - onDTagChange(derived); - }); - } // eslint-disable-next-line react-hooks/exhaustive-deps }, []); @@ -82,47 +58,19 @@ export function NsiteDeployForm({ if (prev === siteType) return; if (siteType === 'named' && siteTitle === '') { - // Switching to named with a blank title → fill with project name setSiteTitle(projectName); onSiteTitleChange(projectName); } else if (siteType === 'root' && siteTitle === projectName) { - // Switching to root and title is still the auto-filled project name → clear it setSiteTitle(''); onSiteTitleChange(''); } }, [siteType, siteTitle, projectName, onSiteTitleChange]); - // Recompute preview URL whenever relevant state changes - useEffect(() => { - if (!userPubkey) { - setPreviewUrl(''); - return; - } - if (siteType === 'root') { - const npub = nip19.npubEncode(userPubkey); - setPreviewUrl(`https://${npub}.${gateway}`); - } else if (dTag && isValidDTag(dTag)) { - const base36 = pubkeyToBase36(userPubkey); - setPreviewUrl(`https://${base36}${dTag}.${gateway}`); - } else { - setPreviewUrl(''); - } - }, [userPubkey, siteType, dTag, gateway]); - const handleSiteTypeChange = (value: 'named' | 'root') => { setSiteType(value); onSiteTypeChange(value); }; - const handleDTagChange = (value: string) => { - // Allow lowercase alphanumeric and hyphens; strip everything else. - // Leading/trailing hyphens and consecutive hyphens are caught by isValidDTag - // and shown as a validation error rather than silently removed while typing. - const clean = value.toLowerCase().replace(/[^a-z0-9-]/g, ''); - setDTag(clean); - onDTagChange(clean); - }; - const handleSiteTitleChange = (value: string) => { setSiteTitle(value); onSiteTitleChange(value); @@ -133,8 +81,6 @@ export function NsiteDeployForm({ onSiteDescriptionChange(value); }; - const dTagInvalid = siteType === 'named' && dTag.length > 0 && !isValidDTag(dTag); - return (
@@ -166,7 +112,7 @@ export function NsiteDeployForm({ Named site

- A site with a custom identifier. You can have many named sites. + A site with a unique identifier. You can have many named sites.

@@ -185,30 +131,6 @@ export function NsiteDeployForm({ - {/* Named site identifier */} - {siteType === 'named' && ( -
- - handleDTagChange(e.target.value)} - placeholder="myblog" - maxLength={13} - className={dTagInvalid ? 'border-destructive' : ''} - /> - {dTagInvalid ? ( -

- Must be 1–13 lowercase letters, digits, or hyphens. Cannot start or end with a hyphen. -

- ) : ( -

- Lowercase letters, digits, and hyphens, max 13 characters. -

- )} -
- )} - {/* Root site warning */} {siteType === 'root' && ( @@ -220,16 +142,6 @@ export function NsiteDeployForm({ )} - {/* Live URL preview */} - {previewUrl && ( -
- -

- {previewUrl} -

-
- )} - {/* Site title */}