feature: add custom droplist

This commit is contained in:
WonderAliceUwU committed 2026-08-02 10:36:03 +02:00
1 parent 103bdbb2cd
commit 9e7f64d06a
2 files changed
+136 -21

No files matched your search

+75 -13
View File
@@ -1323,6 +1323,7 @@ function TitleDetailsModal(props: {
const [pendingEpisodeRequestIds, setPendingEpisodeRequestIds] = useState<string[]>([])
const [pendingSeasonRequestIds, setPendingSeasonRequestIds] = useState<string[]>([])
const [seasonActionBusy, setSeasonActionBusy] = useState<'download' | 'delete' | null>(null)
const [seasonMenuOpen, setSeasonMenuOpen] = useState(false)
const [movieRequestPending, setMovieRequestPending] = useState(false)
const [playerTarget, setPlayerTarget] = useState<{ id: string; title: string } | null>(null)
const [isOverviewExpanded, setIsOverviewExpanded] = useState(false)
@@ -1334,10 +1335,13 @@ function TitleDetailsModal(props: {
const closeTimeoutRef = useRef<number | null>(null)
const modalRef = useRef<HTMLDivElement | null>(null)
const episodeListRef = useRef<HTMLDivElement | null>(null)
const seasonMenuRef = useRef<HTMLDivElement | null>(null)
const seasonMenuOptionsRef = useRef<HTMLDivElement | null>(null)
const pendingSeasonScrollRef = useRef<string | null>(null)
const initialEpisodeFocusKeyRef = useRef('')
const hasUserScrolledEpisodeListRef = useRef(false)
const initialEpisodeListScrollLeftRef = useRef(0)
const seasonValue = activeSeasonId ?? details?.selectedSeasonId ?? ''
useLayoutEffect(() => {
if (!props.originRect || !modalRef.current) {
@@ -1389,6 +1393,7 @@ function TitleDetailsModal(props: {
setPendingEpisodeRequestIds([])
setPendingSeasonRequestIds([])
setSeasonActionBusy(null)
setSeasonMenuOpen(false)
setMovieRequestPending(false)
setPlayerTarget(null)
setIsOverviewExpanded(false)
@@ -1398,6 +1403,48 @@ function TitleDetailsModal(props: {
initialEpisodeListScrollLeftRef.current = 0
}, [props.card.id])
useEffect(() => {
if (!seasonMenuOpen) {
return
}
function closeSeasonMenuOnOutsidePress(event: PointerEvent) {
if (!seasonMenuRef.current?.contains(event.target as Node)) {
setSeasonMenuOpen(false)
}
}
function closeSeasonMenuOnEscape(event: KeyboardEvent) {
if (event.key === 'Escape') {
setSeasonMenuOpen(false)
}
}
window.addEventListener('pointerdown', closeSeasonMenuOnOutsidePress)
window.addEventListener('keydown', closeSeasonMenuOnEscape)
return () => {
window.removeEventListener('pointerdown', closeSeasonMenuOnOutsidePress)
window.removeEventListener('keydown', closeSeasonMenuOnEscape)
}
}, [seasonMenuOpen])
useEffect(() => {
if (!seasonMenuOpen || !seasonMenuOptionsRef.current) {
return
}
const selectedOption = seasonMenuOptionsRef.current.querySelector<HTMLElement>('[aria-selected="true"]')
if (!selectedOption) {
return
}
seasonMenuOptionsRef.current.scrollTop = Math.max(
0,
selectedOption.offsetTop - (seasonMenuOptionsRef.current.clientHeight - selectedOption.offsetHeight) / 2
)
}, [seasonMenuOpen, seasonValue])
function updateEpisodeInCaches(episodeId: string, updater: (episode: NonNullable<TitleDetailsResponse['episodes']>[number]) => NonNullable<TitleDetailsResponse['episodes']>[number]) {
setDetails((current) => current && current.episodes.some((episode) => episode.id === episodeId)
? {
@@ -1440,8 +1487,6 @@ function TitleDetailsModal(props: {
}
}, [props.card])
const seasonValue = activeSeasonId ?? details?.selectedSeasonId ?? ''
useEffect(() => {
const list = episodeListRef.current
const targetSeasonId = pendingSeasonScrollRef.current
@@ -1804,6 +1849,7 @@ function TitleDetailsModal(props: {
function handleSeasonSelectChange(nextSeasonId: string) {
pendingSeasonScrollRef.current = nextSeasonId || null
setActiveSeasonId(nextSeasonId || undefined)
setSeasonMenuOpen(false)
}
function handleEpisodeWatchToggle(
@@ -2104,20 +2150,36 @@ function TitleDetailsModal(props: {
type="button"
/>
{details.seasons.length ? (
<label className="title-season-selector">
<div className="title-season-selector" ref={seasonMenuRef}>
<span className="title-season-kicker">Season</span>
<select
<button
aria-controls="title-season-options"
aria-expanded={seasonMenuOpen}
aria-haspopup="listbox"
className="title-season-select"
onChange={(event) => handleSeasonSelectChange(event.target.value)}
value={seasonValue}
onClick={() => setSeasonMenuOpen((open) => !open)}
type="button"
>
{details.seasons.map((season) => (
<option key={season.id} value={season.id}>
{season.title}
</option>
))}
</select>
</label>
<span>{details.seasons.find((season) => season.id === seasonValue)?.title || 'Select season'}</span>
<span aria-hidden="true" className="title-season-select-chevron" />
</button>
{seasonMenuOpen ? (
<div aria-label="Seasons" className="title-season-options" id="title-season-options" ref={seasonMenuOptionsRef} role="listbox">
{details.seasons.map((season) => (
<button
aria-selected={season.id === seasonValue}
className={season.id === seasonValue ? 'is-selected' : ''}
key={season.id}
onClick={() => handleSeasonSelectChange(season.id)}
role="option"
type="button"
>
{season.title}
</button>
))}
</div>
) : null}
</div>
) : null}
<div className="title-season-divider" aria-hidden="true" />
<div className="title-season-badge">
+61 -8
View File
@@ -1904,7 +1904,7 @@ img {
display: grid;
gap: 0.16rem;
min-width: 0;
padding: 0 1.7rem 0 0.15rem;
padding: 0 0.15rem;
color: #eef3ff;
}
@@ -1917,15 +1917,20 @@ img {
}
.title-season-select {
display: inline-flex;
align-items: center;
justify-content: space-between;
gap: 0.8rem;
min-height: 2.1rem;
padding: 0;
border: 0;
background: transparent;
color: #f5f8ff;
font-family: inherit;
font-size: 1.05rem;
font-weight: 600;
letter-spacing: -0.01em;
appearance: none;
text-align: left;
cursor: pointer;
outline: none;
transition: color 180ms ease, transform 180ms ease;
@@ -1937,17 +1942,65 @@ img {
transform: translateX(0.04rem);
}
.title-season-selector::after {
content: "";
position: absolute;
top: calc(50% + 0.28rem);
right: 0.45rem;
.title-season-select-chevron {
width: 0.52rem;
height: 0.52rem;
border-right: 1.5px solid rgba(255, 255, 255, 0.6);
border-bottom: 1.5px solid rgba(255, 255, 255, 0.6);
transform: translateY(-50%) rotate(45deg);
transform: translateY(-0.16rem) rotate(45deg);
pointer-events: none;
transition: transform 180ms ease;
}
.title-season-select[aria-expanded="true"] .title-season-select-chevron {
transform: translateY(0.14rem) rotate(225deg);
}
.title-season-options {
position: absolute;
z-index: 8;
top: calc(100% + 0.55rem);
left: 0;
display: grid;
width: max-content;
min-width: min(17rem, calc(100vw - 3rem));
max-width: min(24rem, calc(100vw - 3rem));
max-height: min(18rem, 50vh);
overflow-y: auto;
gap: 0.38rem;
padding: 0.55rem;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 0.8rem;
background: rgba(18, 22, 31, 0.98);
box-shadow: 0 1rem 2.5rem rgba(0, 0, 0, 0.32);
}
.title-season-options button {
width: 100%;
padding: 0.68rem 0.75rem;
border: 0;
border-radius: 0.55rem;
background: transparent;
color: #b7c1d6;
font: inherit;
font-size: 0.9rem;
font-weight: 600;
line-height: 1.25;
text-align: left;
cursor: pointer;
transition: background 150ms ease, color 150ms ease;
}
.title-season-options button:hover,
.title-season-options button:focus-visible {
background: rgba(255, 255, 255, 0.1);
color: #ffffff;
outline: none;
}
.title-season-options button.is-selected {
background: rgba(255, 255, 255, 0.14);
color: #ffffff;
}
.title-season-divider {