Skip to content

Commit d5552ac

Browse files
committed
fix: add route query for image editor
Signed-off-by: Hamza <hamzamahjoubi221@gmail.com>
1 parent ae6963e commit d5552ac

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/files_actions/viewerAction.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,32 @@ import type { Node, View } from '@nextcloud/files'
77
import { DefaultType, FileAction, Permission, registerFileAction } from '@nextcloud/files'
88
import { t } from '@nextcloud/l10n'
99
import svgEye from '@mdi/svg/svg/eye.svg?raw'
10+
import { emit } from '@nextcloud/event-bus'
1011

1112
/**
1213
* @param node The file to open
1314
* @param view any The files view
1415
* @param dir the directory path
1516
*/
1617
function pushToHistory(node: Node, view: View, dir: string) {
18+
const editing = window.OCP.Files.Router.query.editing === 'true' ? 'true' : 'false'
1719
window.OCP.Files.Router.goToRoute(
1820
null,
1921
{ view: view.id, fileid: String(node.fileid) },
20-
{ dir, openfile: 'true' },
22+
{ dir, openfile: 'true', editing },
2123
true,
2224
)
2325
}
26+
/**
27+
* @param editing True if the file is being edited
28+
*/
29+
export function toggleEditor(editing = false) {
30+
const newQuery = { ...window.OCP.Files.Router.query, editing: editing ? 'true' : 'false' }
31+
window.OCP.Files.Router.goToRoute(null, window.OCP.Files.Router.params, newQuery)
32+
}
2433

2534
const onPopState = () => {
35+
emit('editor:toggle', window.OCP.Files.Router.query?.editing === 'true')
2636
if (window.OCP.Files.Router.query.openfile !== 'true') {
2737
window.OCA.Viewer.close()
2838
window.removeEventListener('popstate', onPopState)
@@ -40,6 +50,7 @@ async function execAction(node: Node, view: View, dir: string): Promise<boolean|
4050
// This can sometime be called with the openfile set to true already. But we don't want to keep openfile when closing the viewer.
4151
const newQuery = { ...window.OCP.Files.Router.query }
4252
delete newQuery.openfile
53+
delete newQuery.editing
4354
window.OCP.Files.Router.goToRoute(null, window.OCP.Files.Router.params, newQuery)
4455
}
4556

src/views/Viewer.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ import Download from 'vue-material-design-icons/Download.vue'
218218
import Fullscreen from 'vue-material-design-icons/Fullscreen.vue'
219219
import FullscreenExit from 'vue-material-design-icons/FullscreenExit.vue'
220220
import Pencil from 'vue-material-design-icons/Pencil.vue'
221+
import { toggleEditor } from '../files_actions/viewerAction.ts'
221222
222223
// Dynamic loading
223224
const NcModal = () => import(
@@ -561,6 +562,7 @@ export default defineComponent({
561562
subscribe('files:sidebar:closed', this.handleAppSidebarClose)
562563
subscribe('files:node:updated', this.handleFileUpdated)
563564
subscribe('viewer:trapElements:changed', this.handleTrapElementsChange)
565+
subscribe('editor:toggle', this.toggleEditor)
564566
window.addEventListener('keydown', this.keyboardDeleteFile)
565567
window.addEventListener('keydown', this.keyboardDownloadFile)
566568
window.addEventListener('keydown', this.keyboardEditFile)
@@ -576,6 +578,7 @@ export default defineComponent({
576578
unsubscribe('files:sidebar:opened', this.handleAppSidebarOpen)
577579
unsubscribe('files:sidebar:closed', this.handleAppSidebarClose)
578580
unsubscribe('viewer:trapElements:changed', this.handleTrapElementsChange)
581+
unsubscribe('editor:toggle', this.toggleEditor)
579582
window.removeEventListener('keydown', this.keyboardDeleteFile)
580583
window.removeEventListener('keydown', this.keyboardDownloadFile)
581584
window.removeEventListener('keydown', this.keyboardEditFile)
@@ -586,6 +589,10 @@ export default defineComponent({
586589
uniqueKey(file) {
587590
return '' + file.fileid + file.source
588591
},
592+
toggleEditor(isOpen) {
593+
toggleEditor(isOpen)
594+
this.editing = isOpen
595+
},
589596
async beforeOpen() {
590597
// initial loading start
591598
this.initiated = true
@@ -644,6 +651,9 @@ export default defineComponent({
644651
const fileInfo = await fileRequest(path)
645652
console.debug('File info for ' + path + ' fetched', fileInfo)
646653
await this.openFileInfo(fileInfo, overrideHandlerId)
654+
if (window.OCP.Files.Router.query.editing === 'true' && this.canEdit) {
655+
this.toggleEditor(true)
656+
}
647657
} catch (error) {
648658
if (error?.response?.status === 404) {
649659
logger.error('The file no longer exists, error: ', { error })
@@ -1158,7 +1168,7 @@ export default defineComponent({
11581168
},
11591169
11601170
onEdit() {
1161-
this.editing = true
1171+
this.toggleEditor(true)
11621172
},
11631173
11641174
handleTrapElementsChange(element) {

0 commit comments

Comments
 (0)