diff --git a/web/src/hooks/useEpisodeArtworkPreference.ts b/web/src/hooks/useEpisodeArtworkPreference.ts index e267807..a6ccc78 100644 --- a/web/src/hooks/useEpisodeArtworkPreference.ts +++ b/web/src/hooks/useEpisodeArtworkPreference.ts @@ -2,6 +2,7 @@ import { useCallback, useEffect, useRef, useState, type Dispatch, type SetStateA import toast from 'react-hot-toast' import { adminAPI } from '../api/admin' +import { useAuthStore } from '../stores/auth' const SETTING_KEY = 'scrape.episode_images' @@ -13,8 +14,11 @@ export function useEpisodeArtworkPreference(): [boolean, Dispatch state.user?.role === 'admin') useEffect(() => { + if (!isAdmin) return + let active = true adminAPI.listSettings() .then((settings) => { @@ -32,9 +36,11 @@ export function useEpisodeArtworkPreference(): [boolean, Dispatch { active = false } - }, []) + }, [isAdmin]) const setEnabled = useCallback((nextValue: SetStateAction) => { + if (!isAdmin) return + const next = typeof nextValue === 'function' ? nextValue(enabledRef.current) : nextValue if (enabledRef.current === next) return changedLocally.current = true @@ -47,7 +53,7 @@ export function useEpisodeArtworkPreference(): [boolean, Dispatch { toast.error('保存每集图片设置失败') }) - }, []) + }, [isAdmin]) return [enabled, setEnabled] }