Skip to content

Commit 536c9e4

Browse files
Merge pull request #61627 from nextcloud/fix/theming-select
fix(theming): allow to unselect a font theme
2 parents 0316285 + 43a195c commit 536c9e4

7 files changed

Lines changed: 42 additions & 27 deletions

apps/theming/src/components/ThemeList.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ const props = defineProps<{
2626
*/
2727
multiple?: boolean
2828
29+
/**
30+
* The default theme if multiple is false
31+
*/
32+
default?: ITheme
33+
2934
/**
3035
* The list of available themes
3136
*/
@@ -60,18 +65,13 @@ async function toggleTheme(theme: ITheme, state: boolean) {
6065
return
6166
}
6267
63-
if (!props.multiple && state === false) {
64-
// handled by the radio logic below for the enabled element
65-
return
66-
}
67-
6868
try {
6969
loading.value = true
7070
if (state === false) {
7171
await axios.delete(generateOcsUrl('apps/theming/api/v1/theme/{themeId}', { themeId: theme.id }))
72-
if (!props.multiple) {
72+
if (!props.multiple && props.default) {
7373
// If the theme was disabled, we need to enable the default theme
74-
const defaultTheme = props.themes.find((t) => t.id === 'default')
74+
const defaultTheme = props.themes.find((t) => t.id === props.default!.id)
7575
if (defaultTheme && !defaultTheme.enabled) {
7676
await axios.put(generateOcsUrl('apps/theming/api/v1/theme/{themeId}/enable', { themeId: defaultTheme.id }))
7777
defaultTheme.enabled = true
@@ -112,7 +112,7 @@ async function toggleTheme(theme: ITheme, state: boolean) {
112112
:enforced="theme.id === enforcedTheme"
113113
:loading
114114
:theme
115-
:unique="!multiple"
115+
:type="multiple ? 'checkbox' : ($props.default ? 'radio' : 'switch')"
116116
:name
117117
@update:modelValue="toggleTheme(theme, $event)" />
118118
</ul>

apps/theming/src/components/ThemeListItem.vue

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,30 @@ const props = defineProps<{
3131
/** The theme */
3232
theme: ITheme
3333
/**
34-
* If true, the theme can be selected exclusively (radio button),
35-
* otherwise it can be selected in addition to other themes (switch)
34+
* The type of the switch.
3635
*/
37-
unique: boolean
36+
type: 'checkbox' | 'radio' | 'switch'
3837
/**
3938
* When multiple themes are allowed, this is the name of the input group.
4039
*/
4140
name?: string
4241
}>()
4342
44-
const switchType = computed(() => props.unique ? 'radio' : 'checkbox')
4543
const imageUrl = computed(() => generateFilePath('theming', 'img', props.theme.id + '.jpg'))
44+
const checkboxValue = computed({
45+
get() {
46+
if (props.type === 'switch') {
47+
return isSelected.value
48+
} else if (props.type === 'radio') {
49+
return isSelected.value ? props.theme.id : false
50+
} else {
51+
return isSelected.value ? [props.theme.id] : []
52+
}
53+
},
54+
set() {
55+
isSelected.value = !isSelected.value
56+
},
57+
})
4658
</script>
4759

4860
<template>
@@ -64,13 +76,13 @@ const imageUrl = computed(() => generateFilePath('theming', 'img', props.theme.i
6476
<!-- Only show checkbox if we can change themes -->
6577
<NcCheckboxRadioSwitch
6678
v-show="!enforced"
79+
v-model="checkboxValue"
6780
class="theming__preview-toggle"
6881
:disabled="enforced"
6982
:loading
70-
:name
71-
:type="switchType"
72-
:modelValue="isSelected"
73-
@update:modelValue="isSelected = !isSelected">
83+
:name="type !== 'switch' ? name : undefined"
84+
:type
85+
:value="type !== 'switch' ? theme.id : undefined">
7486
{{ theme.enableLabel }}
7587
</NcCheckboxRadioSwitch>
7688
</div>

apps/theming/src/views/UserTheming.vue

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<ThemeList
1616
:label="t('theming', 'Themes')"
1717
:themes="mainThemes"
18+
:default="defaultTheme"
1819
@updated="updateBodyAttributes" />
1920

2021
<ThemeList
@@ -58,7 +59,7 @@ import axios from '@nextcloud/axios'
5859
import { loadState } from '@nextcloud/initial-state'
5960
import { t } from '@nextcloud/l10n'
6061
import { generateOcsUrl } from '@nextcloud/router'
61-
import { computed, nextTick, ref, useTemplateRef } from 'vue'
62+
import { computed, nextTick, onBeforeMount, ref, useTemplateRef } from 'vue'
6263
import NcCheckboxRadioSwitch from '@nextcloud/vue/components/NcCheckboxRadioSwitch'
6364
import NcNoteCard from '@nextcloud/vue/components/NcNoteCard'
6465
import NcSettingsSection from '@nextcloud/vue/components/NcSettingsSection'
@@ -77,16 +78,18 @@ const availableThemes = ref(loadState<ITheme[]>('theming', 'themes', []))
7778
for (const theme of availableThemes.value) {
7879
theme.enabled = theme.enabled || false
7980
}
80-
if (availableThemes.value.every(({ type, enabled }) => type !== 1 || !enabled)) {
81-
const theme = availableThemes.value.find(({ id, type }) => id === 'default' && type === 1)
82-
if (theme) {
83-
theme.enabled = true
84-
}
85-
}
8681
8782
const mainThemes = computed(() => availableThemes.value.filter((theme) => theme.type === 1))
8883
const fontThemes = computed(() => availableThemes.value.filter((theme) => theme.type === 2))
8984
const supplementaryThemes = computed(() => availableThemes.value.filter((theme) => theme.type === 3))
85+
const defaultTheme = computed(() => mainThemes.value.find((theme) => theme.id === 'default'))
86+
onBeforeMount(() => {
87+
if (availableThemes.value.every(({ type, enabled }) => type !== 1 || !enabled)) {
88+
if (defaultTheme.value) {
89+
defaultTheme.value.enabled = true
90+
}
91+
}
92+
})
9093
9194
const primaryColorSection = useTemplateRef('primaryColor')
9295

dist/theming-settings-personal.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* extracted by css-entry-points-plugin */
2-
@import './theming-theming-settings-personal-BZm8LyXt.chunk.css';
2+
@import './theming-theming-settings-personal-Di6TWq9d.chunk.css';
33
@import './common-createElementId-DhjFt1I9-C_oBIsvc.chunk.css';
44
@import './common-TrashCanOutline-BYHcrfvW.chunk.css';
55
@import './common-NcCheckboxRadioSwitch-D8Dfv4iw-CPGkDj-p.chunk.css';

dist/theming-settings-personal.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/theming-settings-personal.mjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/theming-theming-settings-personal-BZm8LyXt.chunk.css renamed to dist/theming-theming-settings-personal-Di6TWq9d.chunk.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)