PlaylistsView.tsx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  1. import { useMemo, useState } from 'react'
  2. import Toggle from '../common/Toggle'
  3. import ResizableWidth from '../common/ResizableWidth'
  4. import { Reorderable, useReorder } from '../common/Reorderable'
  5. import { useQueryClient } from '@tanstack/react-query'
  6. import {
  7. ListVideo,
  8. Plus,
  9. Pencil,
  10. Trash2,
  11. Play,
  12. Pause,
  13. Square,
  14. SkipForward,
  15. SkipBack,
  16. Shuffle,
  17. Film,
  18. Heart,
  19. ArrowDownWideNarrow,
  20. CalendarClock
  21. } from 'lucide-react'
  22. import clsx from 'clsx'
  23. import type { PlaylistMode, PlaylistSettings, ScreenTarget } from '@shared/types'
  24. import PlaylistItemRow from './PlaylistItemRow'
  25. import WallpaperPickerModal from './WallpaperPickerModal'
  26. import DetailSidebar from '../common/DetailSidebar'
  27. import WallpaperContextMenu from '../common/WallpaperContextMenu'
  28. import { useAllWallpapers, usePlaybackStates, usePlaylists } from '../../hooks/queries'
  29. import { useFavoriteIds } from '../../hooks/useFavorites'
  30. import { useApplyWallpaper, useSubscribe, useUnsubscribe } from '../../hooks/useWallpaperActions'
  31. import { detailSidebarProps } from '../../utils/wallpaper'
  32. import ScreenSelect from '../common/ScreenSelect'
  33. import { useDisplayTargets } from '../../hooks/useDisplayTargets'
  34. import { screenLabel } from '../../utils/screens'
  35. import { t } from '../../i18n'
  36. import type { MessageKey } from '@shared/i18n'
  37. const MODE_OPTIONS: { value: PlaylistMode; label: MessageKey }[] = [
  38. { value: 'timer', label: 'playlist.modeTimer' },
  39. { value: 'daytime', label: 'playlist.modeDaytime' },
  40. { value: 'dayofweek', label: 'playlist.modeDayOfWeek' },
  41. { value: 'logon', label: 'playlist.modeLogon' }
  42. ]
  43. const MODE_HINTS: Record<Exclude<PlaylistMode, 'timer'>, MessageKey> = {
  44. daytime: 'playlist.modeDaytimeHint',
  45. dayofweek: 'playlist.modeDayOfWeekHint',
  46. logon: 'playlist.modeLogonHint'
  47. }
  48. const SORT_OPTIONS: { value: PlaylistSettings['sortBy']; label: MessageKey }[] = [
  49. { value: 'manual', label: 'playlist.sortManual' },
  50. { value: 'title', label: 'playlist.sortTitle' },
  51. { value: 'createdAt', label: 'playlist.sortAdded' }
  52. ]
  53. interface PlaylistsViewProps {
  54. onBrowseCreator?: (creatorSteamId: string) => void
  55. }
  56. export default function PlaylistsView({ onBrowseCreator }: PlaylistsViewProps) {
  57. const queryClient = useQueryClient()
  58. const [activePlaylistId, setActivePlaylistId] = useState<string | null>(null)
  59. const [creating, setCreating] = useState(false)
  60. const [newTitle, setNewTitle] = useState('')
  61. const [renamingId, setRenamingId] = useState<string | null>(null)
  62. const [renameValue, setRenameValue] = useState('')
  63. const [pickerOpen, setPickerOpen] = useState(false)
  64. const [dragIndex, setDragIndex] = useState<number | null>(null)
  65. const [dragOverIndex, setDragOverIndex] = useState<number | null>(null)
  66. const [error, setError] = useState<string | null>(null)
  67. const [detailId, setDetailId] = useState<string | null>(null)
  68. const [ctxMenu, setCtxMenu] = useState<{ x: number; y: number; wallpaperId: string } | null>(null)
  69. const savedPlaylists = usePlaylists()
  70. const playlistOrder = useReorder('we-playlist-order', savedPlaylists.map((p) => p.id))
  71. const playlists = useMemo(
  72. () => playlistOrder.sortItems(savedPlaylists, (p) => p.id),
  73. // eslint-disable-next-line react-hooks/exhaustive-deps
  74. [savedPlaylists, playlistOrder.order]
  75. )
  76. const wallpapers = useAllWallpapers()
  77. const wallpaperById = useMemo(() => new Map(wallpapers.map((w) => [w.id, w])), [wallpapers])
  78. const playbackStates = usePlaybackStates()
  79. const { targets, perScreen } = useDisplayTargets()
  80. const [screen, setScreen] = useState<ScreenTarget>('*')
  81. const applyWallpaper = useApplyWallpaper()
  82. const subscribe = useSubscribe()
  83. const unsubscribe = useUnsubscribe()
  84. const activePlaylist = playlists.find((p) => p.id === activePlaylistId) ?? null
  85. const mode: PlaylistMode = activePlaylist?.settings.mode ?? 'timer'
  86. const favoriteIds = useFavoriteIds()
  87. const favoriteCount = activePlaylist?.items.filter((i) => favoriteIds.has(i.wallpaperId)).length ?? 0
  88. function invalidatePlaylists() {
  89. void queryClient.invalidateQueries({ queryKey: ['playlists'] })
  90. }
  91. async function handleCreate() {
  92. if (!newTitle.trim()) {
  93. setCreating(false)
  94. return
  95. }
  96. const playlist = await window.electronAPI.playlist.create(newTitle.trim())
  97. setNewTitle('')
  98. setCreating(false)
  99. invalidatePlaylists()
  100. setActivePlaylistId(playlist.id)
  101. }
  102. async function handleRename(id: string) {
  103. if (!renameValue.trim()) {
  104. setRenamingId(null)
  105. return
  106. }
  107. await window.electronAPI.playlist.rename(id, renameValue.trim())
  108. setRenamingId(null)
  109. invalidatePlaylists()
  110. }
  111. async function handleDelete(id: string) {
  112. await window.electronAPI.playlist.delete(id)
  113. if (activePlaylistId === id) setActivePlaylistId(null)
  114. invalidatePlaylists()
  115. void queryClient.invalidateQueries({ queryKey: ['playlist-playback-state'] })
  116. }
  117. async function updateSettings(patch: Partial<PlaylistSettings>) {
  118. if (!activePlaylist) return
  119. await window.electronAPI.playlist.updateSettings(activePlaylist.id, patch)
  120. invalidatePlaylists()
  121. }
  122. async function handleAddWallpapers(wallpaperIds: string[]) {
  123. if (!activePlaylist) return
  124. await window.electronAPI.playlist.addItems(activePlaylist.id, wallpaperIds)
  125. setPickerOpen(false)
  126. invalidatePlaylists()
  127. }
  128. async function handleRemoveItem(wallpaperId: string) {
  129. if (!activePlaylist) return
  130. await window.electronAPI.playlist.removeItems(activePlaylist.id, [wallpaperId])
  131. invalidatePlaylists()
  132. }
  133. async function handleUpdateItem(
  134. wallpaperId: string,
  135. patch: { volume?: number; durationSec?: number; endMinute?: number }
  136. ) {
  137. if (!activePlaylist) return
  138. await window.electronAPI.playlist.updateItem(activePlaylist.id, wallpaperId, patch)
  139. invalidatePlaylists()
  140. }
  141. function openItemCtxMenu(e: React.MouseEvent, wallpaperId: string) {
  142. e.preventDefault()
  143. setCtxMenu({ x: e.clientX, y: e.clientY, wallpaperId })
  144. }
  145. function handleDragStart(index: number) {
  146. setDragIndex(index)
  147. }
  148. function handleDragOver(index: number) {
  149. setDragOverIndex(index)
  150. }
  151. async function handleDrop() {
  152. if (!activePlaylist || dragIndex === null || dragOverIndex === null || dragIndex === dragOverIndex) {
  153. setDragIndex(null)
  154. setDragOverIndex(null)
  155. return
  156. }
  157. const order = activePlaylist.items.map((i) => i.wallpaperId)
  158. const [moved] = order.splice(dragIndex, 1)
  159. order.splice(dragOverIndex, 0, moved)
  160. setDragIndex(null)
  161. setDragOverIndex(null)
  162. await window.electronAPI.playlist.reorderItems(activePlaylist.id, order)
  163. invalidatePlaylists()
  164. }
  165. async function handlePlay() {
  166. if (!activePlaylist) return
  167. setError(null)
  168. try {
  169. await window.electronAPI.playlist.start(activePlaylist.id, screen)
  170. void queryClient.invalidateQueries({ queryKey: ['playlist-playback-state'] })
  171. } catch (err) {
  172. setError((err as Error).message)
  173. }
  174. }
  175. async function handlePlayItem(wallpaperId: string) {
  176. if (!activePlaylist) return
  177. const playingIt = thisStates.filter((s) => s.isPlaying && s.currentItemId === wallpaperId)
  178. if (playingIt.length > 0) {
  179. for (const s of playingIt) await window.electronAPI.playlist.pause(s.screen)
  180. void queryClient.invalidateQueries({ queryKey: ['playlist-playback-state'] })
  181. return
  182. }
  183. setError(null)
  184. try {
  185. await window.electronAPI.playlist.playItem(activePlaylist.id, wallpaperId, isThisPlaylistActive ? undefined : screen)
  186. void queryClient.invalidateQueries({ queryKey: ['playlist-playback-state'] })
  187. } catch (err) {
  188. setError((err as Error).message)
  189. }
  190. }
  191. // controls act on every screen this playlist plays on, narrowed down by the screen picker
  192. async function forEachScreen(action: (screen: ScreenTarget) => Promise<unknown>) {
  193. for (const s of thisStates) await action(s.screen)
  194. void queryClient.invalidateQueries({ queryKey: ['playlist-playback-state'] })
  195. }
  196. const handlePauseResume = () =>
  197. forEachScreen((s) => (isPlaying ? window.electronAPI.playlist.pause(s) : window.electronAPI.playlist.resume(s)))
  198. const handleStop = () => forEachScreen((s) => window.electronAPI.playlist.stop(s))
  199. const handleNext = () => forEachScreen((s) => window.electronAPI.playlist.next(s))
  200. const handlePrevious = () => forEachScreen((s) => window.electronAPI.playlist.previous(s))
  201. const thisStates = playbackStates.filter(
  202. (s) => s.playlistId === activePlaylist?.id && (screen === '*' || s.screen === screen)
  203. )
  204. const isThisPlaylistActive = thisStates.length > 0
  205. const isPlaying = thisStates.some((s) => s.isPlaying)
  206. const currentItemIds = new Set(thisStates.map((s) => s.currentItemId))
  207. const ctxWallpaper = ctxMenu ? wallpaperById.get(ctxMenu.wallpaperId) : undefined
  208. const detailWallpaper = detailId ? wallpaperById.get(detailId) : undefined
  209. const existingIds = useMemo(
  210. () => new Set(activePlaylist?.items.map((i) => i.wallpaperId) ?? []),
  211. [activePlaylist]
  212. )
  213. return (
  214. <div className="flex h-full">
  215. <ResizableWidth storageKey="we-playlist-panel-width" defaultWidth={224} min={160} max={400} edge="right">
  216. <div className="flex w-full flex-col border-r border-fg/5 overflow-y-auto">
  217. <div className="flex items-center justify-between px-3 pt-3 pb-1">
  218. <span className="text-[10px] font-semibold uppercase tracking-wide text-gray-600">
  219. {t('nav.playlists')}
  220. </span>
  221. <button
  222. onClick={() => {
  223. setCreating(true)
  224. setNewTitle('')
  225. }}
  226. title={t('playlist.create')}
  227. className="rounded p-0.5 text-gray-600 hover:text-gray-300"
  228. >
  229. <Plus size={14} />
  230. </button>
  231. </div>
  232. {creating && (
  233. <div className="flex items-center gap-1 px-3 py-1.5">
  234. <ListVideo size={14} className="shrink-0 text-gray-500" />
  235. <input
  236. autoFocus
  237. value={newTitle}
  238. onChange={(e) => { setNewTitle(e.target.value) }}
  239. onBlur={() => void handleCreate()}
  240. onKeyDown={(e) => {
  241. if (e.key === 'Enter') void handleCreate()
  242. if (e.key === 'Escape') setCreating(false)
  243. }}
  244. placeholder={t('playlist.namePlaceholder')}
  245. className="flex-1 bg-transparent text-sm text-gray-200 outline-none placeholder-gray-600"
  246. />
  247. </div>
  248. )}
  249. {playlists.length === 0 && !creating && (
  250. <p className="px-3 py-4 text-xs text-gray-600">
  251. {t('playlist.noneYet')}
  252. </p>
  253. )}
  254. {playlists.map((p) => (
  255. <Reorderable
  256. key={p.id}
  257. group="we-playlist-order"
  258. id={p.id}
  259. onMove={playlistOrder.move}
  260. disabled={renamingId === p.id}
  261. >
  262. <button
  263. onClick={() => { setActivePlaylistId(p.id) }}
  264. className={clsx(
  265. 'group flex items-center gap-2 px-3 py-2 text-sm',
  266. activePlaylistId === p.id
  267. ? 'bg-fg/5 text-fg'
  268. : 'text-gray-400 hover:bg-fg/5 hover:text-gray-200'
  269. )}
  270. >
  271. <ListVideo
  272. size={14}
  273. className={clsx(
  274. 'shrink-0',
  275. playbackStates.some((s) => s.playlistId === p.id) ? 'text-accent-400' : 'text-gray-600'
  276. )}
  277. />
  278. {renamingId === p.id ? (
  279. <input
  280. autoFocus
  281. value={renameValue}
  282. onChange={(e) => { setRenameValue(e.target.value) }}
  283. onBlur={() => void handleRename(p.id)}
  284. onKeyDown={(e) => {
  285. if (e.key === 'Enter') void handleRename(p.id)
  286. if (e.key === 'Escape') setRenamingId(null)
  287. }}
  288. onClick={(e) => { e.stopPropagation() }}
  289. className="flex-1 bg-transparent text-sm text-gray-200 outline-none"
  290. />
  291. ) : (
  292. <span className="flex-1 truncate text-left">{p.title}</span>
  293. )}
  294. <span className="text-xs text-gray-600">{p.items.length}</span>
  295. <span
  296. onClick={(e) => {
  297. e.stopPropagation()
  298. setRenamingId(p.id)
  299. setRenameValue(p.title)
  300. }}
  301. className="hidden rounded p-0.5 text-gray-600 hover:text-gray-300 group-hover:block"
  302. >
  303. <Pencil size={11} />
  304. </span>
  305. <span
  306. onClick={(e) => {
  307. e.stopPropagation()
  308. void handleDelete(p.id)
  309. }}
  310. className="hidden rounded p-0.5 text-gray-600 hover:text-red-400 group-hover:block"
  311. >
  312. <Trash2 size={11} />
  313. </span>
  314. </button>
  315. </Reorderable>
  316. ))}
  317. </div>
  318. </ResizableWidth>
  319. <div className="flex flex-1 overflow-hidden">
  320. <div className="flex flex-1 flex-col overflow-hidden">
  321. {!activePlaylist ? (
  322. <div className="flex h-full items-center justify-center text-gray-600">
  323. <p>{t('playlist.selectOrCreate')}</p>
  324. </div>
  325. ) : (
  326. <>
  327. <div className="border-b border-fg/5 px-4 py-3">
  328. <div className="flex items-center justify-between">
  329. <h2 className="text-lg font-semibold text-gray-100">{activePlaylist.title}</h2>
  330. <div className="flex items-center gap-2">
  331. {perScreen && (
  332. <ScreenSelect targets={targets} value={screen} onChange={setScreen} title={t('playlist.whichScreen')} />
  333. )}
  334. {isThisPlaylistActive ? (
  335. <>
  336. <button
  337. onClick={() => void handlePrevious()}
  338. title={t('playlist.previous')}
  339. className="rounded-lg bg-fg/5 p-2 text-gray-300 hover:bg-fg/10"
  340. >
  341. <SkipBack size={14} />
  342. </button>
  343. <button
  344. onClick={() => void handlePauseResume()}
  345. title={isPlaying ? t('common.pause') : t('common.resume')}
  346. className="rounded-lg bg-accent-600 p-2 text-white hover:bg-accent-500"
  347. >
  348. {isPlaying ? <Pause size={14} /> : <Play size={14} />}
  349. </button>
  350. <button
  351. onClick={() => void handleNext()}
  352. title={t('common.next')}
  353. className="rounded-lg bg-fg/5 p-2 text-gray-300 hover:bg-fg/10"
  354. >
  355. <SkipForward size={14} />
  356. </button>
  357. <button
  358. onClick={() => void handleStop()}
  359. title={t('playlist.stop')}
  360. className="rounded-lg bg-fg/5 p-2 text-gray-300 hover:bg-red-500/20 hover:text-red-400"
  361. >
  362. <Square size={14} />
  363. </button>
  364. </>
  365. ) : (
  366. <button
  367. onClick={() => void handlePlay()}
  368. disabled={activePlaylist.items.length === 0}
  369. className="flex items-center gap-2 rounded-lg bg-accent-600 px-4 py-2 text-sm font-medium text-white hover:bg-accent-500 disabled:opacity-50"
  370. >
  371. <Play size={14} />
  372. {t('playlist.play')}
  373. </button>
  374. )}
  375. </div>
  376. </div>
  377. {error && <p className="mt-2 text-xs text-red-400">{error}</p>}
  378. {perScreen && isThisPlaylistActive && (
  379. <p className="mt-1 text-xs text-gray-500">
  380. {t('playlist.playingOn', { screens: thisStates.map((s) => screenLabel(s.screen)).join(', ') })}
  381. </p>
  382. )}
  383. <div className="mt-3 flex flex-wrap items-center gap-4">
  384. <label className="flex items-center gap-2 text-xs text-gray-400">
  385. <CalendarClock size={12} />
  386. {t('playlist.mode')}
  387. <select
  388. value={mode}
  389. onChange={(e) => void updateSettings({ mode: e.target.value as PlaylistMode })}
  390. className="rounded bg-fg/5 px-2 py-1 text-gray-200 outline-none focus:ring-1 focus:ring-accent-500"
  391. >
  392. {MODE_OPTIONS.map((o) => (
  393. <option key={o.value} value={o.value}>
  394. {t(o.label)}
  395. </option>
  396. ))}
  397. </select>
  398. </label>
  399. {mode !== 'timer' && (
  400. <p className="basis-full text-xs text-gray-600">{t(MODE_HINTS[mode])}</p>
  401. )}
  402. {mode === 'timer' && (
  403. <>
  404. <label className="flex items-center gap-2 text-xs text-gray-400">
  405. <Toggle on={activePlaylist.settings.randomize} onClick={() => void updateSettings({ randomize: !activePlaylist.settings.randomize })} />
  406. <Shuffle size={12} />
  407. {t('playlist.randomize')}
  408. </label>
  409. {!activePlaylist.settings.randomize && (
  410. <label className="flex items-center gap-2 text-xs text-gray-400">
  411. <ArrowDownWideNarrow size={12} />
  412. {t('playlist.sortBy')}
  413. <select
  414. value={activePlaylist.settings.sortBy}
  415. onChange={(e) =>
  416. void updateSettings({ sortBy: e.target.value as PlaylistSettings['sortBy'] })
  417. }
  418. className="rounded bg-fg/5 px-2 py-1 text-gray-200 outline-none focus:ring-1 focus:ring-accent-500"
  419. >
  420. {SORT_OPTIONS.map((o) => (
  421. <option key={o.value} value={o.value}>
  422. {t(o.label)}
  423. </option>
  424. ))}
  425. </select>
  426. </label>
  427. )}
  428. <label className="flex items-center gap-2 text-xs text-gray-400">
  429. {t('playlist.duration')}
  430. <input
  431. type="number"
  432. min={1}
  433. value={activePlaylist.settings.defaultDurationSec}
  434. onChange={(e) =>
  435. void updateSettings({ defaultDurationSec: Math.max(1, Number(e.target.value)) })
  436. }
  437. className="w-20 rounded bg-fg/5 px-2 py-1 text-gray-200 outline-none focus:ring-1 focus:ring-accent-500"
  438. />
  439. {t('playlist.seconds')}
  440. </label>
  441. <label
  442. className="flex items-center gap-2 text-xs text-gray-400"
  443. title={t('playlist.finishVideosHint')}
  444. >
  445. <Toggle on={!!activePlaylist.settings.finishVideos} onClick={() => void updateSettings({ finishVideos: !activePlaylist.settings.finishVideos })} />
  446. <Film size={12} />
  447. {t('playlist.finishVideos')}
  448. </label>
  449. </>
  450. )}
  451. <label
  452. className="flex items-center gap-2 text-xs text-gray-400"
  453. title={t('playlist.favoritesOnlyHint')}
  454. >
  455. <Toggle on={!!activePlaylist.settings.favoritesOnly} onClick={() => void updateSettings({ favoritesOnly: !activePlaylist.settings.favoritesOnly })} />
  456. <Heart size={12} />
  457. {t('playlist.favoritesOnly')}
  458. {activePlaylist.settings.favoritesOnly && (
  459. <span className={favoriteCount === 0 ? 'text-amber-400' : 'text-gray-600'}>
  460. {favoriteCount === 0
  461. ? t('playlist.favoritesOnlyNone')
  462. : t('playlist.favoritesOnlyCount', { favorites: favoriteCount, total: activePlaylist.items.length })}
  463. </span>
  464. )}
  465. </label>
  466. <label className="flex items-center gap-2 text-xs text-gray-400">
  467. {t('playlist.defaultVolume')}
  468. <input
  469. type="range"
  470. min={0}
  471. max={100}
  472. value={activePlaylist.settings.defaultVolume}
  473. onChange={(e) => void updateSettings({ defaultVolume: Number(e.target.value) })}
  474. className="w-24 accent-accent-500"
  475. />
  476. <span className="w-8 text-gray-300">{activePlaylist.settings.defaultVolume}</span>
  477. </label>
  478. </div>
  479. </div>
  480. <div className="flex items-center justify-between px-4 pt-3">
  481. <span className="text-xs text-gray-600">
  482. {t('playlist.count', { count: activePlaylist.items.length })}
  483. </span>
  484. <button
  485. onClick={() => { setPickerOpen(true) }}
  486. className="flex items-center gap-2 rounded-lg bg-fg/5 px-3 py-1.5 text-xs text-gray-300 hover:bg-fg/10"
  487. >
  488. <Plus size={12} />
  489. {t('playlist.addWallpapers')}
  490. </button>
  491. </div>
  492. <div className="flex-1 overflow-y-auto p-4 space-y-2">
  493. {activePlaylist.items.length === 0 && (
  494. <div className="flex h-32 items-center justify-center text-sm text-gray-600">
  495. {t('playlist.empty')}
  496. </div>
  497. )}
  498. {activePlaylist.items.map((item, index, items) => (
  499. <PlaylistItemRow
  500. key={item.wallpaperId}
  501. item={item}
  502. earlierEnd={items.slice(0, index).reduce((end, other) => Math.max(end, other.endMinute ?? 0), 0)}
  503. isLast={index === items.length - 1}
  504. wallpaper={wallpaperById.get(item.wallpaperId)}
  505. index={index}
  506. isPlaying={isPlaying}
  507. isCurrent={currentItemIds.has(item.wallpaperId)}
  508. onDragStart={handleDragStart}
  509. onDragOver={handleDragOver}
  510. onDrop={() => void handleDrop()}
  511. onPlay={() => void handlePlayItem(item.wallpaperId)}
  512. onRemove={() => void handleRemoveItem(item.wallpaperId)}
  513. onUpdate={(patch) => void handleUpdateItem(item.wallpaperId, patch)}
  514. onContextMenu={(e) => { openItemCtxMenu(e, item.wallpaperId) }}
  515. onOpenDetail={() => { setDetailId(item.wallpaperId) }}
  516. defaultDurationSec={activePlaylist.settings.defaultDurationSec}
  517. mode={mode}
  518. defaultVolume={activePlaylist.settings.defaultVolume}
  519. />
  520. ))}
  521. </div>
  522. </>
  523. )}
  524. </div>
  525. {detailWallpaper && (
  526. <DetailSidebar
  527. id={detailWallpaper.id}
  528. {...detailSidebarProps(detailWallpaper)}
  529. onClose={() => { setDetailId(null) }}
  530. onSubscribe={() => void subscribe(detailWallpaper.id)}
  531. onUnsubscribe={() => unsubscribe([detailWallpaper.id])}
  532. onPlay={(target) => applyWallpaper(detailWallpaper.id, target)}
  533. onBrowseCreator={onBrowseCreator}
  534. />
  535. )}
  536. </div>
  537. {pickerOpen && activePlaylist && (
  538. <WallpaperPickerModal
  539. excludeIds={existingIds}
  540. onAdd={(wallpaperIds) => void handleAddWallpapers(wallpaperIds)}
  541. onClose={() => { setPickerOpen(false) }}
  542. />
  543. )}
  544. {ctxMenu && (
  545. <WallpaperContextMenu
  546. x={ctxMenu.x}
  547. y={ctxMenu.y}
  548. ids={[ctxMenu.wallpaperId]}
  549. wallpapers={ctxWallpaper ? [ctxWallpaper] : []}
  550. onClose={() => { setCtxMenu(null) }}
  551. onBrowseCreator={onBrowseCreator}
  552. />
  553. )}
  554. </div>
  555. )
  556. }