fix(web): file protected overlay not toggling off correctly (#1190)

This commit is contained in:
Aman Harwara
2022-07-01 19:20:15 +05:30
committed by GitHub
parent 297b3bb4f8
commit 7c3c59dd92
2 changed files with 18 additions and 7 deletions

View File

@@ -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 ? (
<div aria-label="Note" className="section editor sn-component">
@@ -23,7 +33,7 @@ const FileView = ({ application, viewControllerManager, file }: FileViewProps) =
<ProtectedItemOverlay
viewControllerManager={viewControllerManager}
hasProtectionSources={application.hasProtectionSources()}
onViewItem={dismissProtectedWarning}
onViewItem={dismissProtectedOverlay}
itemType={'note'}
/>
</div>

View File

@@ -423,6 +423,7 @@ export class FilesController extends AbstractViewController {
this.setShowProtectedOverlay(false)
}
}
void this.application.sync.sync()
}
downloadFiles = async (files: FileItem[]) => {