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' import { FileViewProps } from './FileViewProps'
const FileView = ({ application, viewControllerManager, file }: FileViewProps) => { const FileView = ({ application, viewControllerManager, file }: FileViewProps) => {
const [shouldShowProtectedOverlay, setShouldShowProtectedOverlay] = useState( const [shouldShowProtectedOverlay, setShouldShowProtectedOverlay] = useState(false)
file.protected && !application.hasProtectionSources(),
) useEffect(() => {
viewControllerManager.filesController.setShowProtectedOverlay(file.protected && !application.hasProtectionSources())
}, [application, file.protected, viewControllerManager.filesController])
useEffect(() => { useEffect(() => {
setShouldShowProtectedOverlay(viewControllerManager.filesController.showProtectedOverlay) setShouldShowProtectedOverlay(viewControllerManager.filesController.showProtectedOverlay)
}, [viewControllerManager.filesController.showProtectedOverlay]) }, [viewControllerManager.filesController.showProtectedOverlay])
const dismissProtectedWarning = useCallback(() => { const dismissProtectedOverlay = useCallback(async () => {
void viewControllerManager.filesController.toggleFileProtection(file) let showFileContents = true
}, [file, viewControllerManager.filesController])
if (application.hasProtectionSources()) {
showFileContents = await application.protections.authorizeItemAccess(file)
}
if (showFileContents) {
setShouldShowProtectedOverlay(false)
}
}, [application, file])
return shouldShowProtectedOverlay ? ( return shouldShowProtectedOverlay ? (
<div aria-label="Note" className="section editor sn-component"> <div aria-label="Note" className="section editor sn-component">
@@ -23,7 +33,7 @@ const FileView = ({ application, viewControllerManager, file }: FileViewProps) =
<ProtectedItemOverlay <ProtectedItemOverlay
viewControllerManager={viewControllerManager} viewControllerManager={viewControllerManager}
hasProtectionSources={application.hasProtectionSources()} hasProtectionSources={application.hasProtectionSources()}
onViewItem={dismissProtectedWarning} onViewItem={dismissProtectedOverlay}
itemType={'note'} itemType={'note'}
/> />
</div> </div>

View File

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