Skip to content

Commit 67f74ce

Browse files
feat: handle note restored event on plain mode
Signed-off-by: Luka Trovic <[email protected]>
1 parent 1e1ee8a commit 67f74ce

File tree

5 files changed

+73
-4
lines changed

5 files changed

+73
-4
lines changed

lib/Controller/PageController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use OCA\Notes\Service\SettingsService;
1212
use OCA\Text\Event\LoadEditor;
13+
use OCA\Viewer\Event\LoadViewer;
1314
use OCP\App\IAppManager;
1415
use OCP\AppFramework\Controller;
1516
use OCP\AppFramework\Http\ContentSecurityPolicy;
@@ -71,6 +72,10 @@ public function index() : TemplateResponse {
7172
$this->eventDispatcher->dispatchTyped(new LoadSidebar());
7273
}
7374

75+
if (\OCP\Server::get(IAppManager::class)->isEnabledForUser('viewer') && class_exists(LoadViewer::class)) {
76+
$this->eventDispatcher->dispatchTyped(new LoadViewer());
77+
}
78+
7479
$this->initialState->provideInitialState(
7580
'config',
7681
(array)\OCP\Server::get(SettingsService::class)->getPublic($this->userSession->getUser()->getUID())

src/NotesService.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ export const refreshNote = (noteId, lastETag) => {
150150
return response.headers.etag
151151
}
152152
const currentContent = store.getters.getNote(noteId).content
153+
store.commit('setNoteAttribute', { noteId, attribute: 'internalPath', value: response.data.internalPath })
153154
// only update if local content has not changed
154155
if (oldContent === currentContent) {
155156
_updateLocalNote(response.data)
@@ -290,6 +291,7 @@ export const autotitleNote = noteId => {
290291
.put(url('/notes/' + noteId + '/autotitle'))
291292
.then((response) => {
292293
store.commit('setNoteAttribute', { noteId, attribute: 'title', value: response.data })
294+
refreshNote(noteId)
293295
})
294296
.catch(err => {
295297
console.error(err)

src/components/NoteItem.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ import { showError } from '@nextcloud/dialogs'
6262
import store from '../store.js'
6363
import { setFavorite, setTitle, fetchNote, deleteNote } from '../NotesService.js'
6464
import ShareVariantIcon from 'vue-material-design-icons/ShareVariant.vue'
65-
import { emit, subscribe } from '@nextcloud/event-bus'
65+
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
6666
6767
export default {
6868
name: 'NoteItem',
@@ -131,6 +131,10 @@ export default {
131131
subscribe('files_sharing:share:created', this.onShareCreated)
132132
},
133133
134+
destroyed() {
135+
unsubscribe('files_sharing:share:created', this.onShareCreated)
136+
},
137+
134138
methods: {
135139
onNoteSelected(noteId) {
136140
this.$emit('note-selected', noteId)

src/components/NotePlain.vue

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ import {
103103
isMobile,
104104
} from '@nextcloud/vue'
105105
import { showError } from '@nextcloud/dialogs'
106-
import { emit } from '@nextcloud/event-bus'
106+
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
107107
108108
import EditIcon from 'vue-material-design-icons/LeadPencil.vue'
109109
import EyeIcon from 'vue-material-design-icons/Eye.vue'
@@ -205,6 +205,8 @@ export default {
205205
document.addEventListener('fullscreenchange', this.onDetectFullscreen)
206206
document.addEventListener('keydown', this.onKeyPress)
207207
document.addEventListener('visibilitychange', this.onVisibilityChange)
208+
subscribe('files_versions:restore:requested', this.onFileRestoreRequested)
209+
subscribe('files_versions:restore:restored', this.onFileRestored)
208210
},
209211
210212
destroyed() {
@@ -215,6 +217,8 @@ export default {
215217
document.removeEventListener('keydown', this.onKeyPress)
216218
document.removeEventListener('visibilitychange', this.onVisibilityChange)
217219
this.onUpdateTitle(null)
220+
unsubscribe('files_versions:restore:requested', this.onFileRestoreRequested)
221+
unsubscribe('files_versions:restore:restored', this.onFileRestored)
218222
},
219223
220224
methods: {
@@ -409,6 +413,25 @@ export default {
409413
conflictSolutionRemote(this.note)
410414
this.showConflict = false
411415
},
416+
417+
async onFileRestoreRequested(event) {
418+
const { fileInfo } = event
419+
420+
if (fileInfo.id !== this.note.id) {
421+
return
422+
}
423+
424+
this.loading = true
425+
},
426+
427+
async onFileRestored(version) {
428+
if (version.fileId !== this.note.id) {
429+
return
430+
}
431+
432+
this.refreshNote()
433+
this.loading = false
434+
},
412435
},
413436
}
414437
</script>

src/components/NoteRich.vue

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from '@nextcloud/vue'
1111
import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
1212
13-
import { queueCommand } from '../NotesService.js'
13+
import { queueCommand, refreshNote } from '../NotesService.js'
1414
import { routeIsNewNote } from '../Util.js'
1515
import store from '../store.js'
1616
@@ -58,12 +58,15 @@ export default {
5858
created() {
5959
this.fetchData()
6060
subscribe('files:file:updated', this.fileUpdated)
61-
61+
subscribe('files_versions:restore:requested', this.onFileRestoreRequested)
62+
subscribe('files_versions:restore:restored', this.onFileRestored)
6263
},
6364
6465
destroyed() {
6566
this?.editor?.destroy()
6667
unsubscribe('files:file:updated', this.fileUpdated)
68+
unsubscribe('files_versions:restore:requested', this.onFileRestoreRequested)
69+
unsubscribe('files_versions:restore:restored', this.onFileRestored)
6770
},
6871
6972
methods: {
@@ -144,6 +147,38 @@ export default {
144147
.replaceAll(/\s/gmu, ' ')
145148
return title.length > 0 ? title : t('notes', 'New note')
146149
},
150+
151+
async onFileRestoreRequested(event) {
152+
const { fileInfo } = event
153+
154+
if (fileInfo.id !== this.note.id) {
155+
return
156+
}
157+
158+
this.loading = true
159+
},
160+
161+
async onFileRestored(version) {
162+
if (version.fileId !== this.note.id) {
163+
return
164+
}
165+
166+
const etag = await refreshNote(parseInt(this.noteId), this.etag)
167+
168+
if (etag) {
169+
this.etag = etag
170+
}
171+
172+
const autoResolve = setInterval(() => {
173+
const el = document.querySelector('[data-cy="resolveServerVersion"]')
174+
175+
if (el) {
176+
el.click()
177+
clearInterval(autoResolve)
178+
}
179+
}, 200)
180+
this.loading = false
181+
},
147182
},
148183
}
149184
</script>

0 commit comments

Comments
 (0)