mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-04 04:26:38 +08:00
67b85840dc
* Add favourite buttons to library list and series detail pages Co-authored-by: truewhile <truewhile@users.noreply.github.com> * Fix favourites list for remote Emby mounted media Co-authored-by: truewhile <truewhile@users.noreply.github.com> * Route favourites to library series detail when appropriate Co-authored-by: truewhile <truewhile@users.noreply.github.com> * Fix favourites link to library series for remote anime paths Co-authored-by: truewhile <truewhile@users.noreply.github.com> * Fix remote Emby playback history and continue watching - Preserve duration_ms when web player reports duration=0 - Add GET /playback/:id/resume for reliable per-item resume - Switch home continue watching to /watch-history/continue API - Set library_id on remote media for play-profile visibility - Keep continue-watching rows when remote metadata hydration fails Co-authored-by: truewhile <truewhile@users.noreply.github.com> * Fix mobile sort dropdown overflowing off-screen Align dropdown to button left edge on small screens and cap width to viewport so sort options stay fully visible on mobile. Co-authored-by: truewhile <truewhile@users.noreply.github.com> * Remove stale Windows binary backup files Co-authored-by: truewhile <truewhile@users.noreply.github.com> * Fix STRM account edit form not echoing saved config Return config_preview from account API for server/url/username and secret flags. Merge partial config updates so empty password/token fields do not wipe stored credentials. Co-authored-by: truewhile <truewhile@users.noreply.github.com> * perf(strm): speed up OpenList metadata downloads with provider-aware concurrency - Split download semaphore: 115 stays capped at 3 for WAF safety; OpenList/CloudDrive2 WebDAV metadata uses strm.download_threads (default raised to 6, max 16) - Scope 115 WAF cooldown to 115 tasks only so OpenList downloads are not paused - Requeue claimed tasks back to pending when slot acquisition fails or 115 is cooling - Add tests for separate semaphores and requeue behavior Co-authored-by: truewhile <truewhile@users.noreply.github.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: truewhile <truewhile@users.noreply.github.com>
178 lines
4.9 KiB
TypeScript
178 lines
4.9 KiB
TypeScript
import { useEffect, useMemo, useState } from 'react'
|
|
|
|
import { libraryAPI, type LibraryWithPreview } from '../api/library'
|
|
import { historyAPI } from '../api/history'
|
|
import type { HistoryItem } from '../api/playback'
|
|
import type { Library, Media } from '../types'
|
|
import type { SeriesCard } from '../utils/groupSeries'
|
|
import {
|
|
ContinueWatchingSection,
|
|
HomeCarouselSection,
|
|
HomeEmptyState,
|
|
HomeLibrariesSection,
|
|
HomeLibraryRowSection,
|
|
HomeLoadingState,
|
|
} from './HomePageSections'
|
|
|
|
const hasArtwork = (media?: Media | null) => !!(media?.poster_url || media?.backdrop_url)
|
|
const asArray = <T,>(value: unknown): T[] => (Array.isArray(value) ? (value as T[]) : [])
|
|
|
|
export function HomePage() {
|
|
const [libraries, setLibraries] = useState<Library[]>([])
|
|
const [libraryData, setLibraryData] = useState<Record<string, { cards: SeriesCard[]; items: Media[]; total: number }>>({})
|
|
const [history, setHistory] = useState<HistoryItem[]>([])
|
|
const [loading, setLoading] = useState(true)
|
|
|
|
useEffect(() => {
|
|
let cancelled = false
|
|
|
|
async function load() {
|
|
setLoading(true)
|
|
try {
|
|
const [libs, hist] = await Promise.all([
|
|
libraryAPI
|
|
.list({ withPreview: true, previewLimit: 20 })
|
|
.then((rows) => asArray<LibraryWithPreview>(rows))
|
|
.catch(() => [] as LibraryWithPreview[]),
|
|
historyAPI
|
|
.continueWatching(12)
|
|
.then((rows) =>
|
|
rows.map(
|
|
(row): HistoryItem => ({
|
|
...row.history,
|
|
created_at: '',
|
|
updated_at: '',
|
|
media: row.media,
|
|
}),
|
|
),
|
|
)
|
|
.catch(() => [] as HistoryItem[]),
|
|
])
|
|
|
|
if (cancelled) return
|
|
setLibraries(libs)
|
|
setHistory(hist.filter((h) => h && !h.completed))
|
|
|
|
const mapData: Record<string, { cards: SeriesCard[]; items: Media[]; total: number }> = {}
|
|
for (const lib of libs) {
|
|
mapData[lib.id] = {
|
|
cards: lib.cards ?? [],
|
|
items: [],
|
|
total: lib.total ?? 0,
|
|
}
|
|
}
|
|
setLibraryData(mapData)
|
|
} finally {
|
|
if (!cancelled) setLoading(false)
|
|
}
|
|
}
|
|
|
|
load()
|
|
return () => {
|
|
cancelled = true
|
|
}
|
|
}, [])
|
|
|
|
// Quick lookup map for libraries
|
|
const libraryMap = useMemo(() => {
|
|
const map = new Map<string, Library>()
|
|
for (const lib of libraries) {
|
|
map.set(lib.id, lib)
|
|
}
|
|
return map
|
|
}, [libraries])
|
|
|
|
// Counts lookup
|
|
const libraryCounts = useMemo(() => {
|
|
const counts: Record<string, number> = {}
|
|
for (const lib of libraries) {
|
|
counts[lib.id] = libraryData[lib.id]?.total ?? 0
|
|
}
|
|
return counts
|
|
}, [libraries, libraryData])
|
|
|
|
// Compute items to show in the Hero Carousel. Only libraries flagged
|
|
// carousel_enabled contribute; a library's items array is empty for
|
|
// series-type libs (loaded via /series), so gate on cards instead.
|
|
const carouselItems = useMemo(() => {
|
|
const candidateMedia: Media[] = []
|
|
const effectiveSelectedIds = libraries
|
|
.filter((l) => l.carousel_enabled === true)
|
|
.map((l) => l.id)
|
|
|
|
for (const libId of effectiveSelectedIds) {
|
|
const data = libraryData[libId]
|
|
if (data && data.cards.length > 0) {
|
|
for (const card of data.cards) {
|
|
if (hasArtwork(card.rep)) {
|
|
candidateMedia.push(card.rep)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Fallback to all loaded items with artwork
|
|
if (candidateMedia.length === 0) {
|
|
for (const lib of libraries) {
|
|
const data = libraryData[lib.id]
|
|
if (data) {
|
|
for (const card of data.cards) {
|
|
candidateMedia.push(card.rep)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return candidateMedia.slice(0, 10)
|
|
}, [libraries, libraryData])
|
|
|
|
const empty =
|
|
!loading &&
|
|
libraries.length === 0 &&
|
|
history.length === 0
|
|
|
|
if (loading) {
|
|
return <HomeLoadingState />
|
|
}
|
|
|
|
if (empty) {
|
|
return <HomeEmptyState />
|
|
}
|
|
|
|
return (
|
|
<div className="space-y-12 pb-16">
|
|
{/* 1. 顶部海报轮播区 */}
|
|
{carouselItems.length > 0 && (
|
|
<HomeCarouselSection items={carouselItems} libraryMap={libraryMap} />
|
|
)}
|
|
|
|
{/* 2. 继续观看(若有历史) */}
|
|
{history.length > 0 && <ContinueWatchingSection history={history} />}
|
|
|
|
{/* 3. 媒体库卡片区 */}
|
|
{libraries.length > 0 && (
|
|
<HomeLibrariesSection
|
|
libraries={libraries}
|
|
libraryData={libraryData}
|
|
libraryCounts={libraryCounts}
|
|
/>
|
|
)}
|
|
|
|
{/* 4. 各媒体库内容展示行 */}
|
|
<div className="space-y-10">
|
|
{libraries.map((lib) => {
|
|
const cards = libraryData[lib.id]?.cards || []
|
|
if (cards.length === 0) return null
|
|
return (
|
|
<HomeLibraryRowSection
|
|
key={lib.id}
|
|
library={lib}
|
|
cards={cards}
|
|
/>
|
|
)
|
|
})}
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|