Merge pull request #974 from Stremio/feat/details-scroll-to-last-watched-video
Some checks are pending
Build / build (push) Waiting to run

Details: Scroll to last watched video
This commit is contained in:
Timothy Z. 2025-10-27 16:49:23 +02:00 committed by GitHub
commit 000d5be639
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 27 additions and 30 deletions

View file

@ -12,11 +12,12 @@ const useProfile = require('stremio/common/useProfile');
const VideoPlaceholder = require('./VideoPlaceholder'); const VideoPlaceholder = require('./VideoPlaceholder');
const styles = require('./styles'); const styles = require('./styles');
const Video = React.forwardRef(({ className, id, title, thumbnail, season, episode, released, upcoming, watched, progress, scheduled, seasonWatched, deepLinks, onMarkVideoAsWatched, onMarkSeasonAsWatched, ...props }, ref) => { const Video = ({ className, id, title, thumbnail, season, episode, released, upcoming, watched, progress, scheduled, seasonWatched, selected, deepLinks, onMarkVideoAsWatched, onMarkSeasonAsWatched, ...props }) => {
const routeFocused = useRouteFocused(); const routeFocused = useRouteFocused();
const profile = useProfile(); const profile = useProfile();
const { t } = useTranslation(); const { t } = useTranslation();
const [menuOpen, , closeMenu, toggleMenu] = useBinaryState(false); const [menuOpen, , closeMenu, toggleMenu] = useBinaryState(false);
const popupLabelOnMouseUp = React.useCallback((event) => { const popupLabelOnMouseUp = React.useCallback((event) => {
if (!event.nativeEvent.togglePopupPrevented) { if (!event.nativeEvent.togglePopupPrevented) {
if (event.nativeEvent.ctrlKey || event.nativeEvent.button === 2) { if (event.nativeEvent.ctrlKey || event.nativeEvent.button === 2) {
@ -68,27 +69,19 @@ const Video = React.forwardRef(({ className, id, title, thumbnail, season, episo
} }
} }
}, [deepLinks]); }, [deepLinks]);
const renderLabel = React.useMemo(() => function renderLabel({ className, id, title, thumbnail, episode, released, upcoming, watched, progress, scheduled, children, ref: popupRef, ...props }) { const renderLabel = React.useMemo(() => function renderLabel({ className, id, title, thumbnail, episode, released, upcoming, watched, progress, scheduled, children, ref, ...props }) {
const blurThumbnail = profile.settings.hideSpoilers && season && episode && !watched; const blurThumbnail = profile.settings.hideSpoilers && season && episode && !watched;
const handleRef = React.useCallback((node) => {
if (popupRef) { React.useEffect(() => {
if (typeof popupRef === 'function') { selected && !watched && ref.current?.scrollIntoView({
popupRef(node); behavior: 'smooth',
} else { block: 'nearest',
popupRef.current = node; inline: 'start'
} });
} }, [selected]);
if (ref) {
if (typeof ref === 'function') {
ref(node);
} else {
ref.current = node;
}
}
}, [popupRef]);
return ( return (
<Button {...props} className={classnames(className, styles['video-container'])} title={title} ref={handleRef}> <Button {...props} ref={ref} className={classnames(className, styles['video-container'])} title={title}>
{ {
typeof thumbnail === 'string' && thumbnail.length > 0 ? typeof thumbnail === 'string' && thumbnail.length > 0 ?
<div className={styles['thumbnail-container']}> <div className={styles['thumbnail-container']}>
@ -159,7 +152,7 @@ const Video = React.forwardRef(({ className, id, title, thumbnail, season, episo
{children} {children}
</Button> </Button>
); );
}, []); }, [selected]);
const renderMenu = React.useMemo(() => function renderMenu() { const renderMenu = React.useMemo(() => function renderMenu() {
return ( return (
<div className={styles['context-menu-content']} onPointerDown={popupMenuOnPointerDown} onContextMenu={popupMenuOnContextMenu} onClick={popupMenuOnClick} onKeyDown={popupMenuOnKeyDown}> <div className={styles['context-menu-content']} onPointerDown={popupMenuOnPointerDown} onContextMenu={popupMenuOnContextMenu} onClick={popupMenuOnClick} onKeyDown={popupMenuOnKeyDown}>
@ -203,7 +196,7 @@ const Video = React.forwardRef(({ className, id, title, thumbnail, season, episo
renderMenu={renderMenu} renderMenu={renderMenu}
/> />
); );
}); };
Video.Placeholder = VideoPlaceholder; Video.Placeholder = VideoPlaceholder;
@ -220,6 +213,7 @@ Video.propTypes = {
progress: PropTypes.number, progress: PropTypes.number,
scheduled: PropTypes.bool, scheduled: PropTypes.bool,
seasonWatched: PropTypes.bool, seasonWatched: PropTypes.bool,
selected: PropTypes.bool,
deepLinks: PropTypes.shape({ deepLinks: PropTypes.shape({
metaDetailsStreams: PropTypes.string, metaDetailsStreams: PropTypes.string,
player: PropTypes.string player: PropTypes.string

View file

@ -190,6 +190,7 @@ const MetaDetails = ({ urlParams, queryParams }) => {
metaItem={metaDetails.metaItem} metaItem={metaDetails.metaItem}
libraryItem={metaDetails.libraryItem} libraryItem={metaDetails.libraryItem}
season={season} season={season}
selectedVideoId={metaDetails.libraryItem?.state?.video_id}
seasonOnSelect={seasonOnSelect} seasonOnSelect={seasonOnSelect}
toggleNotifications={toggleNotifications} toggleNotifications={toggleNotifications}
/> />

View file

@ -11,9 +11,10 @@ const SeasonsBar = require('./SeasonsBar');
const { default: EpisodePicker } = require('../EpisodePicker'); const { default: EpisodePicker } = require('../EpisodePicker');
const styles = require('./styles'); const styles = require('./styles');
const VideosList = ({ className, metaItem, libraryItem, season, seasonOnSelect, toggleNotifications }) => { const VideosList = ({ className, metaItem, libraryItem, season, seasonOnSelect, selectedVideoId, toggleNotifications }) => {
const { core } = useServices(); const { core } = useServices();
const profile = useProfile(); const profile = useProfile();
const showNotificationsToggle = React.useMemo(() => { const showNotificationsToggle = React.useMemo(() => {
return metaItem?.content?.content?.inLibrary && metaItem?.content?.content?.videos?.length; return metaItem?.content?.content?.inLibrary && metaItem?.content?.content?.videos?.length;
}, [metaItem]); }, [metaItem]);
@ -178,6 +179,7 @@ const VideosList = ({ className, metaItem, libraryItem, season, seasonOnSelect,
deepLinks={video.deepLinks} deepLinks={video.deepLinks}
scheduled={video.scheduled} scheduled={video.scheduled}
seasonWatched={seasonWatched} seasonWatched={seasonWatched}
selected={video.id === selectedVideoId}
onMarkVideoAsWatched={onMarkVideoAsWatched} onMarkVideoAsWatched={onMarkVideoAsWatched}
onMarkSeasonAsWatched={onMarkSeasonAsWatched} onMarkSeasonAsWatched={onMarkSeasonAsWatched}
/> />
@ -195,6 +197,7 @@ VideosList.propTypes = {
metaItem: PropTypes.object, metaItem: PropTypes.object,
libraryItem: PropTypes.object, libraryItem: PropTypes.object,
season: PropTypes.number, season: PropTypes.number,
selectedVideoId: PropTypes.string,
seasonOnSelect: PropTypes.func, seasonOnSelect: PropTypes.func,
toggleNotifications: PropTypes.func, toggleNotifications: PropTypes.func,
}; };

View file

@ -1,6 +1,6 @@
// Copyright (C) 2017-2024 Smart code 203358507 // Copyright (C) 2017-2024 Smart code 203358507
import React, { useMemo, useCallback, useState, forwardRef, memo, useRef } from 'react'; import React, { useMemo, useCallback, useState, forwardRef, memo } from 'react';
import classNames from 'classnames'; import classNames from 'classnames';
import Icon from '@stremio/stremio-icons/react'; import Icon from '@stremio/stremio-icons/react';
import { useServices } from 'stremio/services'; import { useServices } from 'stremio/services';
@ -21,7 +21,8 @@ type Props = {
const SideDrawer = memo(forwardRef<HTMLDivElement, Props>(({ seriesInfo, className, closeSideDrawer, selected, ...props }: Props, ref) => { const SideDrawer = memo(forwardRef<HTMLDivElement, Props>(({ seriesInfo, className, closeSideDrawer, selected, ...props }: Props, ref) => {
const { core } = useServices(); const { core } = useServices();
const [season, setSeason] = useState<number>(seriesInfo?.season); const [season, setSeason] = useState<number>(seriesInfo?.season);
const selectedVideoRef = useRef<HTMLDivElement>(null); const [selectedVideoId, setSelectedVideoId] = useState<string | null>(null);
const metaItem = useMemo(() => { const metaItem = useMemo(() => {
return seriesInfo ? return seriesInfo ?
{ {
@ -78,11 +79,9 @@ const SideDrawer = memo(forwardRef<HTMLDivElement, Props>(({ seriesInfo, classNa
event.stopPropagation(); event.stopPropagation();
}; };
const onTransitionEnd = () => { const onTransitionEnd = useCallback(() => {
selectedVideoRef.current?.scrollIntoView({ setSelectedVideoId(selected);
behavior: 'smooth', }, [selected]);
});
};
return ( return (
<div ref={ref} className={classNames(styles['side-drawer'], className)} onMouseDown={onMouseDown} onTransitionEnd={onTransitionEnd}> <div ref={ref} className={classNames(styles['side-drawer'], className)} onMouseDown={onMouseDown} onTransitionEnd={onTransitionEnd}>
@ -114,7 +113,6 @@ const SideDrawer = memo(forwardRef<HTMLDivElement, Props>(({ seriesInfo, classNa
{videos.map((video, index) => ( {videos.map((video, index) => (
<Video <Video
key={index} key={index}
ref={video.id === selected ? selectedVideoRef : null}
className={styles['video']} className={styles['video']}
id={video.id} id={video.id}
title={video.title} title={video.title}
@ -128,6 +126,7 @@ const SideDrawer = memo(forwardRef<HTMLDivElement, Props>(({ seriesInfo, classNa
progress={video.progress} progress={video.progress}
deepLinks={video.deepLinks} deepLinks={video.deepLinks}
scheduled={video.scheduled} scheduled={video.scheduled}
selected={video.id === selectedVideoId}
onMarkVideoAsWatched={onMarkVideoAsWatched} onMarkVideoAsWatched={onMarkVideoAsWatched}
onMarkSeasonAsWatched={onMarkSeasonAsWatched} onMarkSeasonAsWatched={onMarkSeasonAsWatched}
/> />