Skip to content

Commit

Permalink
fix(Viewer): Now wait all sharing fetch before checking write access
Browse files Browse the repository at this point in the history
  • Loading branch information
JF-Cozy committed Jan 21, 2025
1 parent 4d064f9 commit 3657ac3
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/cozy-viewer/src/ViewerContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const ViewerContainer = props => {
const [isReadOnly, setIsReadOnly] = useState(true)
const client = useClient()
useExtendI18n(locales)
const { hasWriteAccess, hasSharedParent } = useSharingContext()
const { hasWriteAccess, hasSharedParent, allLoaded } = useSharingContext()

const currentFile = files[currentIndex]
const fileCount = files.length
Expand All @@ -59,17 +59,26 @@ const ViewerContainer = props => {
document: currentFile,
client
})
: !hasWriteAccess(
: allLoaded
? !hasWriteAccess(
hasSharedParent(currentFile.path)
? currentFile.dir_id
: currentFile._id
)
: true

setIsReadOnly(res)
}

getIsReadOnly()
}, [client, currentFile, hasWriteAccess, hasSharedParent, isPublic])
}, [
client,
currentFile,
hasWriteAccess,
hasSharedParent,
allLoaded,
isPublic
])

return (
<AlertProvider>
Expand Down

0 comments on commit 3657ac3

Please sign in to comment.