Skip to content

Commit

Permalink
fix: Close viewer if we navigate back in browser history
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Knorr <jus@bitgrid.net>
Signed-off-by: nextcloud-command <nextcloud-command@users.noreply.github.com>
  • Loading branch information
juliusknorr committed Jan 7, 2025
1 parent c1507af commit 4f5b728
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
29 changes: 29 additions & 0 deletions cypress/e2e/navigation.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

describe('Browser navigation', function() {
before(function() {
// Init user
cy.createRandomUser().then(user => {
// Upload test files
cy.uploadFile(user, 'image.png', 'image/png', '/image1.png')

// Visit nextcloud
cy.login(user)
cy.visit('/apps/files')
})
})
after(function() {
cy.logout()
})

it('Navigating back to the files overview', function() {
cy.getFile('image1.png', { timeout: 10000 })
cy.openFile('image1.png')
cy.get('body > .viewer').should('be.visible')
cy.go('back')
cy.get('body > .viewer').should('not.exist')
})
})
9 changes: 9 additions & 0 deletions src/files_actions/viewerAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ function pushToHistory(node: Node, view: View, dir: string) {
)
}

const onPopState = () => {
if (window.OCP.Files.Router.query.openfile !== 'true') {
window.OCA.Viewer.close()
window.removeEventListener('popstate', onPopState)
}
}

/**
* Execute the viewer files action
* @param node The active node
Expand All @@ -36,6 +43,8 @@ async function execAction(node: Node, view: View, dir: string): Promise<boolean|
window.OCP.Files.Router.goToRoute(null, window.OCP.Files.Router.params, newQuery)
}

window.addEventListener('popstate', onPopState)

pushToHistory(node, view, dir)
window.OCA.Viewer.open({
path: node.path,
Expand Down

0 comments on commit 4f5b728

Please sign in to comment.