From e97d2b32cc12a8395a4cff0e354ffa14eb059747 Mon Sep 17 00:00:00 2001 From: Nicolas Cantu Date: Tue, 6 Jan 2026 21:44:43 +0100 Subject: [PATCH] lint fix wip --- components/AuthorFilterButton.tsx | 2 +- components/AuthorFilterDropdown.tsx | 2 +- components/AuthorPresentationEditor.tsx | 16 ++++++---- components/CreateAccountModalComponents.tsx | 2 +- components/GlobalSyncProgressBar.tsx | 22 ++++++++++--- components/HomeView.tsx | 22 +++++++------ components/KeyManagementManager.tsx | 2 +- components/UnlockAccountModal.tsx | 2 +- lib/purchaseQueries.ts | 4 ++- lib/reviewTipQueries.ts | 8 +++-- lib/sponsoringQueries.ts | 4 ++- lib/userContentSync.ts | 34 ++++++++++++++++----- pages/_app.tsx | 28 +++++++++-------- 13 files changed, 99 insertions(+), 49 deletions(-) diff --git a/components/AuthorFilterButton.tsx b/components/AuthorFilterButton.tsx index 3828073..8526300 100644 --- a/components/AuthorFilterButton.tsx +++ b/components/AuthorFilterButton.tsx @@ -5,7 +5,7 @@ export function AuthorMnemonicIcons({ value, getMnemonicIcons }: { value: string return (
{getMnemonicIcons(value).map((icon, idx) => ( - + {icon} ))} diff --git a/components/AuthorFilterDropdown.tsx b/components/AuthorFilterDropdown.tsx index 29e8074..6943249 100644 --- a/components/AuthorFilterDropdown.tsx +++ b/components/AuthorFilterDropdown.tsx @@ -47,7 +47,7 @@ export function AuthorOption({ {displayName}
{mnemonicIcons.map((icon, idx) => ( - + {icon} ))} diff --git a/components/AuthorPresentationEditor.tsx b/components/AuthorPresentationEditor.tsx index 588af21..3251244 100644 --- a/components/AuthorPresentationEditor.tsx +++ b/components/AuthorPresentationEditor.tsx @@ -224,11 +224,15 @@ function PresentationForm({ disabled={loading ?? deleting} className="w-full px-4 py-2 bg-neon-cyan/20 hover:bg-neon-cyan/30 text-neon-cyan rounded-lg font-medium transition-all border border-neon-cyan/50 hover:shadow-glow-cyan disabled:opacity-50 disabled:cursor-not-allowed" > - {loading ?? deleting - ? t('publish.publishing') - : hasExistingPresentation === true - ? t('presentation.update.button') - : t('publish.button')} + {(() => { + if (loading ?? deleting) { + return t('publish.publishing') + } + if (hasExistingPresentation === true) { + return t('presentation.update.button') + } + return t('publish.button') + })()}
{hasExistingPresentation && ( @@ -279,7 +283,7 @@ function useAuthorPresentationState(pubkey: string | null, existingAuthorName?: if (existingAuthorName && existingAuthorName !== draft.authorName && !existingPresentation) { setDraft((prev) => ({ ...prev, authorName: existingAuthorName })) } - }, [existingAuthorName, existingPresentation]) + }, [existingAuthorName, existingPresentation, draft.authorName]) const handleSubmit = useCallback( async (e: FormEvent) => { diff --git a/components/CreateAccountModalComponents.tsx b/components/CreateAccountModalComponents.tsx index 81eb2b6..978c18b 100644 --- a/components/CreateAccountModalComponents.tsx +++ b/components/CreateAccountModalComponents.tsx @@ -25,7 +25,7 @@ export function RecoveryPhraseDisplay({
{recoveryPhrase.map((word, index) => (
{index + 1}. diff --git a/components/GlobalSyncProgressBar.tsx b/components/GlobalSyncProgressBar.tsx index 78763a3..7b22480 100644 --- a/components/GlobalSyncProgressBar.tsx +++ b/components/GlobalSyncProgressBar.tsx @@ -53,21 +53,35 @@ export function SyncStatus(): React.ReactElement | null { setProgress(newProgress) }) + // Check current progress immediately + const currentProgress = syncProgressManager.getProgress() + if (currentProgress) { + setProgress(currentProgress) + } + return () => { unsubscribe() } }, []) - if (!progress || progress.completed) { + // Show indicator if we have progress and it's not completed + if (!progress) { return null } + // Always show indicator during sync, even if completed is false (means sync is in progress) + if (progress.completed) { + return null + } + + const relayName = progress.currentRelay ? getRelayDisplayName(progress.currentRelay) : null + return ( -
+
- {progress.currentRelay ? ( + {relayName ? ( - {getRelayDisplayName(progress.currentRelay)} + {relayName} ) : ( diff --git a/components/HomeView.tsx b/components/HomeView.tsx index 82b3f07..34eab8e 100644 --- a/components/HomeView.tsx +++ b/components/HomeView.tsx @@ -102,15 +102,19 @@ function HomeContent({ )} - {isInitialLoad ? ( -
-

{t('common.loading')}

-
- ) : shouldShowAuthors ? ( - - ) : ( - - )} + {(() => { + if (isInitialLoad) { + return ( +
+

{t('common.loading')}

+
+ ) + } + if (shouldShowAuthors) { + return + } + return + })()}
) } diff --git a/components/KeyManagementManager.tsx b/components/KeyManagementManager.tsx index 2c7c99a..e2ad606 100644 --- a/components/KeyManagementManager.tsx +++ b/components/KeyManagementManager.tsx @@ -382,7 +382,7 @@ export function KeyManagementManager(): React.ReactElement {
{recoveryPhrase.map((word, index) => (
{index + 1}. diff --git a/components/UnlockAccountModal.tsx b/components/UnlockAccountModal.tsx index 9597464..a7998e4 100644 --- a/components/UnlockAccountModal.tsx +++ b/components/UnlockAccountModal.tsx @@ -129,7 +129,7 @@ function WordInputs({
{words.map((word, index) => ( onWordChange(index, value)} diff --git a/lib/purchaseQueries.ts b/lib/purchaseQueries.ts index 131845b..3dd4f86 100644 --- a/lib/purchaseQueries.ts +++ b/lib/purchaseQueries.ts @@ -193,6 +193,8 @@ export function getPurchasesByPayer(payerPubkey: string, timeoutMs: number = 500 sub.on('eose', (): void => { void done() }) - setTimeout(() => done(), timeoutMs).unref?.() + setTimeout((): void => { + void done() + }, timeoutMs).unref?.() }) } diff --git a/lib/reviewTipQueries.ts b/lib/reviewTipQueries.ts index 0e1d32f..5868bdb 100644 --- a/lib/reviewTipQueries.ts +++ b/lib/reviewTipQueries.ts @@ -154,7 +154,9 @@ export function getReviewTipsForArticle(articleId: string, timeoutMs: number = 5 sub.on('eose', (): void => { void done() }) - setTimeout(() => done(), timeoutMs).unref?.() + setTimeout((): void => { + void done() + }, timeoutMs).unref?.() }) } @@ -198,6 +200,8 @@ export function getReviewTipsForReview(reviewId: string, timeoutMs: number = 500 sub.on('eose', (): void => { void done() }) - setTimeout(() => done(), timeoutMs).unref?.() + setTimeout((): void => { + void done() + }, timeoutMs).unref?.() }) } diff --git a/lib/sponsoringQueries.ts b/lib/sponsoringQueries.ts index fed9874..c11c137 100644 --- a/lib/sponsoringQueries.ts +++ b/lib/sponsoringQueries.ts @@ -154,6 +154,8 @@ export function getSponsoringByAuthor(authorPubkey: string, timeoutMs: number = sub.on('eose', (): void => { void done() }) - setTimeout(() => done(), timeoutMs).unref?.() + setTimeout((): void => { + void done() + }, timeoutMs).unref?.() }) } diff --git a/lib/userContentSync.ts b/lib/userContentSync.ts index bccb4c8..15dac0b 100644 --- a/lib/userContentSync.ts +++ b/lib/userContentSync.ts @@ -13,7 +13,7 @@ import { getLatestVersion } from './versionManager' import { buildTagFilter } from './nostrTagSystemFilter' import { getPrimaryRelaySync } from './config' import { tryWithRelayRotation } from './relayRotation' -import { PLATFORM_SERVICE, MIN_EVENT_DATE } from './platformConfig' +import { PLATFORM_SERVICE } from './platformConfig' import { parseObjectId } from './urlGenerator' import type { SimplePoolWithSub } from '@/types/nostr-tools-extended' @@ -24,6 +24,9 @@ async function fetchAndCachePublications( pool: SimplePoolWithSub, authorPubkey: string ): Promise { + const { getLastSyncDate } = await import('./syncStorage') + const lastSyncDate = await getLastSyncDate() + const filters = [ { ...buildTagFilter({ @@ -31,7 +34,7 @@ async function fetchAndCachePublications( authorPubkey, service: PLATFORM_SERVICE, }), - since: MIN_EVENT_DATE, + since: lastSyncDate, limit: 1000, // Get all publications }, ] @@ -148,6 +151,9 @@ async function fetchAndCacheSeries( pool: SimplePoolWithSub, authorPubkey: string ): Promise { + const { getLastSyncDate } = await import('./syncStorage') + const lastSyncDate = await getLastSyncDate() + // Fetch all events for series to cache them properly const filters = [ { @@ -156,7 +162,7 @@ async function fetchAndCacheSeries( authorPubkey, service: PLATFORM_SERVICE, }), - since: MIN_EVENT_DATE, + since: lastSyncDate, limit: 1000, // Get all series events }, ] @@ -278,12 +284,15 @@ async function fetchAndCachePurchases( pool: SimplePoolWithSub, payerPubkey: string ): Promise { + const { getLastSyncDate } = await import('./syncStorage') + const lastSyncDate = await getLastSyncDate() + const filters = [ { kinds: [9735], // Zap receipt authors: [payerPubkey], '#kind_type': ['purchase'], - since: MIN_EVENT_DATE, + since: lastSyncDate, limit: 1000, }, ] @@ -376,12 +385,15 @@ async function fetchAndCacheSponsoring( pool: SimplePoolWithSub, authorPubkey: string ): Promise { + const { getLastSyncDate } = await import('./syncStorage') + const lastSyncDate = await getLastSyncDate() + const filters = [ { kinds: [9735], // Zap receipt '#p': [authorPubkey], '#kind_type': ['sponsoring'], - since: MIN_EVENT_DATE, + since: lastSyncDate, limit: 1000, }, ] @@ -474,12 +486,15 @@ async function fetchAndCacheReviewTips( pool: SimplePoolWithSub, authorPubkey: string ): Promise { + const { getLastSyncDate } = await import('./syncStorage') + const lastSyncDate = await getLastSyncDate() + const filters = [ { kinds: [9735], // Zap receipt '#p': [authorPubkey], '#kind_type': ['review_tip'], - since: MIN_EVENT_DATE, + since: lastSyncDate, limit: 1000, }, ] @@ -579,6 +594,9 @@ async function fetchAndCachePaymentNotes( pool: SimplePoolWithSub, userPubkey: string ): Promise { + const { getLastSyncDate } = await import('./syncStorage') + const lastSyncDate = await getLastSyncDate() + // Payment notes are kind 1 with type='payment' // They can be: as payer (authors) or as recipient (#recipient tag) const filters = [ @@ -587,7 +605,7 @@ async function fetchAndCachePaymentNotes( authors: [userPubkey], '#payment': [''], '#service': [PLATFORM_SERVICE], - since: MIN_EVENT_DATE, + since: lastSyncDate, limit: 1000, }, { @@ -595,7 +613,7 @@ async function fetchAndCachePaymentNotes( '#recipient': [userPubkey], '#payment': [''], '#service': [PLATFORM_SERVICE], - since: MIN_EVENT_DATE, + since: lastSyncDate, limit: 1000, }, ] diff --git a/pages/_app.tsx b/pages/_app.tsx index 8175324..d68a5aa 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -5,7 +5,6 @@ import React from 'react' import { platformSyncService } from '@/lib/platformSync' import { nostrAuthService } from '@/lib/nostrAuth' import { syncUserContentToCache } from '@/lib/userContentSync' -import { getLastSyncDate, getCurrentTimestamp } from '@/lib/syncStorage' import { syncProgressManager } from '@/lib/syncProgressManager' import { relaySessionManager } from '@/lib/relaySessionManager' @@ -74,27 +73,20 @@ export default function App({ Component, pageProps }: AppProps): React.ReactElem } }, []) - // Start user content sync on app mount if connected + // Start user content sync on app mount and on each page navigation if connected React.useEffect(() => { let syncInProgress = false const startUserSync = async (): Promise => { if (syncInProgress) { + console.log('[App] Sync already in progress, skipping') return } const state = nostrAuthService.getState() + console.log('[App] Checking connection state:', { connected: state.connected, hasPubkey: Boolean(state.pubkey) }) if (!state.connected || !state.pubkey) { - return - } - - // Check if already recently synced (within last hour) - const storedLastSyncDate = await getLastSyncDate() - const currentTimestamp = getCurrentTimestamp() - const isRecentlySynced = storedLastSyncDate >= currentTimestamp - 3600 - - if (isRecentlySynced) { - console.log('[App] User content already synced recently, skipping') + console.log('[App] Not connected or no pubkey, skipping sync') return } @@ -121,7 +113,16 @@ export default function App({ Component, pageProps }: AppProps): React.ReactElem // Try to start sync immediately void startUserSync() - // Also listen to connection changes to sync when user connects + // Also listen to connection changes and route changes to sync when user connects or navigates + const router = require('next/router').default + const handleRouteChange = (): void => { + if (!syncInProgress) { + void startUserSync() + } + } + + router.events?.on('routeChangeComplete', handleRouteChange) + const unsubscribe = nostrAuthService.subscribe((state) => { if (state.connected && state.pubkey && !syncInProgress) { void startUserSync() @@ -129,6 +130,7 @@ export default function App({ Component, pageProps }: AppProps): React.ReactElem }) return () => { + router.events?.off('routeChangeComplete', handleRouteChange) unsubscribe() } }, [])