Skip to content

Commit

Permalink
fix: force sync when exiting the note editor
Browse files Browse the repository at this point in the history
  • Loading branch information
JF-Cozy committed Sep 8, 2022
1 parent 4a77a0b commit cf93575
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

* Note folder path in HeaderNotePath
* UseFileWithPath can handle file without name prop
* Force sync when clicking on back button, in the note editor
* Force sync when exiting the note editor

# 1.21.0
## ✨ Features
Expand Down
10 changes: 9 additions & 1 deletion src/components/notes/editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'

import { useClient } from 'cozy-client'
import { SharingBannerPlugin } from 'cozy-sharing'
import { useWindowEventListener } from 'rooks/dist/esm/hooks/useWindowEventListener'

import EditorView from 'components/notes/editor-view'
import EditorCorner from 'components/notes/EditorCorner'
Expand Down Expand Up @@ -67,8 +68,15 @@ export default function Editor(props) {
doc,
collabProvider
})
// when leaving the component or changing doc

// when leaving the component
useWindowEventListener('beforeunload', () => {
forceSync()
})

// when changing doc
useEffect(() => forceSync, [noteId, doc, forceSync])

// when quitting the webpage
const activate = useCallback(() => collabProvider.isDirty(), [collabProvider])
const { exitConfirmationModal, requestToLeave } = useConfirmExit({
Expand Down

0 comments on commit cf93575

Please sign in to comment.