From 8b9d87b5d55e10f46b958a29b384587512ff87a9 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 21 Dec 2025 00:55:51 -0600 Subject: [PATCH] Sync user grasp servers --- src/App.tsx | 8 +- src/components/AppProvider.tsx | 12 +- src/components/GraspListManager.tsx | 225 ++++++++++++++++++ src/components/NostrProvider.tsx | 2 +- src/components/NostrSync.tsx | 41 ++++ src/components/SentryProvider.test.tsx | 20 +- .../git/AnnounceRepositoryDialog.tsx | 28 ++- src/contexts/AppContext.ts | 11 +- src/hooks/useGenerateProjectInfo.test.ts | 10 +- src/hooks/useGit.test.ts | 8 +- src/hooks/useGit.ts | 15 +- src/lib/SessionManager.test.ts | 2 +- src/lib/system.test.ts | 2 +- src/pages/NostrSettings.tsx | 88 +------ src/test/TestApp.tsx | 8 +- 15 files changed, 365 insertions(+), 115 deletions(-) create mode 100644 src/components/GraspListManager.tsx diff --git a/src/App.tsx b/src/App.tsx index 1992a68d..d1d388f4 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -106,6 +106,13 @@ const defaultConfig: AppConfig = { ], updatedAt: 0, }, + graspMetadata: { + relays: [ + { url: 'wss://git.shakespeare.diy/' }, + { url: 'wss://relay.ngit.dev/' }, + ], + updatedAt: 0, + }, templates: [ { name: "MKStack", @@ -129,7 +136,6 @@ const defaultConfig: AppConfig = { previewDomain: "local-shakespeare.dev", showcaseEnabled: true, showcaseModerator: "npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc", - ngitServers: ["git.shakespeare.diy", "relay.ngit.dev"], fsPathProjects: electronPaths.fsPathProjects, fsPathConfig: electronPaths.fsPathConfig, fsPathTmp: electronPaths.fsPathTmp, diff --git a/src/components/AppProvider.tsx b/src/components/AppProvider.tsx index 069efb80..c424e94e 100644 --- a/src/components/AppProvider.tsx +++ b/src/components/AppProvider.tsx @@ -1,7 +1,7 @@ import { ReactNode, useEffect } from 'react'; import { z } from 'zod'; import { useLocalStorage } from '@/hooks/useLocalStorage'; -import { AppContext, type AppConfig, type AppContextType, type Theme, type RelayMetadata } from '@/contexts/AppContext'; +import { AppContext, type AppConfig, type AppContextType, type Theme, type RelayMetadata, type GraspMetadata } from '@/contexts/AppContext'; import i18n from '@/lib/i18n'; interface AppProviderProps { @@ -22,6 +22,14 @@ const RelayMetadataSchema = z.object({ updatedAt: z.number(), }) satisfies z.ZodType; +// Zod schema for GraspMetadata +const GraspMetadataSchema = z.object({ + relays: z.array(z.object({ + url: z.string().url(), + })), + updatedAt: z.number(), +}) satisfies z.ZodType; + // Zod schema for ProjectTemplate const ProjectTemplateSchema = z.object({ name: z.string().min(1), @@ -33,6 +41,7 @@ const ProjectTemplateSchema = z.object({ const AppConfigSchema = z.object({ theme: z.enum(['dark', 'light', 'system']), relayMetadata: RelayMetadataSchema, + graspMetadata: GraspMetadataSchema, templates: z.array(ProjectTemplateSchema), esmUrl: z.string().url(), corsProxy: z.string().url(), @@ -41,7 +50,6 @@ const AppConfigSchema = z.object({ language: z.string(), showcaseEnabled: z.boolean(), showcaseModerator: z.string(), - ngitServers: z.array(z.string()), fsPathProjects: z.string().min(1), fsPathConfig: z.string().min(1), fsPathTmp: z.string().min(1), diff --git a/src/components/GraspListManager.tsx b/src/components/GraspListManager.tsx new file mode 100644 index 00000000..8c92e388 --- /dev/null +++ b/src/components/GraspListManager.tsx @@ -0,0 +1,225 @@ +import { useState, useEffect } from 'react'; +import { Plus, X, Server } from 'lucide-react'; +import { useTranslation } from 'react-i18next'; +import { Button } from '@/components/ui/button'; +import { Label } from '@/components/ui/label'; +import { Input } from '@/components/ui/input'; +import { useAppContext } from '@/hooks/useAppContext'; +import { useCurrentUser } from '@/hooks/useCurrentUser'; +import { useNostrPublish } from '@/hooks/useNostrPublish'; +import { toast } from '@/hooks/useToast'; + +export function GraspListManager() { + const { t } = useTranslation(); + const { config, updateConfig } = useAppContext(); + const { user } = useCurrentUser(); + const { mutate: publishEvent } = useNostrPublish(); + + const [graspRelays, setGraspRelays] = useState<{ url: string }[]>(config.graspMetadata.relays); + const [newRelayUrl, setNewRelayUrl] = useState(''); + + // Sync local state with config when it changes (e.g., from NostrProvider sync) + useEffect(() => { + setGraspRelays(config.graspMetadata.relays); + }, [config.graspMetadata.relays]); + + const normalizeRelayUrl = (url: string): string => { + url = url.trim(); + try { + const parsed = new URL(url); + // Ensure it's a websocket URL + if (parsed.protocol !== 'ws:' && parsed.protocol !== 'wss:') { + parsed.protocol = 'wss:'; + } + // Ensure trailing slash + if (!parsed.pathname.endsWith('/')) { + parsed.pathname += '/'; + } + return parsed.toString(); + } catch { + // If parsing fails, try to construct a valid URL + try { + const withProtocol = url.startsWith('ws://') || url.startsWith('wss://') + ? url + : `wss://${url}`; + const parsed = new URL(withProtocol); + if (!parsed.pathname.endsWith('/')) { + parsed.pathname += '/'; + } + return parsed.toString(); + } catch { + return url; + } + } + }; + + const isValidRelayUrl = (url: string): boolean => { + const trimmed = url.trim(); + if (!trimmed) return false; + + const normalized = normalizeRelayUrl(trimmed); + try { + const parsed = new URL(normalized); + return parsed.protocol === 'ws:' || parsed.protocol === 'wss:'; + } catch { + return false; + } + }; + + const handleAddRelay = () => { + if (!isValidRelayUrl(newRelayUrl)) { + toast({ + title: 'Invalid relay URL', + description: 'Please enter a valid websocket URL (e.g., wss://git.shakespeare.diy/)', + variant: 'destructive', + }); + return; + } + + const normalized = normalizeRelayUrl(newRelayUrl); + + if (graspRelays.some(r => r.url === normalized)) { + toast({ + title: 'Relay already exists', + description: 'This relay is already in your list', + variant: 'destructive', + }); + return; + } + + const newRelays = [...graspRelays, { url: normalized }]; + setGraspRelays(newRelays); + setNewRelayUrl(''); + + saveRelays(newRelays); + }; + + const handleRemoveRelay = (url: string) => { + const newRelays = graspRelays.filter(r => r.url !== url); + setGraspRelays(newRelays); + saveRelays(newRelays); + }; + + const saveRelays = (newRelays: { url: string }[]) => { + const now = Math.floor(Date.now() / 1000); + + // Update local config + updateConfig((current) => ({ + ...current, + graspMetadata: { + relays: newRelays, + updatedAt: now, + }, + })); + + // Publish to Nostr if user is logged in + if (user) { + publishNIP34GraspList(newRelays); + } + }; + + const publishNIP34GraspList = (relays: { url: string }[]) => { + const tags = relays.map(relay => ['g', relay.url]); + + publishEvent( + { + kind: 10317, + content: '', + tags, + }, + { + onSuccess: () => { + toast({ + title: 'Grasp list published', + description: 'Your Nostr git server list has been published to your relays', + }); + }, + onError: (error) => { + console.error('Failed to publish grasp list:', error); + toast({ + title: 'Publish failed', + description: 'Failed to publish your grasp server list', + variant: 'destructive', + }); + }, + } + ); + }; + + const renderRelayUrl = (url: string): string => { + try { + const parsed = new URL(url); + if (parsed.pathname === '/') { + return parsed.host; + } else { + return parsed.host + parsed.pathname; + } + } catch { + return url; + } + }; + + return ( +
+ {/* Relay List */} +
+ {graspRelays.map((relay) => ( +
+ + + {renderRelayUrl(relay.url)} + + +
+ ))} +
+ + {/* Add Relay Form */} +
+
+ + setNewRelayUrl(e.target.value)} + onKeyDown={(e) => { + if (e.key === 'Enter') { + handleAddRelay(); + } + }} + /> +
+ +
+ + {!user && ( +

+ Log in to sync your grasp server list with Nostr +

+ )} +
+ ); +} diff --git a/src/components/NostrProvider.tsx b/src/components/NostrProvider.tsx index 535e559f..04ac9e89 100644 --- a/src/components/NostrProvider.tsx +++ b/src/components/NostrProvider.tsx @@ -19,7 +19,7 @@ const NostrProvider: React.FC = (props) => { const { children } = props; const { config } = useAppContext(); - const gitRelays = config.ngitServers.map(server => `wss://${server}/`); + const gitRelays = config.graspMetadata.relays.map(r => r.url); const queryClient = useQueryClient(); // Create NPool instance only once diff --git a/src/components/NostrSync.tsx b/src/components/NostrSync.tsx index e8a6c7fd..38509906 100644 --- a/src/components/NostrSync.tsx +++ b/src/components/NostrSync.tsx @@ -10,6 +10,7 @@ import { useContacts } from '@/hooks/useContacts'; * This component runs globally to sync various Nostr data when the user logs in. * Currently syncs: * - NIP-65 relay list (kind 10002) + * - NIP-34 grasp server list (kind 10317) */ export function NostrSync() { const { nostr } = useNostr(); @@ -62,5 +63,45 @@ export function NostrSync() { syncRelaysFromNostr(); }, [user, config.relayMetadata.updatedAt, nostr, updateConfig]); + useEffect(() => { + if (!user) return; + + const syncGraspServersFromNostr = async () => { + try { + const events = await nostr.query( + [{ kinds: [10317], authors: [user.pubkey], limit: 1 }], + { signal: AbortSignal.timeout(5000) } + ); + + if (events.length > 0) { + const event = events[0]; + + // Only update if the event is newer than our stored data + if (event.created_at > config.graspMetadata.updatedAt) { + const fetchedRelays = event.tags + .filter(([name]) => name === 'g') + .map(([_, url]) => ({ url })) + .filter(relay => relay.url); // Filter out empty URLs + + if (fetchedRelays.length > 0) { + console.log('Syncing grasp server list from Nostr:', fetchedRelays); + updateConfig((current) => ({ + ...current, + graspMetadata: { + relays: fetchedRelays, + updatedAt: event.created_at, + }, + })); + } + } + } + } catch (error) { + console.error('Failed to sync grasp servers from Nostr:', error); + } + }; + + syncGraspServersFromNostr(); + }, [user, config.graspMetadata.updatedAt, nostr, updateConfig]); + return null; } diff --git a/src/components/SentryProvider.test.tsx b/src/components/SentryProvider.test.tsx index 9af8c289..a6ae90b0 100644 --- a/src/components/SentryProvider.test.tsx +++ b/src/components/SentryProvider.test.tsx @@ -27,6 +27,10 @@ describe('SentryProvider', () => { relays: [{ url: 'wss://relay.test', read: true, write: true }], updatedAt: 0, }, + graspMetadata: { + relays: [], + updatedAt: 0, + }, templates: [{ name: 'Test', description: 'Test template', url: 'https://test.git' }], esmUrl: 'https://esm.test', corsProxy: 'https://proxy.test/{href}', @@ -34,7 +38,6 @@ describe('SentryProvider', () => { previewDomain: 'test.dev', showcaseEnabled: false, showcaseModerator: '', - ngitServers: [], fsPathProjects: '/projects', fsPathConfig: '/config', fsPathTmp: '/tmp', @@ -64,6 +67,10 @@ describe('SentryProvider', () => { relays: [{ url: 'wss://relay.test', read: true, write: true }], updatedAt: 0, }, + graspMetadata: { + relays: [], + updatedAt: 0, + }, templates: [{ name: 'Test', description: 'Test template', url: 'https://test.git' }], esmUrl: 'https://esm.test', corsProxy: 'https://proxy.test/{href}', @@ -71,7 +78,6 @@ describe('SentryProvider', () => { previewDomain: 'test.dev', showcaseEnabled: false, showcaseModerator: '', - ngitServers: [], fsPathProjects: '/projects', fsPathConfig: '/config', fsPathTmp: '/tmp', @@ -102,6 +108,10 @@ describe('SentryProvider', () => { relays: [{ url: 'wss://relay.test', read: true, write: true }], updatedAt: 0, }, + graspMetadata: { + relays: [], + updatedAt: 0, + }, templates: [{ name: 'Test', description: 'Test template', url: 'https://test.git' }], esmUrl: 'https://esm.test', corsProxy: 'https://proxy.test/{href}', @@ -109,7 +119,6 @@ describe('SentryProvider', () => { previewDomain: 'test.dev', showcaseEnabled: false, showcaseModerator: '', - ngitServers: [], fsPathProjects: '/projects', fsPathConfig: '/config', fsPathTmp: '/tmp', @@ -143,6 +152,10 @@ describe('SentryProvider', () => { relays: [{ url: 'wss://relay.test', read: true, write: true }], updatedAt: 0, }, + graspMetadata: { + relays: [], + updatedAt: 0, + }, templates: [{ name: 'Test', description: 'Test template', url: 'https://test.git' }], esmUrl: 'https://esm.test', corsProxy: 'https://proxy.test/{href}', @@ -150,7 +163,6 @@ describe('SentryProvider', () => { previewDomain: 'test.dev', showcaseEnabled: false, showcaseModerator: '', - ngitServers: [], fsPathProjects: '/projects', fsPathConfig: '/config', fsPathTmp: '/tmp', diff --git a/src/components/git/AnnounceRepositoryDialog.tsx b/src/components/git/AnnounceRepositoryDialog.tsx index 0dfaf8fc..a31641e3 100644 --- a/src/components/git/AnnounceRepositoryDialog.tsx +++ b/src/components/git/AnnounceRepositoryDialog.tsx @@ -151,20 +151,28 @@ export function AnnounceRepositoryDialog({ .join(' '); setName(defaultName); - // Prepopulate clone URLs and relays from ngitServers (matching original handlePushToNostr) - if (user?.pubkey && config.ngitServers && config.ngitServers.length > 0) { - // Clone URLs: https://{server}/{npub}/{repo-id}.git + // Prepopulate clone URLs and relays from grasp servers (matching original handlePushToNostr) + if (user?.pubkey && config.graspMetadata.relays && config.graspMetadata.relays.length > 0) { const npub = nip19.npubEncode(user.pubkey); - const cloneUrls = config.ngitServers.map(server => - `https://${server}/${npub}/${defaultRepoId}.git` - ); + + // Clone URLs: https://{hostname}/{npub}/{repo-id}.git + const cloneUrls = config.graspMetadata.relays.map(relay => { + try { + const url = new URL(relay.url); + return `https://${url.hostname}/${npub}/${defaultRepoId}.git`; + } catch { + // Fallback: extract hostname from URL string + const hostname = relay.url.replace(/^wss?:\/\//, '').replace(/\/.*$/, ''); + return `https://${hostname}/${npub}/${defaultRepoId}.git`; + } + }); setCloneUrls(cloneUrls); - // Relay URLs: wss://{server} - const relayUrls = config.ngitServers.map(server => `wss://${server}`); + // Relay URLs from grasp metadata + const relayUrls = config.graspMetadata.relays.map(r => r.url); setRelays(relayUrls); } else { - // Fallback to write relays if no ngitServers configured + // Fallback to write relays if no grasp servers configured const writeRelays = config.relayMetadata.relays .filter(r => r.write) .map(r => r.url); @@ -193,7 +201,7 @@ export function AnnounceRepositoryDialog({ // Get earliest commit await getEarliestCommit(); - }, [projectId, projectPath, fs, config.relayMetadata, config.ngitServers, user?.pubkey, getEarliestCommit]); + }, [projectId, projectPath, fs, config.relayMetadata, config.graspMetadata.relays, user?.pubkey, getEarliestCommit]); // Load existing repository data if editing, or prepopulate fields for new repos useEffect(() => { diff --git a/src/contexts/AppContext.ts b/src/contexts/AppContext.ts index 68ad6c78..d3ed0972 100644 --- a/src/contexts/AppContext.ts +++ b/src/contexts/AppContext.ts @@ -9,6 +9,13 @@ export interface RelayMetadata { updatedAt: number; } +export interface GraspMetadata { + /** List of grasp server relays */ + relays: { url: string }[]; + /** Unix timestamp of when the grasp list was last updated */ + updatedAt: number; +} + export interface ProjectTemplate { /** Template name */ name: string; @@ -23,6 +30,8 @@ export interface AppConfig { theme: Theme; /** NIP-65 relay list metadata */ relayMetadata: RelayMetadata; + /** NIP-34 grasp server list metadata */ + graspMetadata: GraspMetadata; /** Available project templates */ templates: ProjectTemplate[]; /** ESM CDN URL for package imports */ @@ -39,8 +48,6 @@ export interface AppConfig { showcaseEnabled: boolean; /** Npub of the showcase moderator */ showcaseModerator: string; - /** Nostr Git Servers (hostnames) */ - ngitServers: string[]; /** VFS path for projects directory */ fsPathProjects: string; /** VFS path for config directory */ diff --git a/src/hooks/useGenerateProjectInfo.test.ts b/src/hooks/useGenerateProjectInfo.test.ts index 00b90794..deb5fc2d 100644 --- a/src/hooks/useGenerateProjectInfo.test.ts +++ b/src/hooks/useGenerateProjectInfo.test.ts @@ -67,7 +67,10 @@ describe('useGenerateProjectInfo', () => { previewDomain: 'local-shakespeare.dev', showcaseEnabled: true, showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc', - ngitServers: ['git.shakespeare.diy', 'relay.ngit.dev'], + graspMetadata: { + relays: [{ url: 'wss://git.shakespeare.diy/' }, { url: 'wss://relay.ngit.dev/' }], + updatedAt: 0, + }, fsPathProjects: '/projects', fsPathConfig: '/config', fsPathTmp: '/tmp', @@ -224,7 +227,10 @@ describe('useGenerateProjectInfo', () => { previewDomain: 'local-shakespeare.dev', showcaseEnabled: true, showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc', - ngitServers: ['git.shakespeare.diy', 'relay.ngit.dev'], + graspMetadata: { + relays: [{ url: 'wss://git.shakespeare.diy/' }, { url: 'wss://relay.ngit.dev/' }], + updatedAt: 0, + }, fsPathProjects: '/projects', fsPathConfig: '/config', fsPathTmp: '/tmp', diff --git a/src/hooks/useGit.test.ts b/src/hooks/useGit.test.ts index 03c26442..14b97a09 100644 --- a/src/hooks/useGit.test.ts +++ b/src/hooks/useGit.test.ts @@ -44,7 +44,7 @@ function createWrapper(corsProxy: string) { previewDomain: 'local-test.dev', showcaseEnabled: true, showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc', - ngitServers: ['git.shakespeare.diy', 'relay.ngit.dev'], + graspMetadata: { relays: [{ url: 'wss://git.shakespeare.diy/' }, { url: 'wss://relay.ngit.dev/' }], updatedAt: 0 }, fsPathProjects: '/projects', fsPathConfig: '/config', fsPathTmp: '/tmp', @@ -92,7 +92,7 @@ describe('useGit', () => { fs: mockFS, nostr: mockNostr, corsProxy: 'https://cors.isomorphic-git.org', - ngitServers: ['git.shakespeare.diy', 'relay.ngit.dev'], + graspMetadata: { relays: [{ url: 'wss://git.shakespeare.diy/' }, { url: 'wss://relay.ngit.dev/' }], updatedAt: 0 }, }); expect(result.current).toEqual({ git: expect.any(Object) }); }); @@ -106,7 +106,7 @@ describe('useGit', () => { fs: mockFS, nostr: mockNostr, corsProxy: 'https://custom-cors.example.com', - ngitServers: ['git.shakespeare.diy', 'relay.ngit.dev'], + graspMetadata: { relays: [{ url: 'wss://git.shakespeare.diy/' }, { url: 'wss://relay.ngit.dev/' }], updatedAt: 0 }, }); expect(result.current).toEqual({ git: expect.any(Object) }); }); @@ -120,7 +120,7 @@ describe('useGit', () => { fs: mockFS, nostr: mockNostr, corsProxy: 'https://cors.isomorphic-git.org', - ngitServers: ['git.shakespeare.diy', 'relay.ngit.dev'], + graspMetadata: { relays: [{ url: 'wss://git.shakespeare.diy/' }, { url: 'wss://relay.ngit.dev/' }], updatedAt: 0 }, }); // Rerender with a different wrapper (different CORS proxy) diff --git a/src/hooks/useGit.ts b/src/hooks/useGit.ts index 66116b6e..810f890a 100644 --- a/src/hooks/useGit.ts +++ b/src/hooks/useGit.ts @@ -12,7 +12,20 @@ export function useGit(): { git: Git } { const { fs } = useFS(); const { nostr } = useNostr(); const { config } = useAppContext(); - const { corsProxy, ngitServers } = config; + const { corsProxy, graspMetadata } = config; + + const ngitServers = useMemo(() => { + // Extract hostnames from grasp relay URLs for backwards compatibility with Git class + return graspMetadata.relays.map(r => { + try { + const url = new URL(r.url); + return url.hostname; + } catch { + // Fallback: try to extract hostname from URL string + return r.url.replace(/^wss?:\/\//, '').replace(/\/.*$/, ''); + } + }); + }, [graspMetadata.relays]); const git = useMemo(() => { return new Git({ fs, nostr, corsProxy, ngitServers }); diff --git a/src/lib/SessionManager.test.ts b/src/lib/SessionManager.test.ts index bea3f769..3f9fcd28 100644 --- a/src/lib/SessionManager.test.ts +++ b/src/lib/SessionManager.test.ts @@ -48,7 +48,7 @@ const testConfig: AppConfig = { language: 'en', showcaseEnabled: true, showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc', - ngitServers: ['git.shakespeare.diy', 'relay.ngit.dev'], + graspMetadata: { relays: [{ url: 'wss://git.shakespeare.diy/' }, { url: 'wss://relay.ngit.dev/' }], updatedAt: 0 }, fsPathProjects: '/projects', fsPathConfig: '/config', fsPathTmp: '/tmp', diff --git a/src/lib/system.test.ts b/src/lib/system.test.ts index f52bd79f..276f7b96 100644 --- a/src/lib/system.test.ts +++ b/src/lib/system.test.ts @@ -35,7 +35,7 @@ const testConfig: AppConfig = { language: 'en', showcaseEnabled: true, showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc', - ngitServers: ['git.shakespeare.diy', 'relay.ngit.dev'], + graspMetadata: { relays: [{ url: 'wss://git.shakespeare.diy/' }, { url: 'wss://relay.ngit.dev/' }], updatedAt: 0 }, fsPathProjects: '/projects', fsPathConfig: '/config', fsPathTmp: '/tmp', diff --git a/src/pages/NostrSettings.tsx b/src/pages/NostrSettings.tsx index 3020111c..8950793b 100644 --- a/src/pages/NostrSettings.tsx +++ b/src/pages/NostrSettings.tsx @@ -1,12 +1,11 @@ -import { ArrowLeft, Wifi, Users, UserPlus, LogOut, Trash2, User, Plus, Server, X, Key } from 'lucide-react'; +import { ArrowLeft, Wifi, Users, UserPlus, LogOut, Trash2, User, Plus, Server, Key } from 'lucide-react'; import { useTranslation } from 'react-i18next'; import { Button } from '@/components/ui/button'; -import { Label } from '@/components/ui/label'; -import { Input } from '@/components/ui/input'; import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'; import { Skeleton } from '@/components/ui/skeleton'; import { Separator } from '@/components/ui/separator'; import { RelayListManager } from '@/components/RelayListManager'; +import { GraspListManager } from '@/components/GraspListManager'; import SimpleLoginDialog from '@/components/auth/SimpleLoginDialog'; import SimpleSignupDialog from '@/components/auth/SimpleSignupDialog'; import { useIsMobile } from '@/hooks/useIsMobile'; @@ -14,7 +13,6 @@ import { useNavigate } from 'react-router-dom'; import { useLoggedInAccounts, type Account } from '@/hooks/useLoggedInAccounts'; import { genUserName } from '@/lib/genUserName'; import { useState } from 'react'; -import { useAppContext } from '@/hooks/useAppContext'; import { toast } from '@/hooks/useToast'; import { useNostrLogin } from '@nostrify/react/login'; @@ -29,8 +27,6 @@ export function NostrSettings() { const { authors, currentUser, setLogin, removeLogin, isLoading } = useLoggedInAccounts(); const [showLoginDialog, setShowLoginDialog] = useState(false); const [showSignupDialog, setShowSignupDialog] = useState(false); - const { config, updateConfig } = useAppContext(); - const [newServerHostname, setNewServerHostname] = useState(''); const { logins } = useNostrLogin(); const handleSwitchAccount = (accountId: string) => { @@ -53,30 +49,6 @@ export function NostrSettings() { return account.metadata?.name ?? genUserName(account.pubkey); }; - const handleAddServer = () => { - const hostname = newServerHostname.trim(); - if (!hostname) return; - - // Basic validation - check if it's a valid hostname format - if (!/^[a-zA-Z0-9][a-zA-Z0-9-_.]*[a-zA-Z0-9]$/.test(hostname)) { - return; - } - - updateConfig((current) => ({ - ...current, - ngitServers: [...(current.ngitServers ?? config.ngitServers), hostname], - })); - - setNewServerHostname(''); - }; - - const handleRemoveServer = (hostname: string) => { - updateConfig((current) => ({ - ...current, - ngitServers: (current.ngitServers ?? config.ngitServers).filter(s => s !== hostname), - })); - }; - const getAccountLogin = (accountId: string) => { return logins.find((l) => l.id === accountId); }; @@ -307,61 +279,7 @@ export function NostrSettings() {

{t('nostrGitServers')}

-
- {/* Server List */} -
- {config.ngitServers.map((hostname) => ( -
- - - {hostname} - - -
- ))} -
- - {/* Add Server Form */} -
-
- - setNewServerHostname(e.target.value)} - onKeyDown={(e) => { - if (e.key === 'Enter') { - handleAddServer(); - } - }} - /> -
- -
-
+ diff --git a/src/test/TestApp.tsx b/src/test/TestApp.tsx index 660418e4..e76632eb 100644 --- a/src/test/TestApp.tsx +++ b/src/test/TestApp.tsx @@ -49,7 +49,13 @@ export function TestApp({ children }: TestAppProps) { language: 'en', showcaseEnabled: true, showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc', - ngitServers: ['git.shakespeare.diy', 'relay.ngit.dev'], + graspMetadata: { + relays: [ + { url: 'wss://git.shakespeare.diy/' }, + { url: 'wss://relay.ngit.dev/' }, + ], + updatedAt: 0, + }, fsPathProjects: '/projects', fsPathConfig: '/config', fsPathTmp: '/tmp',