Skip to content

Commit 6ddb416

Browse files
fix: enable real-time theme preview and refactor (#1175)
1 parent bbd03e0 commit 6ddb416

File tree

2 files changed

+26
-35
lines changed

2 files changed

+26
-35
lines changed

app/eventyay/webapp/src/components/ColorPicker.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.c-color-picker
33
.color(:style="{'--color': modelValue}")
44
bunt-input(v-bind="$attrs", :modelValue="modelValue", @update:modelValue="$emit('update:modelValue', $event)")
5-
input.color-picker(type="color", :value="modelValue", @change="$emit('update:modelValue', $event.target.value)")
5+
input.color-picker(type="color", :value="modelValue", @input="$emit('update:modelValue', $event.target.value)")
66
</template>
77
<script>
88
export default {

app/eventyay/webapp/src/views/admin/config/theme.vue

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ export default {
4444
setup:() => ({v$:useVuelidate()}),
4545
data() {
4646
return {
47-
// We do not use the global config object since we cannot rely on it being up to date (theme is only updated
48-
// during application load).
4947
config: null,
50-
5148
saving: false,
5249
error: null
5350
}
@@ -67,40 +64,30 @@ export default {
6764
}))
6865
}
6966
},
67+
watch: {
68+
'config.theme': {
69+
deep: true,
70+
handler() {
71+
this._applyThemePreview()
72+
}
73+
}
74+
},
7075
validations: {
7176
config: {
7277
theme: {
7378
colors: {
74-
primary: {
75-
required: required('primary color is required'),
76-
color: color('color must be in 3 or 6 digit hex format')
77-
},
78-
sidebar: {
79-
required: required('sidebar color is required'),
80-
color: color('color must be in 3 or 6 digit hex format')
81-
},
82-
bbb_background: {
83-
required: required('BBB background color is required'),
84-
color: color('color must be in 3 or 6 digit hex format')
85-
},
86-
},
87-
logo: {
88-
url: {
89-
url: url('must be a valid url')
90-
}
79+
primary: { required, color },
80+
sidebar: { required, color },
81+
bbb_background: { required, color },
9182
},
92-
streamOfflineImage: {
93-
url: url('must be a valid url')
94-
}
83+
logo: { url },
84+
streamOfflineImage: { url }
9585
},
9686
}
9787
},
9888
async created() {
99-
// TODO: Force reloading if world.updated is received from the server
10089
try {
10190
this.config = await api.call('world.config.get')
102-
103-
// Enforce some defaults
10491
this.config.theme = {logo: {}, colors: {}, streamOfflineImage: null, textOverwrites: {}, ...this.config.theme}
10592
this.config.theme.colors = {...DEFAULT_COLORS, ...this.config.theme.colors}
10693
this.config.theme.logo = {...DEFAULT_LOGO, ...this.config.theme.logo}
@@ -111,13 +98,23 @@ export default {
11198
}
11299
},
113100
methods: {
101+
// New helper method to apply theme changes (as suggested by Sourcery)
102+
_applyThemePreview() {
103+
if (!this.config) return
104+
const themePayload = {
105+
colors: {...DEFAULT_COLORS, ...this.config.theme.colors},
106+
logo: {...DEFAULT_LOGO, ...this.config.theme.logo},
107+
streamOfflineImage: this.config.theme.streamOfflineImage ?? null,
108+
identicons: {...DEFAULT_IDENTICONS, ...this.config.theme.identicons}
109+
}
110+
applyThemeConfig(themePayload)
111+
},
114112
async save() {
115113
this.v$.$touch()
116114
if (this.v$.$invalid) return
117115
if (!this.config) return
118116
119117
this.error = null
120-
// Cleanup empty strings in text overwrites
121118
for (const key of Object.keys(this.config.theme.textOverwrites)) {
122119
if (!this.config.theme.textOverwrites[key]) {
123120
delete this.config.theme.textOverwrites[key]
@@ -127,13 +124,7 @@ export default {
127124
this.saving = true
128125
try {
129126
await api.call('world.config.patch', {theme: this.config.theme})
130-
const themePayload = {
131-
colors: {...DEFAULT_COLORS, ...this.config.theme.colors},
132-
logo: {...DEFAULT_LOGO, ...this.config.theme.logo},
133-
streamOfflineImage: this.config.theme.streamOfflineImage ?? null,
134-
identicons: {...DEFAULT_IDENTICONS, ...this.config.theme.identicons}
135-
}
136-
applyThemeConfig(themePayload)
127+
this._applyThemePreview() // Re-use the helper method
137128
} catch (error) {
138129
console.error(error.apiError || error)
139130
this.error = error.apiError?.code || error.message || error.toString()

0 commit comments

Comments
 (0)