Skip to content

Commit

Permalink
refactor(files): Drop unneeded initial state
Browse files Browse the repository at this point in the history
The initial state is no longer used, it was only used in legacy UI and in the f2v rewrite
it was only used for the `id` which can be loaded just from the URL.

Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Aug 13, 2024
1 parent f93edb1 commit c6c919a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 61 deletions.
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
30 changes: 20 additions & 10 deletions apps/files/src/components/FilesListVirtual.vue
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,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(open: boolean) {

Check failure on line 201 in apps/files/src/components/FilesListVirtual.vue

View workflow job for this annotation

GitHub Actions / NPM lint

'open' is defined but never used
// 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 +215,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

0 comments on commit c6c919a

Please sign in to comment.