diff --git a/js/desktop/src/App.tsx b/js/desktop/src/App.tsx index 8a84a3b..2858f50 100644 --- a/js/desktop/src/App.tsx +++ b/js/desktop/src/App.tsx @@ -11,6 +11,7 @@ import NetworkSelector from '@/features/network-selector'; import NetworkRoot from '@/features/network-root'; import ParticleViewResolver from '@/features/particles/particle-view-resolver'; import Layout from '@/features/layout'; +import { logError } from '@/lib/errors'; import NetworkSettingsPage from '@/features/network-settings'; import { Toaster } from '@/components/ui/sonner'; import { PusherProvider } from '@/lib/pusher-provider'; diff --git a/js/desktop/src/hooks/use-stream-particles.ts b/js/desktop/src/hooks/use-stream-particles.ts index 41bcae1..7be9ff6 100644 --- a/js/desktop/src/hooks/use-stream-particles.ts +++ b/js/desktop/src/hooks/use-stream-particles.ts @@ -10,8 +10,8 @@ export type StreamParticle = Particle & { properties: StreamProperties; }; -const CLOSED_INITIAL_PAGE_SIZE = 50; -const CLOSED_PAGE_INCREMENT = 50; +const INITIAL_PAGE_SIZE = 12; +const PAGE_INCREMENT = 12; // Stable where-constraint references so the Firestore subscription only // re-attaches when the tab actually changes, not on every render. @@ -28,11 +28,7 @@ function useVisibilityScopes(userId?: string, networkId?: string) { } interface UseStreamParticlesOptions { - /** - * Which streams to subscribe to. Open streams are loaded in full (bounded - * by active work — full realtime coverage is needed for autoplay/huddles). - * Closed streams are paginated via `loadMore`. - */ + // Which streams to subscribe to status: 'open' | 'closed'; } @@ -40,9 +36,9 @@ interface UseStreamParticlesResult { streams: StreamParticle[]; isLoading: boolean; networkId: string; - /** True when more closed streams may exist beyond the current window. */ + /** True when more streams may exist beyond the current window. */ canLoadMore: boolean; - /** Extend the pagination window. No-op on the open tab. */ + /** Extend the pagination window. */ loadMore: () => void; } @@ -54,21 +50,10 @@ export function useStreamParticles( const user = useAuthStore((s) => s.user); const visibilityScopes = useVisibilityScopes(user?.id, networkId); - const [closedLimit, setClosedLimit] = useState(CLOSED_INITIAL_PAGE_SIZE); - const [prevStatus, setPrevStatus] = useState(status); - - // Switching back to the closed tab starts a fresh window, avoiding an - // ever-growing subscription across a long session. - if (status !== prevStatus) { - setPrevStatus(status); - if (status === 'closed') { - setClosedLimit(CLOSED_INITIAL_PAGE_SIZE); - } - } + const [limit, setLimit] = useState(INITIAL_PAGE_SIZE); const whereFilter: QueryFieldFilterConstraint = status === 'open' ? OPEN_STATUS_FILTER : CLOSED_STATUS_FILTER; - const limit = status === 'closed' ? closedLimit : undefined; const { children, isLoading } = useLiveParticleChildren(path, { orderByField: 'last_child_created_at', @@ -85,12 +70,11 @@ export function useStreamParticles( // Heuristic: if we got back as many items as we asked for, assume there // might be more. Clicking load-more when there are no more is a no-op. - const canLoadMore = status === 'closed' && streams.length >= closedLimit; + const canLoadMore = streams.length >= limit; const loadMore = useCallback(() => { - if (status !== 'closed') return; - setClosedLimit((prev) => prev + CLOSED_PAGE_INCREMENT); - }, [status]); + setLimit((prev) => prev + PAGE_INCREMENT); + }, []); return { streams, isLoading, networkId, canLoadMore, loadMore }; }