diff --git a/packages/web/src/javascripts/Components/FileView/FileView.tsx b/packages/web/src/javascripts/Components/FileView/FileView.tsx index 5549dde94..ceffe5508 100644 --- a/packages/web/src/javascripts/Components/FileView/FileView.tsx +++ b/packages/web/src/javascripts/Components/FileView/FileView.tsx @@ -5,17 +5,27 @@ import FileViewWithoutProtection from './FileViewWithoutProtection' import { FileViewProps } from './FileViewProps' const FileView = ({ application, viewControllerManager, file }: FileViewProps) => { - const [shouldShowProtectedOverlay, setShouldShowProtectedOverlay] = useState( - file.protected && !application.hasProtectionSources(), - ) + const [shouldShowProtectedOverlay, setShouldShowProtectedOverlay] = useState(false) + + useEffect(() => { + viewControllerManager.filesController.setShowProtectedOverlay(file.protected && !application.hasProtectionSources()) + }, [application, file.protected, viewControllerManager.filesController]) useEffect(() => { setShouldShowProtectedOverlay(viewControllerManager.filesController.showProtectedOverlay) }, [viewControllerManager.filesController.showProtectedOverlay]) - const dismissProtectedWarning = useCallback(() => { - void viewControllerManager.filesController.toggleFileProtection(file) - }, [file, viewControllerManager.filesController]) + const dismissProtectedOverlay = useCallback(async () => { + let showFileContents = true + + if (application.hasProtectionSources()) { + showFileContents = await application.protections.authorizeItemAccess(file) + } + + if (showFileContents) { + setShouldShowProtectedOverlay(false) + } + }, [application, file]) return shouldShowProtectedOverlay ? (