aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_sharing/src/init-public.ts
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_sharing/src/init-public.ts')
-rw-r--r--apps/files_sharing/src/init-public.ts34
1 files changed, 31 insertions, 3 deletions
diff --git a/apps/files_sharing/src/init-public.ts b/apps/files_sharing/src/init-public.ts
index 79aab58bd1d..72a3098a0e6 100644
--- a/apps/files_sharing/src/init-public.ts
+++ b/apps/files_sharing/src/init-public.ts
@@ -2,13 +2,16 @@
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
-import { getNavigation } from '@nextcloud/files'
+import type { ShareAttribute } from './sharing.d.ts'
+import { emit, subscribe, unsubscribe } from '@nextcloud/event-bus'
+import { Folder, getNavigation } from '@nextcloud/files'
import { loadState } from '@nextcloud/initial-state'
import registerFileDropView from './files_views/publicFileDrop.ts'
import registerPublicShareView from './files_views/publicShare.ts'
import registerPublicFileShareView from './files_views/publicFileShare.ts'
-import RouterService from '../../files/src/services/RouterService'
-import router from './router'
+import RouterService from '../../files/src/services/RouterService.ts'
+import router from './router/index.ts'
+import logger from './services/logger.ts'
registerFileDropView()
registerPublicShareView()
@@ -33,3 +36,28 @@ if (fileId !== null) {
{ ...window.OCP.Files.Router.query, openfile: 'true' },
)
}
+
+// When the file list is loaded we need to apply the "userconfig" setup on the share
+subscribe('files:list:updated', loadShareConfig)
+
+/**
+ * Event handler to load the view config for the current share.
+ * This is done on the `files:list:updated` event to ensure the list and especially the config store was correctly initialized.
+ *
+ * @param context The event context
+ * @param context.folder The current folder
+ */
+function loadShareConfig({ folder }: { folder: Folder }) {
+ // Only setup config once
+ unsubscribe('files:list:updated', loadShareConfig)
+
+ // Share attributes (the same) are set on all folders of a share
+ if (folder.attributes['share-attributes']) {
+ const shareAttributes = JSON.parse(folder.attributes['share-attributes'] || '[]') as Array<ShareAttribute>
+ const gridViewAttribute = shareAttributes.find(({ scope, key }: ShareAttribute) => scope === 'config' && key === 'grid_view')
+ if (gridViewAttribute !== undefined) {
+ logger.debug('Loading share attributes', { gridViewAttribute })
+ emit('files:config:updated', { key: 'grid_view', value: gridViewAttribute.value === true })
+ }
+ }
+}