Kaleido-Desktop/src/screens/HubScreen.tsx
Elijah 00d72e70f4 Create Kaleido Desktop, a cinematic Plex client for Windows
Tauri 2 shell with a React/TypeScript interface and libmpv playback composed
beneath the web view (DirectComposition on Windows). Shared code with per-OS
platform modules and configs so macOS and Linux can follow.

- Plex sign-in (browser, plex.tv/link or manual), server selection, Plex Home
- Home, Movies and TV Shows (Discover, Library, Collections), search, people
- Title pages with logos, ratings, cast, extras, seasons and episodes
- Direct play with Plex conversion fallback, tracks, markers, autoplay
- Metadata editing, artwork, fix match, refresh, analyze and deletion
- Resumable offline downloads
- App settings and Plex server administration with a live dashboard
- Signed updater feed and Forgejo CI

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 16:26:37 -07:00

43 lines
1.9 KiB
TypeScript

import { useInfiniteQuery } from '@tanstack/react-query';
import { useEffect, useRef } from 'react';
import * as api from '../plex/api';
import { useServer } from '../app/session';
import { LandscapeCard, PosterCard } from '../ui/media';
import { EmptyState, ErrorState, PageLoader, Spinner } from '../ui/primitives';
/** "View all" for a hub, paged as it scrolls. */
export default function HubScreen({ hubKey, title }: { hubKey: string; title: string }) {
const server = useServer();
const q = useInfiniteQuery({
queryKey: [server.machineId, 'hubAll', hubKey],
queryFn: ({ pageParam }) => api.hubItems(server, hubKey, pageParam, 72),
initialPageParam: 0,
getNextPageParam: (last, pages) => {
const loaded = pages.reduce((a, p) => a + p.items.length, 0);
return last.items.length && loaded < last.total ? loaded : undefined;
},
});
const sentinel = useRef<HTMLDivElement>(null);
useEffect(() => {
const el = sentinel.current;
if (!el) return;
const io = new IntersectionObserver(([e]) => e.isIntersecting && q.hasNextPage && !q.isFetchingNextPage && q.fetchNextPage(), { rootMargin: '800px' });
io.observe(el);
return () => io.disconnect();
}, [q.hasNextPage, q.isFetchingNextPage]);
const items = q.data?.pages.flatMap((p) => p.items) ?? [];
const wide = items.length > 0 && items.every((i) => i.type === 'episode');
return (
<div className="page-pad top hub-page">
<h1 className="page-title">{title}</h1>
{q.isError && <ErrorState error={q.error} onRetry={() => q.refetch()} />}
{q.isLoading && <PageLoader />}
{q.data && !items.length && <EmptyState title="Nothing here yet" />}
<div className={`poster-grid auto${wide ? ' wide' : ''}`}>{items.map((i) => (wide ? <LandscapeCard key={i.id} item={i} /> : <PosterCard key={i.id} item={i} />))}</div>
<div ref={sentinel} className="grid-sentinel">
{q.isFetchingNextPage && <Spinner />}
</div>
</div>
);
}