From c8fa561c7f73682be58e5e7140f5d5ad4b753d87 Mon Sep 17 00:00:00 2001 From: qtchaos <72168435+qtchaos@users.noreply.github.com> Date: Wed, 10 Apr 2024 20:25:45 +0300 Subject: [PATCH] fix: remove unnecessary lodash functions and use setInterval instead --- .eslintrc.js | 1 - package.json | 1 - .../player/atoms/NextEpisodeButton.tsx | 29 +++++++++---------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index f27e359d..e9b54595 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -103,7 +103,6 @@ module.exports = { allowSeparatedGroups: true } ], - "import/no-extraneous-dependencies": ["error", {"devDependencies": true}], ...a11yOff } }; diff --git a/package.json b/package.json index 22501a81..d70f0143 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,6 @@ "@types/crypto-js": "^4.2.1", "@types/dompurify": "^3.0.5", "@types/fscreen": "^1.0.4", - "@types/lodash": "^4.17.0", "@types/lodash.isequal": "^4.5.8", "@types/lodash.merge": "^4.6.9", "@types/lodash.throttle": "^4.1.9", diff --git a/src/components/player/atoms/NextEpisodeButton.tsx b/src/components/player/atoms/NextEpisodeButton.tsx index 60ba63eb..07d89068 100644 --- a/src/components/player/atoms/NextEpisodeButton.tsx +++ b/src/components/player/atoms/NextEpisodeButton.tsx @@ -1,5 +1,4 @@ import classNames from "classnames"; -import { debounce, throttle } from "lodash"; import { useCallback, useEffect } from "react"; import { useTranslation } from "react-i18next"; @@ -102,23 +101,23 @@ export function NextEpisodeButton(props: { ]); useEffect(() => { - if (!enableAutoplay || !meta || !nextEp || metaType !== "show") return; - const halfPercent = duration / 100; - const isEnding = time >= duration - halfPercent && duration !== 0; + if (!enableAutoplay || metaType !== "show") return; - const debouncedLoadNextEpisode = throttle(debounce(loadNextEpisode), 300); - const allowAutoplay = Boolean( - conf().ALLOW_AUTOPLAY || - isExtensionActiveCached() || - useAuthStore.getState().proxySet, - ); + const interval = setInterval(() => { + const onePercent = duration / 100; + const isEnding = time >= duration - onePercent && duration !== 0; - if (isEnding && allowAutoplay) debouncedLoadNextEpisode(); + const allowAutoplay = Boolean( + conf().ALLOW_AUTOPLAY || + isExtensionActiveCached() || + useAuthStore.getState().proxySet, + ); - return () => { - debouncedLoadNextEpisode.cancel(); - }; - }, [duration, enableAutoplay, loadNextEpisode, meta, metaType, nextEp, time]); + if (isEnding && allowAutoplay) loadNextEpisode(); + }, 250); + + return () => clearInterval(interval); + }, [duration, enableAutoplay, loadNextEpisode, metaType, time]); if (!meta?.episode || !nextEp) return null; if (metaType !== "show") return null;