refactor(files): Drop unneeded initial state

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 <opensource@fthiessen.de>
This commit is contained in:
Ferdinand Thiessen 2024-08-03 14:04:25 +02:00 committed by skjnldsv
parent 0c0ba5f552
commit 7fec706f68
2 changed files with 20 additions and 62 deletions

View file

@ -221,60 +221,9 @@ class ViewController extends Controller {
$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
*

View file

@ -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'
@ -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,
},
},
@ -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() {