diff --git a/src/routes/Settings/Settings.js b/src/routes/Settings/Settings.js index a50df5ba6..1051c5156 100644 --- a/src/routes/Settings/Settings.js +++ b/src/routes/Settings/Settings.js @@ -1,5 +1,6 @@ const React = require('react'); const classnames = require('classnames'); +const throttle = require('lodash.throttle'); const Icon = require('stremio-icons/dom'); const { useServices } = require('stremio/services'); const { Button, Checkbox, NavBar, Multiselect, ColorInput, useProfile, useStreamingServer } = require('stremio/common'); @@ -31,12 +32,6 @@ const Settings = () => { cacheSizeSelect, torrentProfileSelect } = useStreamingServerSettingsInputs(); - const [section, setSection] = React.useState(GENERAL_SECTION); - const sectionsContainerRef = React.useRef(null); - const sectionsContainerOnScorll = React.useCallback((event) => { - }, []); - const sideMenuButtonOnClick = React.useCallback((event) => { - }, []); const logoutButtonOnClick = React.useCallback(() => { core.dispatch({ action: 'Ctx', @@ -65,6 +60,43 @@ const Settings = () => { } }); }, []); + const sectionsContainerRef = React.useRef(null); + const generalSectionRef = React.useRef(null); + const playerSectionRef = React.useRef(null); + const streamingServerSectionRef = React.useRef(null); + const sections = React.useMemo(() => ([ + { ref: generalSectionRef, id: GENERAL_SECTION }, + { ref: playerSectionRef, id: PLAYER_SECTION }, + { ref: streamingServerSectionRef, id: STREAMING_SECTION }, + ]), []); + const [selectedSectionId, setSelectedSectionId] = React.useState(sections[0].id); + const updateSelectedSectionId = React.useCallback(() => { + if (sectionsContainerRef.current.scrollTop + sectionsContainerRef.current.clientHeight === sectionsContainerRef.current.scrollHeight) { + setSelectedSectionId(sections[sections.length - 1].id); + } else { + for (let i = sections.length - 1; i >= 0; i--) { + if (sections[i].ref.current.offsetTop - sectionsContainerRef.current.offsetTop <= sectionsContainerRef.current.scrollTop) { + setSelectedSectionId(sections[i].id); + break; + } + } + } + }, []); + const sideMenuButtonOnClick = React.useCallback((event) => { + const section = sections.find((section) => { + return section.id === event.currentTarget.dataset.section; + }); + sectionsContainerRef.current.scrollTo({ + top: section.ref.current.offsetTop - sectionsContainerRef.current.offsetTop, + behavior: 'smooth' + }); + }, []); + const sectionsContainerOnScorll = React.useCallback(throttle(() => { + updateSelectedSectionId(); + }, 50), []); + React.useEffect(() => { + updateSelectedSectionId(); + }, []); return (
{ />
- - -
-
+
General
{
-
+
Player
@@ -278,7 +310,7 @@ const Settings = () => { />
-
+
Streaming Server