Refactored designer

pull/7024/head
Cagatay Civici 2024-12-28 12:43:15 +03:00
parent 686eba4ea1
commit b8ef0922f5
3 changed files with 79 additions and 57 deletions

View File

@ -65,6 +65,9 @@ export default {
this.deferredTabs = true; this.deferredTabs = true;
}, },
async downloadTheme(theme) { async downloadTheme(theme) {
if (!this.$appState.designer.licenseKey) {
this.$toast.add({ severity: 'error', summary: 'Not Available', detail: 'A license is required to download', life: 3000 });
} else {
try { try {
const response = await $fetch(this.designerApiBase + '/theme/download/' + this.$appState.designer.licenseKey + '/' + theme.t_key, { const response = await $fetch(this.designerApiBase + '/theme/download/' + this.$appState.designer.licenseKey + '/' + theme.t_key, {
responseType: 'blob' responseType: 'blob'
@ -84,9 +87,9 @@ export default {
window.URL.revokeObjectURL(blobUrl); window.URL.revokeObjectURL(blobUrl);
} }
} catch (err) { } catch (err) {
console.log(err);
this.$toast.add({ severity: 'error', summary: 'An Error Occurred', detail: 'Failed to download file', life: 3000 }); this.$toast.add({ severity: 'error', summary: 'An Error Occurred', detail: 'Failed to download file', life: 3000 });
} }
}
}, },
async updateTheme(theme) { async updateTheme(theme) {
const { error } = await $fetch(this.designerApiBase + '/theme/update', { const { error } = await $fetch(this.designerApiBase + '/theme/update', {
@ -104,7 +107,10 @@ export default {
} }
}, },
applyTheme(theme) { applyTheme(theme) {
if (this.$appState.designer.licenseKey) {
this.updateTheme(theme); this.updateTheme(theme);
}
updatePreset(theme.preset); updatePreset(theme.preset);
EventBus.emit('theme-palette-change'); EventBus.emit('theme-palette-change');
}, },

View File

@ -96,6 +96,7 @@ export default {
document.body.classList.remove('material'); document.body.classList.remove('material');
} }
if (this.$appState.designer.licenseKey) {
const { data, error } = await $fetch(this.designerApiBase + '/theme/create', { const { data, error } = await $fetch(this.designerApiBase + '/theme/create', {
method: 'POST', method: 'POST',
body: { body: {
@ -114,8 +115,13 @@ export default {
} else { } else {
this.loadThemeEditor(data.t_key, newPreset); this.loadThemeEditor(data.t_key, newPreset);
} }
} else {
this.loadThemeEditor('trial', newPreset);
}
}, },
async createThemeFromFigma() { async createThemeFromFigma() {
if (this.figmaData) {
if (this.$appState.designer.licenseKey) {
const { data, error } = await $fetch(this.designerApiBase + '/theme/figma', { const { data, error } = await $fetch(this.designerApiBase + '/theme/figma', {
method: 'POST', method: 'POST',
body: { body: {
@ -134,6 +140,12 @@ export default {
} else { } else {
this.loadThemeEditor(data.t_key, newPreset); this.loadThemeEditor(data.t_key, newPreset);
} }
} else {
this.$toast.add({ severity: 'error', summary: 'An error occured', detail: 'A valid license required', life: 3000 });
}
} else {
this.$toast.add({ severity: 'error', summary: 'An error occured', detail: 'File is required', life: 3000 });
}
}, },
onFileSelect(event) { onFileSelect(event) {
const file = event.files[0]; const file = event.files[0];

View File

@ -1,16 +1,17 @@
<template> <template>
<div class="text-lg font-semibold mb-2">License Key</div> <div class="text-lg font-semibold mb-2">License Key</div>
<span class="block text-muted-color leading-6 mb-4" <span class="block text-muted-color leading-6 mb-4"
>A license can be purchased from PrimeStore, if you do not have a license key, you are still able to use the Designer in free tier. <NuxtLink to="/designer" class="doc-link">Learn more</NuxtLink> about the Theme Designer.</span >A license can be purchased from PrimeStore, if you do not have a license key, you are still able to experience the Designer with limited features. <NuxtLink to="/designer" class="doc-link">Learn more</NuxtLink> about the Theme
Designer.</span
> >
<form @submit.prevent class="flex gap-4"> <form @submit.prevent class="flex gap-4">
<input v-model="$appState.designer.licenseKey" type="password" autocomplete="off" class="px-3 py-2 rounded-md border border-surface-300 dark:border-surface-700 flex-1" /> <input v-model="licenseKey" type="password" autocomplete="off" class="px-3 py-2 rounded-md border border-surface-300 dark:border-surface-700 flex-1" />
<button <button
type="button" type="button"
@click="activate(false)" @click="activate(false)"
icon="pi pi-download" icon="pi pi-download"
:disabled="!$appState.designer.licenseKey" :disabled="!licenseKey"
class="px-3 py-2 bg-zinc-950 hover:bg-zinc-800 text-white dark:bg-white dark:hover:bg-gray-100 dark:text-black rounded-md font-medium cursor-pointer transition-colors duration-200 focus:outline focus:outline-offset-2 focus:outline-zinc-950 focus:dark:outline-white disabled:opacity-60" class="px-3 py-2 bg-zinc-950 disabled:hover:bg-zinc-950 hover:bg-zinc-800 text-white dark:bg-white dark:hover:bg-gray-100 dark:disabled:hover:bg-white dark:text-black rounded-md font-medium cursor-pointer disabled:cursor-auto transition-colors duration-200 focus:outline focus:outline-offset-2 focus:outline-zinc-950 focus:dark:outline-white disabled:opacity-60"
> >
Activate Activate
</button> </button>
@ -71,6 +72,7 @@ export default {
inject: ['designerService'], inject: ['designerService'],
data() { data() {
return { return {
licenseKey: null,
loading: false, loading: false,
currentTheme: null, currentTheme: null,
confirmDialogVisible: false, confirmDialogVisible: false,
@ -115,7 +117,7 @@ export default {
const keyValue = localStorage.getItem(this.$appState.designer.localStoreKey); const keyValue = localStorage.getItem(this.$appState.designer.localStoreKey);
if (keyValue) { if (keyValue) {
this.$appState.designer.licenseKey = keyValue; this.licenseKey = keyValue;
this.activate(true); this.activate(true);
} }
} else { } else {
@ -124,13 +126,14 @@ export default {
}, },
methods: { methods: {
async activate(silent) { async activate(silent) {
this.loading = true; const { data, error } = await $fetch(this.designerApiBase + '/license/verify/' + this.licenseKey);
const { data, error } = await $fetch(this.designerApiBase + '/license/verify/' + this.$appState.designer.licenseKey);
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 {
if (data.valid) { if (data.valid) {
this.$appState.designer.licenseKey = this.licenseKey;
if (!silent) { if (!silent) {
this.$toast.add({ severity: 'success', summary: 'Success', detail: 'License is activated.', life: 3000 }); this.$toast.add({ severity: 'success', summary: 'Success', detail: 'License is activated.', life: 3000 });
} }
@ -142,13 +145,12 @@ export default {
this.$appState.designer.themes = []; this.$appState.designer.themes = [];
} }
} }
this.loading = false;
}, },
openNewTheme() { openNewTheme() {
this.$appState.designer.activeView = 'create_theme'; this.$appState.designer.activeView = 'create_theme';
}, },
async loadThemes() { async loadThemes() {
this.loading = true;
const { data, error } = await $fetch(this.designerApiBase + '/theme/list/' + this.$appState.designer.licenseKey); const { data, error } = await $fetch(this.designerApiBase + '/theme/list/' + this.$appState.designer.licenseKey);
if (error) { if (error) {
@ -156,6 +158,8 @@ export default {
} else { } else {
this.$appState.designer.themes = data; this.$appState.designer.themes = data;
} }
this.loading = false;
}, },
async loadTheme(theme) { async loadTheme(theme) {
const { data, error } = await $fetch(this.designerApiBase + '/theme/load/' + this.$appState.designer.licenseKey + '/' + theme.t_key); const { data, error } = await $fetch(this.designerApiBase + '/theme/load/' + this.$appState.designer.licenseKey + '/' + theme.t_key);