diff --git a/app/src/components/Common.js b/app/src/components/Common.js index 0f33deff..e4c9d5af 100644 --- a/app/src/components/Common.js +++ b/app/src/components/Common.js @@ -43,7 +43,7 @@ import { } from "./Theme"; import {FilePreviewContext} from "./FilePreview"; import _ from "lodash"; -import {killDownloads, startDownloads} from "../api"; +import {killDownloads, startDownloads, unlockCookies} from "../api"; import {allFrequencyOptions, NAME, semanticUIColorMap, validUrlRegex} from "./Vars"; import Grid from "semantic-ui-react/dist/commonjs/collections/Grid"; @@ -591,25 +591,88 @@ export function WROLModeMessage({content}) { return null; } +export function CookiesUnlockModal({open, onClose, onSuccess}) { + const [password, setPassword] = useState(''); + const [submitting, setSubmitting] = useState(false); + const passwordRef = React.useRef(null); + + useEffect(() => { + if (open) { + const timer = setTimeout(() => { + if (passwordRef.current) { + passwordRef.current.focus(); + } + }, 100); + return () => clearTimeout(timer); + } + }, [open]); + + const handleUnlock = async () => { + setSubmitting(true); + const result = await unlockCookies(password); + setSubmitting(false); + if (result.success) { + setPassword(''); + if (onSuccess) onSuccess(); + onClose(); + } + }; + + return + Unlock Cookies + +
+ setPassword(e.target.value)} + onKeyPress={(e) => e.key === 'Enter' && handleUnlock()} + /> + +
+ + + + +
; +} + export function CookiesLockedMessage() { const {settings} = React.useContext(SettingsContext); const {status} = React.useContext(StatusContext); const flags = status?.flags || {}; + const [modalOpen, setModalOpen] = useState(false); + if (!flags.cookies_exist || flags.cookies_unlocked || settings?.wrol_mode) { return null; } - return - - - Cookies Locked - You have encrypted cookies stored, but they are currently locked. - - Unlock in Video Settings - - - ; + return <> + + + + Cookies Locked + You have encrypted cookies stored, but they are currently locked. + setModalOpen(true)}> + Unlock Cookies + + + + + setModalOpen(false)}/> + ; } // Thanks https://www.npmjs.com/package/text-ellipsis diff --git a/app/src/components/Videos.js b/app/src/components/Videos.js index 7f28c475..c6dafe3c 100644 --- a/app/src/components/Videos.js +++ b/app/src/components/Videos.js @@ -23,7 +23,8 @@ import { SortButton, TabLinks, textEllipsis, - useTitle + useTitle, + CookiesUnlockModal } from "./Common" import VideoPage from "./VideoPlayer"; import { @@ -59,7 +60,6 @@ import { lockCookies, postVideoFileFormat, previewBatchReorganization, - unlockCookies, updateVideoDownloaderConfig, uploadCookies, } from "../api"; @@ -582,9 +582,7 @@ function CookiesSettingsSection() { const [unlockModalOpen, setUnlockModalOpen] = useState(false); const [cookiesContent, setCookiesContent] = useState(''); const [password, setPassword] = useState(''); - const [unlockPassword, setUnlockPassword] = useState(''); const [submitting, setSubmitting] = useState(false); - const unlockPasswordRef = useRef(null); const cookiesContentRef = useRef(null); useEffect(() => { @@ -598,18 +596,6 @@ function CookiesSettingsSection() { } }, [uploadModalOpen]); - useEffect(() => { - if (unlockModalOpen) { - // Delay focus to allow modal animation to complete - const timer = setTimeout(() => { - if (unlockPasswordRef.current) { - unlockPasswordRef.current.focus(); - } - }, 100); - return () => clearTimeout(timer); - } - }, [unlockModalOpen]); - const fetchStatus = async () => { setLoading(true); const result = await getCookiesStatus(); @@ -638,17 +624,6 @@ function CookiesSettingsSection() { } }; - const handleUnlock = async () => { - setSubmitting(true); - const result = await unlockCookies(unlockPassword); - setSubmitting(false); - if (result.success) { - setUnlockModalOpen(false); - setUnlockPassword(''); - fetchStatus(); - } - }; - const handleLock = async () => { setSubmitting(true); await lockCookies(); @@ -795,38 +770,11 @@ function CookiesSettingsSection() { - {/* Unlock Modal */} - setUnlockModalOpen(false)} - size='tiny' - > - Unlock Cookies - -
- setUnlockPassword(e.target.value)} - onKeyPress={(e) => e.key === 'Enter' && handleUnlock()} - /> - -
- - - - -
+ onSuccess={fetchStatus} + /> ; }