From 91fe30a86048cfbe1c7a1babf3e30f8e6e6705c9 Mon Sep 17 00:00:00 2001 From: Nicolas Cantu Date: Tue, 6 Jan 2026 21:52:38 +0100 Subject: [PATCH] lint fix wip --- components/RelayManager.tsx | 14 +++-- components/ReviewForm.tsx | 7 ++- lib/platformSync.ts | 108 +++++++++++++++++++++++------------- 3 files changed, 85 insertions(+), 44 deletions(-) diff --git a/components/RelayManager.tsx b/components/RelayManager.tsx index 6cf7231..94d6930 100644 --- a/components/RelayManager.tsx +++ b/components/RelayManager.tsx @@ -291,11 +291,15 @@ export function RelayManager({ onConfigChange }: RelayManagerProps): React.React handleDrop(e, relay.id) }} className={`bg-cyber-dark border rounded p-4 space-y-3 transition-all ${ - draggedId === relay.id - ? 'opacity-50 border-neon-cyan' - : dragOverId === relay.id - ? 'border-neon-green shadow-lg' - : 'border-neon-cyan/30' + (() => { + if (draggedId === relay.id) { + return 'opacity-50 border-neon-cyan' + } + if (dragOverId === relay.id) { + return 'border-neon-green shadow-lg' + } + return 'border-neon-cyan/30' + })() }`} >
diff --git a/components/ReviewForm.tsx b/components/ReviewForm.tsx index 6f0eaa9..4bcf3d4 100644 --- a/components/ReviewForm.tsx +++ b/components/ReviewForm.tsx @@ -41,7 +41,12 @@ export function ReviewForm({ article, onSuccess, onCancel }: ReviewFormProps): R return } - const category = article.category === 'author-presentation' ? 'science-fiction' : (article.category ?? 'science-fiction') + const category = (() => { + if (article.category === 'author-presentation') { + return 'science-fiction' + } + return article.category ?? 'science-fiction' + })() const seriesId = article.seriesId ?? '' await publishReview({ diff --git a/lib/platformSync.ts b/lib/platformSync.ts index ad8f5df..5b5e5cb 100644 --- a/lib/platformSync.ts +++ b/lib/platformSync.ts @@ -7,7 +7,6 @@ import type { Event } from 'nostr-tools' import type { SimplePoolWithSub } from '@/types/nostr-tools-extended' import { nostrService } from './nostr' -import { getPrimaryRelaySync } from './config' import { PLATFORM_SERVICE, MIN_EVENT_DATE } from './platformConfig' import { buildTagFilter, extractTagsFromEvent } from './nostrTagSystem' import { objectCache } from './objectCache' @@ -24,6 +23,7 @@ class PlatformSyncService { /** * Start background sync * Scans all notes with service='zapwall.fr' and caches them + * Does not require pubkey - syncs all public notes with service='zapwall.fr' */ async startSync(): Promise { if (this.syncInProgress) { @@ -38,12 +38,25 @@ class PlatformSyncService { this.syncInProgress = true + // Update progress manager to show sync indicator + const { syncProgressManager } = await import('./syncProgressManager') + const { relaySessionManager } = await import('./relaySessionManager') + const activeRelays = await relaySessionManager.getActiveRelays() + const initialRelay = activeRelays[0] ?? 'Connecting...' + syncProgressManager.setProgress({ currentStep: 0, totalSteps: 1, completed: false, currentRelay: initialRelay }) + try { await this.performSync(pool as unknown as SimplePoolWithSub) + syncProgressManager.setProgress({ currentStep: 1, totalSteps: 1, completed: true, currentRelay: initialRelay }) } catch (error) { console.error('Error in platform sync:', error) + syncProgressManager.setProgress(null) } finally { this.syncInProgress = false + // Clear progress after a short delay + setTimeout(() => { + syncProgressManager.setProgress(null) + }, 500) } } @@ -62,52 +75,71 @@ class PlatformSyncService { }, ] - return new Promise((resolve) => { - const relayUrl = getPrimaryRelaySync() - const { createSubscription } = require('@/types/nostr-tools-extended') - const sub = createSubscription(pool, [relayUrl], filters) + // Use relay rotation for platform sync + const { tryWithRelayRotation } = await import('./relayRotation') + const { syncProgressManager } = await import('./syncProgressManager') - const events: Event[] = [] - let resolved = false - - const finalize = async (): Promise => { - if (resolved) { - return + return tryWithRelayRotation( + pool as unknown as import('nostr-tools').SimplePool, + async (relayUrl, poolWithSub) => { + // Update progress with current relay + const currentProgress = syncProgressManager.getProgress() + if (currentProgress) { + syncProgressManager.setProgress({ + ...currentProgress, + currentRelay: relayUrl, + }) } - resolved = true - sub.unsub() - this.syncSubscription = null - // Process all events and cache them - await this.processAndCacheEvents(events) + const { createSubscription } = require('@/types/nostr-tools-extended') + const sub = createSubscription(poolWithSub, [relayUrl], filters) - this.lastSyncTime = Date.now() - resolve() - } + const events: Event[] = [] + let resolved = false - sub.on('event', (event: Event): void => { - // Only process events with service='zapwall.fr' - const tags = extractTagsFromEvent(event) - if (tags.service === PLATFORM_SERVICE) { - events.push(event) + const finalize = async (): Promise => { + if (resolved) { + return + } + resolved = true + sub.unsub() + this.syncSubscription = null + + // Process all events and cache them + await this.processAndCacheEvents(events) + + this.lastSyncTime = Date.now() } - }) - sub.on('eose', (): void => { - void (async (): Promise => { - await finalize() - })() - }) + return new Promise((resolve) => { + sub.on('event', (event: Event): void => { + // Only process events with service='zapwall.fr' + const tags = extractTagsFromEvent(event) + if (tags.service === PLATFORM_SERVICE) { + events.push(event) + } + }) - // Timeout after SYNC_TIMEOUT_MS - setTimeout((): void => { - void (async (): Promise => { - await finalize() - })() - }, this.SYNC_TIMEOUT_MS).unref?.() + sub.on('eose', (): void => { + void (async (): Promise => { + await finalize() + resolve() + })() + }) - this.syncSubscription = sub - }) + // Timeout after SYNC_TIMEOUT_MS + setTimeout((): void => { + void (async (): Promise => { + await finalize() + resolve() + })() + }, this.SYNC_TIMEOUT_MS).unref?.() + + this.syncSubscription = sub + }) + }, + 30000 // 30 second timeout per relay + ) } /**