Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable text editor autosave #8455

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/unreleased/enhancement-autosave-text-editor-changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Enhancement: Autosave content changes in text editor

We have added the configurable functionality to autosave content changes in text editor.

https://github.com/owncloud/web/pull/8455
2 changes: 2 additions & 0 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ hovers the row with his mouse. Defaults to `false`.
- `option.routing` This accepts an object with the following fields to customize the routing behaviour:
- `options.routing.idBased` Enable or disable fileIds being added to the URL. Defaults to `true` because otherwise e.g. spaces with name clashes can't be resolved correctly. Only disable this if you can guarantee server side that spaces of the same namespace can't have name clashes.
- `options.upload.xhr.timeout` Specifies the timeout for XHR uploads in milliseconds.
- `options.editor.autosaveEnabled` Specifies if the autosave for the text editor is enabled.
- `options.editor.autosaveInterval` Specifies the time interval for the file editor autosave in milliseconds.

### Sentry

Expand Down
20 changes: 19 additions & 1 deletion packages/web-app-text-editor/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export default defineComponent({
const resource: Ref<Resource> = ref()
const store = useStore()
const { $gettext, interpolate: $gettextInterpolate } = useGettext()
let autosaveInterval = ref(null)

const errorPopup = (error) => {
store.dispatch('showMessage', {
Expand All @@ -111,6 +112,12 @@ export default defineComponent({
})
}

const autosavePopup = () => {
store.dispatch('showMessage', {
title: $gettext('File autosaved')
})
}

const loadFileTask = useTask(function* () {
resource.value = yield getFileInfo(currentFileContext, {
davProperties: [DavProperty.FileId, DavProperty.Permissions, DavProperty.Name]
Expand Down Expand Up @@ -194,7 +201,7 @@ export default defineComponent({
})

const isLoading = computed(() => {
return loadFileTask.isRunning || saveFileTask.isRunning
return loadFileTask.isRunning
})

const showPreview = computed(() => {
Expand All @@ -215,11 +222,22 @@ export default defineComponent({
document.addEventListener('keydown', handleSKey, false)
// Ensure reload is not possible if there are changes
window.addEventListener('beforeunload', handleUnload)

// Autosave
const editorOptions = store.getters.configuration?.options?.editor
if (editorOptions?.autosaveEnabled && editorOptions?.autosaveInterval) {
autosaveInterval.value = setInterval(() => {
if (isDirty.value) {
save().then((r) => autosavePopup())
}
}, editorOptions?.autosaveInterval)
}
})

onBeforeUnmount(() => {
window.removeEventListener('beforeunload', handleUnload)
document.removeEventListener('keydown', handleSKey, false)
clearInterval(autosaveInterval)
})

const save = async function () {
Expand Down