Display an error for bad token values, and update theme afte migration

pull/6454/merge
Cagatay Civici 2025-01-13 10:52:11 +03:00
parent 06ae612f3b
commit 8b8a5e2f45
4 changed files with 27 additions and 17 deletions

View File

@ -34,7 +34,7 @@
<script> <script>
import EventBus from '@/app/AppEventBus'; import EventBus from '@/app/AppEventBus';
import { $dt, updatePreset } from '@primevue/themes'; import { $dt, updatePreset, usePreset } from '@primevue/themes';
export default { export default {
setup() { setup() {
@ -50,6 +50,7 @@ export default {
refreshACTokens: this.refreshACTokens, refreshACTokens: this.refreshACTokens,
saveTheme: this.saveTheme, saveTheme: this.saveTheme,
downloadTheme: this.downloadTheme, downloadTheme: this.downloadTheme,
activateTheme: this.activateTheme,
applyTheme: this.applyTheme, applyTheme: this.applyTheme,
applyFont: this.applyFont, applyFont: this.applyFont,
replaceColorPalette: this.replaceColorPalette replaceColorPalette: this.replaceColorPalette
@ -194,6 +195,20 @@ export default {
}, },
toggleDarkMode() { toggleDarkMode() {
EventBus.emit('dark-mode-toggle', { dark: !this.$appState.darkTheme }); EventBus.emit('dark-mode-toggle', { dark: !this.$appState.darkTheme });
},
activateTheme(data) {
this.$appState.designer.theme = {
key: data.t_key,
name: data.t_name,
preset: JSON.parse(data.t_preset),
config: JSON.parse(data.t_config)
};
usePreset(this.$appState.designer.theme.preset);
this.applyFont(this.$appState.designer.theme.config.fontFamily);
document.documentElement.style.fontSize = this.$appState.designer.theme.config.fontSize;
this.replaceColorPalette();
this.refreshACTokens();
} }
}, },
computed: { computed: {

View File

@ -60,8 +60,6 @@
</template> </template>
<script> <script>
import { usePreset } from '@primevue/themes';
export default { export default {
setup() { setup() {
const runtimeConfig = useRuntimeConfig(); const runtimeConfig = useRuntimeConfig();
@ -186,18 +184,7 @@ export default {
if (error) { if (error) {
this.$toast.add({ severity: 'error', summary: 'An Error Occurred', detail: error.message, life: 3000 }); this.$toast.add({ severity: 'error', summary: 'An Error Occurred', detail: error.message, life: 3000 });
} else { } else {
this.$appState.designer.theme = { this.designerService.activateTheme(data);
key: data.t_key,
name: data.t_name,
preset: JSON.parse(data.t_preset),
config: JSON.parse(data.t_config)
};
usePreset(this.$appState.designer.theme.preset);
this.designerService.applyFont(this.$appState.designer.theme.config.fontFamily);
document.documentElement.style.fontSize = this.$appState.designer.theme.config.fontSize;
this.designerService.replaceColorPalette();
this.designerService.refreshACTokens();
this.$appState.designer.activeView = 'editor'; this.$appState.designer.activeView = 'editor';
} }
}, },

View File

@ -18,7 +18,10 @@
:showEmptyMessage="false" :showEmptyMessage="false"
:pt="{ :pt="{
pcInputText: { pcInputText: {
root: ['border border-surface-300 text-zinc-950 dark:text-white dark:border-surface-600 rounded-lg py-2 px-2 w-full text-xs', { 'pr-6': type === 'color' }] root: [
'border text-zinc-950 dark:text-white rounded-lg py-2 px-2 w-full text-xs',
{ 'pr-6': type === 'color', 'border-red-500 dark:border-red-400 bg-red-50 dark:bg-red-500/30': invalid, 'border-surface-300 dark:border-surface-600': !invalid }
]
}, },
overlay: 'border border-surface-200 dark:border-surface-700 bg-surface-0 dark:bg-surface-950 shadow-2 rounded-md', overlay: 'border border-surface-200 dark:border-surface-700 bg-surface-0 dark:bg-surface-950 shadow-2 rounded-md',
listContainer: 'max-h-40 overflow-auto', listContainer: 'max-h-40 overflow-auto',
@ -219,6 +222,9 @@ export default {
}, },
inputId() { inputId() {
return this.id + '_input'; return this.id + '_input';
},
invalid() {
return this.modelValue == null || this.modelValue.trim().length === 0 || this.modelValue.startsWith(this.componentKey);
} }
} }
}; };

View File

@ -137,7 +137,7 @@ export default {
}); });
}, },
async migrate() { async migrate() {
const { error } = await $fetch(this.designerApiBase + '/theme/migrate/execute/' + this.$appState.designer.theme.key, { const { data, error } = await $fetch(this.designerApiBase + '/theme/migrate/execute/' + this.$appState.designer.theme.key, {
method: 'PATCH', method: 'PATCH',
headers: { headers: {
Authorization: `Bearer ${this.$appState.designer.ticket}`, Authorization: `Bearer ${this.$appState.designer.ticket}`,
@ -150,6 +150,8 @@ export default {
} else { } else {
this.status = 'updated'; this.status = 'updated';
this.missingTokens = []; this.missingTokens = [];
this.designerService.activateTheme(data);
} }
} }
} }