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

fix: Close viewer if we navigate back in browser history #2661

Merged
merged 1 commit into from
Jan 7, 2025
Merged
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
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')
})
})
2 changes: 1 addition & 1 deletion js/viewer-init.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/viewer-init.mjs.map

Large diffs are not rendered by default.

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 @@
)
}

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 @@
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 All @@ -45,7 +54,7 @@
onNext(fileInfo) {
pushToHistory(fileInfo, view, dir)
},
onClose

Check warning on line 57 in src/files_actions/viewerAction.ts

View workflow job for this annotation

GitHub Actions / NPM lint

Missing trailing comma
})

return null
Expand Down
Loading