Skip to content
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
51 changes: 0 additions & 51 deletions apps/files/lib/Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,60 +221,9 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal
$policy->addAllowedWorkerSrcDomain('\'self\'');
$response->setContentSecurityPolicy($policy);

$this->provideInitialState($dir, $fileid);

return $response;
}

/**
* Add openFileInfo in initialState.
* @param string $dir - the ?dir= URL param
* @param string $fileid - the fileid URL param
* @return void
*/
private function provideInitialState(string $dir, ?string $fileid): void {
if ($fileid === null) {
return;
}

$user = $this->userSession->getUser();

if ($user === null) {
return;
}

$uid = $user->getUID();
$userFolder = $this->rootFolder->getUserFolder($uid);
$node = $userFolder->getFirstNodeById((int) $fileid);

if ($node === null) {
return;
}

// properly format full path and make sure
// we're relative to the user home folder
$isRoot = $node === $userFolder;
$path = $userFolder->getRelativePath($node->getPath());
$directory = $userFolder->getRelativePath($node->getParent()->getPath());

// Prevent opening a file from another folder.
if ($dir !== $directory) {
return;
}

$this->initialState->provideInitialState(
'fileInfo', [
'id' => $node->getId(),
'name' => $isRoot ? '' : $node->getName(),
'path' => $path,
'directory' => $directory,
'mime' => $node->getMimetype(),
'type' => $node->getType(),
'permissions' => $node->getPermissions(),
]
);
}

/**
* Redirects to the trashbin file list and highlight the given file id
*
Expand Down
31 changes: 20 additions & 11 deletions apps/files/src/components/FilesListVirtual.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ import type { UserConfig } from '../types'

import { getFileListHeaders, Folder, View, getFileActions, FileType } from '@nextcloud/files'
import { showError } from '@nextcloud/dialogs'
import { loadState } from '@nextcloud/initial-state'
import { translate as t } from '@nextcloud/l10n'
import { defineComponent } from 'vue'

Expand Down Expand Up @@ -190,14 +189,23 @@ export default defineComponent({
},

watch: {
fileId(fileId) {
this.scrollToFile(fileId, false)
fileId: {
handler(fileId) {
this.scrollToFile(fileId, false)
},
immediate: true,
},

openFile(open: boolean) {
if (open) {
this.$nextTick(() => this.handleOpenFile(this.fileId))
}
openFile: {
handler() {
// wait for scrolling and updating the actions to settle
this.$nextTick(() => {
if (this.fileId && this.openFile) {
this.handleOpenFile(this.fileId)
}
})
},
immediate: true,
},
},

Expand All @@ -206,10 +214,11 @@ export default defineComponent({
const mainContent = window.document.querySelector('main.app-content') as HTMLElement
mainContent.addEventListener('dragover', this.onDragOver)

const { id } = loadState<{ id?: number }>('files', 'fileInfo', {})
this.scrollToFile(id ?? this.fileId)
this.openSidebarForFile(id ?? this.fileId)
this.handleOpenFile(id ?? null)
// If the file list is mounted with a fileId specified
// then we need to open the sidebar initially
if (this.fileId) {
this.openSidebarForFile(this.fileId)
}
},

beforeDestroy() {
Expand Down
4 changes: 2 additions & 2 deletions dist/files-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-main.js.map

Large diffs are not rendered by default.