-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Usage of pushToHistory function on prev/next
Signed-off-by: Louis Chemineau <[email protected]>
- Loading branch information
Showing
11 changed files
with
123 additions
and
11 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
/* extracted by css-entry-points-plugin */ | ||
@import './main--fK07A8K.chunk.css'; | ||
@import './main-DnH6w7F4.chunk.css'; | ||
@import './logger-B5Yp6f8I.chunk.css'; |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
import type { Node, View } from '@nextcloud/files' | ||
|
||
import { DefaultType, FileAction, Permission, registerFileAction } from '@nextcloud/files' | ||
import { t } from '@nextcloud/l10n' | ||
import svgEye from '@mdi/svg/svg/eye.svg?raw' | ||
|
||
/** | ||
* @param node The file to open | ||
* @param view any The files view | ||
* @param dir the directory path | ||
*/ | ||
function pushToHistory(node: Node, view: View, dir: string) { | ||
window.OCP.Files.Router.goToRoute( | ||
null, | ||
{ view: view.id, fileid: String(node.fileid) }, | ||
{ dir, openfile: 'true' }, | ||
true, | ||
) | ||
} | ||
|
||
/** | ||
* Execute the viewer files action | ||
* @param node The active node | ||
* @param view The current view | ||
* @param dir The current path | ||
*/ | ||
async function execAction(node: Node, view: View, dir: string): Promise<boolean|null> { | ||
const onClose = () => { | ||
// This can sometime be called with the openfile set to true already. But we don't want to keep openfile when closing the viewer. | ||
const newQuery = { ...window.OCP.Files.Router.query } | ||
delete newQuery.openfile | ||
window.OCP.Files.Router.goToRoute(null, window.OCP.Files.Router.params, newQuery) | ||
} | ||
|
||
pushToHistory(node, view, dir) | ||
window.OCA.Viewer.open({ | ||
path: node.path, | ||
onPrev(fileInfo) { | ||
pushToHistory(fileInfo, view, dir) | ||
}, | ||
onNext(fileInfo) { | ||
pushToHistory(fileInfo, view, dir) | ||
}, | ||
onClose | ||
}) | ||
|
||
return null | ||
} | ||
|
||
/** | ||
* Register the viewer action on the files API | ||
*/ | ||
export function registerViewerAction() { | ||
registerFileAction(new FileAction({ | ||
id: 'view', | ||
displayName: () => t('viewer', 'View'), | ||
iconSvgInline: () => svgEye, | ||
default: DefaultType.DEFAULT, | ||
enabled: (nodes) => { | ||
// Disable if not located in user root | ||
if (nodes.some(node => !(node.isDavRessource && node.root?.startsWith('/files')))) { | ||
return false | ||
} | ||
|
||
return nodes.every((node) => | ||
Boolean(node.permissions & Permission.READ) | ||
&& window.OCA.Viewer.mimetypes.includes(node.mime), | ||
) | ||
}, | ||
exec: execAction, | ||
})) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters