Skip to content

Commit ae855f9

Browse files
committed
fix(settings): use proper component structure to make navigation work
`NcAppNavigation` is only allowed in `NcContent` but we were not using it because the content was rendered by the server as templates. This is now fixed by moving the content inside the `NcContent` once mounted. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent b002443 commit ae855f9

7 files changed

Lines changed: 58 additions & 27 deletions

File tree

apps/settings/src/main-settings.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
import { getCSPNonce } from '@nextcloud/auth'
77
import Vue from 'vue'
8-
import SettingsNavigation from './views/SettingsNavigation.vue'
8+
import SettingsApp from './views/SettingsApp.vue'
99

1010
__webpack_nonce__ = getCSPNonce()
1111

12-
const app = new Vue(SettingsNavigation)
13-
app.$mount('#app-navigation')
12+
const app = new Vue(SettingsApp)
13+
app.$mount('#settings-app')

apps/settings/src/main-users-management.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import VTooltipPlugin from 'v-tooltip'
1212
import Vue from 'vue'
1313
import Vuex from 'vuex'
1414
import { sync } from 'vuex-router-sync'
15-
import SettingsApp from './views/SettingsApp.vue'
15+
import UserManagement from './views/UserManagement.vue'
1616
import router from './router/index.ts'
1717
import { useStore } from './store/index.js'
1818

@@ -37,10 +37,10 @@ const pinia = createPinia()
3737
// Migrate legacy local storage settings to the database
3838
store.dispatch('migrateLocalStorage')
3939

40-
export default new Vue({
40+
const App = Vue.extend(UserManagement)
41+
const app = new App({
4142
router,
4243
store,
4344
pinia,
44-
render: (h) => h(SettingsApp),
45-
el: '#content',
4645
})
46+
app.$mount('#content')

apps/settings/src/router/routes.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
1-
/**
1+
/*
22
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

66
import type { RouteConfig } from 'vue-router'
77

8-
const UserManagement = () => import(/* webpackChunkName: 'settings-users' */'../views/UserManagement.vue')
9-
const UserManagementNavigation = () => import(/* webpackChunkName: 'settings-users' */'../views/UserManagementNavigation.vue')
10-
118
const routes: RouteConfig[] = [
129
{
1310
name: 'users',
1411
path: '/:index(index.php/)?settings/users',
15-
components: {
16-
default: UserManagement,
17-
navigation: UserManagementNavigation,
18-
},
1912
props: true,
2013
children: [
2114
{

apps/settings/src/views/SettingsApp.vue

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,22 @@
44
-->
55

66
<template>
7-
<NcContent app-name="settings">
8-
<router-view name="navigation" />
9-
<router-view />
10-
<router-view name="sidebar" />
7+
<NcContent :class="$style.settingsApp" appName="settings">
8+
<SettingsNavigation />
9+
<SettingsContentWrapper />
1110
</NcContent>
1211
</template>
1312

1413
<script setup lang="ts">
1514
import NcContent from '@nextcloud/vue/components/NcContent'
15+
import SettingsContentWrapper from './SettingsContentWrapper.vue'
16+
import SettingsNavigation from './SettingsNavigation.vue'
1617
</script>
18+
19+
<style module>
20+
:global(#content):has(.settingsApp) {
21+
margin: 0;
22+
width: 100%;
23+
height: 100%;
24+
}
25+
</style>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!--
2+
- SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
3+
- SPDX-License-Identifier: AGPL-3.0-or-later
4+
-->
5+
6+
<template>
7+
<NcAppContent>
8+
<div ref="contentMain" />
9+
</NcAppContent>
10+
</template>
11+
12+
<script setup lang="ts">
13+
import { NcAppContent } from '@nextcloud/vue'
14+
import { onMounted, ref } from 'vue'
15+
16+
const contentMain = ref<HTMLDivElement>()
17+
onMounted(() => {
18+
const realElement = document.getElementById('original-settings-content')!
19+
contentMain.value!.replaceChildren(...realElement.childNodes)
20+
realElement.parentNode!.removeChild(realElement)
21+
})
22+
</script>

apps/settings/src/views/UserManagement.vue

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,33 @@
44
-->
55

66
<template>
7-
<NcAppContent :page-heading="pageHeading">
8-
<UserList
9-
:selected-group="selectedGroupDecoded"
10-
:external-actions="externalActions" />
11-
</NcAppContent>
7+
<NcContent app-name="settings">
8+
<UserManagementNavigation />
9+
<NcAppContent :page-heading="pageHeading">
10+
<UserList
11+
:selected-group="selectedGroupDecoded"
12+
:external-actions="externalActions" />
13+
</NcAppContent>
14+
</NcContent>
1215
</template>
1316

1417
<script>
1518
import { emit } from '@nextcloud/event-bus'
1619
import { translate as t } from '@nextcloud/l10n'
1720
import { defineComponent } from 'vue'
1821
import NcAppContent from '@nextcloud/vue/components/NcAppContent'
22+
import NcContent from '@nextcloud/vue/components/NcContent'
1923
import UserList from '../components/UserList.vue'
24+
import UserManagementNavigation from './UserManagementNavigation.vue'
2025
2126
export default defineComponent({
2227
name: 'UserManagement',
2328
2429
components: {
30+
NcContent,
2531
NcAppContent,
2632
UserList,
33+
UserManagementNavigation,
2734
},
2835
2936
data() {

apps/settings/templates/settings/frame.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
style('settings', 'settings');
88
?>
99

10-
<div id="app-navigation"></div>
11-
<main id="app-content" <?php if (!empty($_['activeSectionId'])) { ?> data-active-section-id="<?php print_unescaped($_['activeSectionId']) ?>" <?php } if (!empty($_['activeSectionType'])) { ?> data-active-section-type="<?php print_unescaped($_['activeSectionType']) ?>" <?php } ?>>
10+
<div id="settings-app"></div>
11+
<div class="hidden-visually" id="original-settings-content" <?php if (!empty($_['activeSectionId'])) { ?> data-active-section-id="<?php print_unescaped($_['activeSectionId']) ?>" <?php } if (!empty($_['activeSectionType'])) { ?> data-active-section-type="<?php print_unescaped($_['activeSectionType']) ?>" <?php } ?>>
1212
<?php print_unescaped($_['content']); ?>
13-
</main>
13+
</div>

0 commit comments

Comments
 (0)