|
101 | 101 | themes.sort((a, b) => a.name.localeCompare(b.name)); |
102 | 102 | } |
103 | 103 |
|
104 | | - async function saveConfig(themes, desiredThemeId) { |
| 104 | + async function getExtraConfig(themeId) { |
| 105 | + let endpoint = `${getApiBaseUrl()}/api/themes/${themeId}`; |
| 106 | + let res = await fetch(new URL(endpoint)); |
| 107 | + return (await res.json())['extra_config']; |
| 108 | + } |
| 109 | + |
| 110 | + async function saveConfig(themes, desiredThemeId, themeExtraConfig) { |
105 | 111 | let endpoint = `${getApiBaseUrl()}/api/config`; |
106 | 112 | let headers = { |
107 | 113 | ...{ |
|
114 | 120 | let response = await fetch(endpoint, { |
115 | 121 | method: 'PUT', |
116 | 122 | headers: headers, |
117 | | - body: JSON.stringify({ theme: desiredThemeId }), |
| 123 | + body: JSON.stringify({ theme: desiredThemeId, extra_config: themeExtraConfig }), |
118 | 124 | }); |
119 | 125 | if (response.ok) { |
120 | 126 | for (let theme of themes) { |
@@ -174,21 +180,36 @@ <h2 class="card-title" x-text="site.domain"></h2> |
174 | 180 | </div> |
175 | 181 | </template> |
176 | 182 | <template x-if="host"> |
177 | | - <div class="w-full mx-auto" x-data="{themes: []}" x-init="await getConfig(themes);"> |
| 183 | + <div class="w-full mx-auto" x-data="{themes: [], theme: null, themeExtraConfig: ''}" |
| 184 | + x-init="await getConfig(themes);"> |
178 | 185 | <div> |
| 186 | + <dialog id="themeExtraConfigModal" class="modal"> |
| 187 | + <div class="modal-box"> |
| 188 | + <form method="dialog"> |
| 189 | + <button class="btn btn-sm btn-circle btn-ghost absolute right-2 top-2">✕</button> |
| 190 | + <h3 class="text-lg font-bold">Configure theme</h3> |
| 191 | + <p class="py-4"> |
| 192 | + <textarea class="textarea textarea-bordered w-full h-80" x-model="themeExtraConfig"> |
| 193 | + </textarea> |
| 194 | + </p> |
| 195 | + <button class="btn btn-primary" |
| 196 | + x-on:click="await saveConfig(themes, theme.id, themeExtraConfig);">Ok</button> |
| 197 | + </form> |
| 198 | + </div> |
| 199 | + </dialog> |
179 | 200 | <div class="mt-12"> |
180 | 201 | <div class="w-full mt-24"> |
181 | 202 | <div class="flex flex-wrap gap-4"> |
182 | | - <template x-for="theme in themes"> |
183 | | - <div :class="theme.selected ? 'bg-primary text-primary-content' : 'bg-neutral text-neutral-content'" |
| 203 | + <template x-for="t in themes"> |
| 204 | + <div :class="t.selected ? 'bg-primary text-primary-content' : 'bg-neutral text-neutral-content'" |
184 | 205 | class="card w-96 card-xs shadow-sm"> |
185 | 206 | <div class="card-body"> |
186 | | - <h2 class="card-title" x-text="theme.name"></h2> |
187 | | - <p x-text="theme.description"></p> |
188 | | - <p>License: <span x-text="theme.license"></span></p> |
| 207 | + <h2 class="card-title" x-text="t.name"></h2> |
| 208 | + <p x-text="t.description"></p> |
| 209 | + <p>License: <span x-text="t.license"></span></p> |
189 | 210 | <div class="justify-end card-actions"> |
190 | | - <button :class="{'btn-primary': !theme.selected}" class="btn" |
191 | | - x-on:click="await saveConfig(themes, theme.id);">Select</button> |
| 211 | + <button :class="{'btn-primary': !t.selected}" class="btn" |
| 212 | + x-on:click="theme = t; themeExtraConfig = await getExtraConfig(t.id); themeExtraConfigModal.showModal();">Select</button> |
192 | 213 | </div> |
193 | 214 | </div> |
194 | 215 | </div> |
|
0 commit comments