Kaleido-Desktop/src/screens/dialogs/Lists.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

101 lines
3.9 KiB
TypeScript

import { useState } from 'react';
import * as api from '../../plex/api';
import type { Item } from '../../plex/types';
import { useServer } from '../../app/session';
import { invalidateLibrary, useServerQuery } from '../../app/queries';
import { Dialog, toast, toastError } from '../../ui/overlays';
import { Button, PageLoader } from '../../ui/primitives';
import { Icon } from '../../ui/Icon';
export function CollectionDialog({ item, onClose }: { item: Item; onClose: () => void }) {
const server = useServer();
const collections = useServerQuery(['collections', item.librarySectionId], (s) => api.collections(s, item.librarySectionId), { enabled: !!item.librarySectionId });
const [name, setName] = useState('');
const [busy, setBusy] = useState(false);
const current = new Set(item.collections.map((c) => c.tag));
const add = async (title: string) => {
setBusy(true);
try {
await api.addToCollection(server, item, title);
toast(`Added to “${title}”`, 'success');
invalidateLibrary();
onClose();
} catch (e) {
toastError(e);
} finally {
setBusy(false);
}
};
return (
<Dialog title="Add to collection" subtitle={item.title} onClose={onClose} width={480}>
<form
className="inline-create"
onSubmit={(e) => {
e.preventDefault();
if (name.trim()) add(name.trim());
}}
>
<input className="text-input" value={name} onChange={(e) => setName(e.target.value)} placeholder="New collection name" />
<Button variant="ghost" icon="plus" type="submit" disabled={!name.trim() || busy}>
Create
</Button>
</form>
{collections.isLoading && <PageLoader />}
<div className="list-pick">
{collections.data?.map((c) => (
<button key={c.id} className="list-pick-row" disabled={busy || current.has(c.title)} onClick={() => add(c.title)}>
<Icon name="collection" size={17} />
<span>{c.title}</span>
{current.has(c.title) && <Icon name="check" size={15} className="dim" />}
</button>
))}
</div>
</Dialog>
);
}
export function PlaylistDialog({ item, onClose }: { item: Item; onClose: () => void }) {
const server = useServer();
const playlists = useServerQuery(['playlists'], (s) => api.playlists(s));
const [name, setName] = useState('');
const [busy, setBusy] = useState(false);
const run = async (fn: () => Promise<unknown>, done: string) => {
setBusy(true);
try {
await fn();
toast(done, 'success');
onClose();
} catch (e) {
toastError(e);
} finally {
setBusy(false);
}
};
return (
<Dialog title="Add to playlist" subtitle={item.title} onClose={onClose} width={480}>
<form
className="inline-create"
onSubmit={(e) => {
e.preventDefault();
if (name.trim()) run(() => api.createPlaylist(server, name.trim(), server.machineId, item.id), `Created “${name.trim()}”`);
}}
>
<input className="text-input" value={name} onChange={(e) => setName(e.target.value)} placeholder="New playlist name" />
<Button variant="ghost" icon="plus" type="submit" disabled={!name.trim() || busy}>
Create
</Button>
</form>
{playlists.isLoading && <PageLoader />}
<div className="list-pick">
{playlists.data?.map((p) => (
<button key={p.id} className="list-pick-row" disabled={busy} onClick={() => run(() => api.addToPlaylist(server, p.id, server.machineId, item.id), `Added to “${p.title}”`)}>
<Icon name="queue" size={17} />
<span>{p.title}</span>
<small className="dim">{p.leafCount ? `${p.leafCount} items` : ''}</small>
</button>
))}
{playlists.data && !playlists.data.length && <p className="muted">No video playlists yet. Create one above.</p>}
</div>
</Dialog>
);
}