fix: remove unnecessary lodash functions and use setInterval instead

This commit is contained in:
qtchaos 2024-04-10 20:25:45 +03:00
parent e78d7a36f5
commit c8fa561c7f
No known key found for this signature in database
GPG key ID: 7DA98B2B9EF06A90
3 changed files with 14 additions and 17 deletions

View file

@ -103,7 +103,6 @@ module.exports = {
allowSeparatedGroups: true allowSeparatedGroups: true
} }
], ],
"import/no-extraneous-dependencies": ["error", {"devDependencies": true}],
...a11yOff ...a11yOff
} }
}; };

View file

@ -79,7 +79,6 @@
"@types/crypto-js": "^4.2.1", "@types/crypto-js": "^4.2.1",
"@types/dompurify": "^3.0.5", "@types/dompurify": "^3.0.5",
"@types/fscreen": "^1.0.4", "@types/fscreen": "^1.0.4",
"@types/lodash": "^4.17.0",
"@types/lodash.isequal": "^4.5.8", "@types/lodash.isequal": "^4.5.8",
"@types/lodash.merge": "^4.6.9", "@types/lodash.merge": "^4.6.9",
"@types/lodash.throttle": "^4.1.9", "@types/lodash.throttle": "^4.1.9",

View file

@ -1,5 +1,4 @@
import classNames from "classnames"; import classNames from "classnames";
import { debounce, throttle } from "lodash";
import { useCallback, useEffect } from "react"; import { useCallback, useEffect } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
@ -102,23 +101,23 @@ export function NextEpisodeButton(props: {
]); ]);
useEffect(() => { useEffect(() => {
if (!enableAutoplay || !meta || !nextEp || metaType !== "show") return; if (!enableAutoplay || metaType !== "show") return;
const halfPercent = duration / 100;
const isEnding = time >= duration - halfPercent && duration !== 0;
const debouncedLoadNextEpisode = throttle(debounce(loadNextEpisode), 300); const interval = setInterval(() => {
const allowAutoplay = Boolean( const onePercent = duration / 100;
conf().ALLOW_AUTOPLAY || const isEnding = time >= duration - onePercent && duration !== 0;
isExtensionActiveCached() ||
useAuthStore.getState().proxySet,
);
if (isEnding && allowAutoplay) debouncedLoadNextEpisode(); const allowAutoplay = Boolean(
conf().ALLOW_AUTOPLAY ||
isExtensionActiveCached() ||
useAuthStore.getState().proxySet,
);
return () => { if (isEnding && allowAutoplay) loadNextEpisode();
debouncedLoadNextEpisode.cancel(); }, 250);
};
}, [duration, enableAutoplay, loadNextEpisode, meta, metaType, nextEp, time]); return () => clearInterval(interval);
}, [duration, enableAutoplay, loadNextEpisode, metaType, time]);
if (!meta?.episode || !nextEp) return null; if (!meta?.episode || !nextEp) return null;
if (metaType !== "show") return null; if (metaType !== "show") return null;