|
80 | 80 | });
|
81 | 81 | let themesResponse = await res.json();
|
82 | 82 | for (t of themesResponse['themes']) {
|
83 |
| - themes.push({name: t.name, selected: t.name == configResponse['theme']}); |
| 83 | + themes.push({name: t.name, license: t.license, description: t.description, selected: t.name == configResponse['theme']}); |
84 | 84 | }
|
| 85 | + themes.sort((a, b) => a.name.localeCompare(b.name)); |
85 | 86 | }
|
86 | 87 |
|
87 |
| - async function saveConfig(site, theme) { |
| 88 | + async function saveConfig(site, themes, desiredThemeName) { |
88 | 89 | let endpoint = `${getSiteApiBaseUrl(site.domain)}/api/config`;
|
89 | 90 | let response = await fetch(endpoint, {
|
90 | 91 | method: 'PUT',
|
|
94 | 95 | 'Authorization': await getNostrAuthHeader(endpoint, 'PUT'),
|
95 | 96 | },
|
96 | 97 | body: JSON.stringify({
|
97 |
| - theme: theme, |
| 98 | + theme: desiredThemeName, |
98 | 99 | }),
|
99 | 100 | });
|
100 | 101 | if (response.ok) {
|
101 |
| - alert("Theme changed!") |
| 102 | + for (let theme of themes) { |
| 103 | + theme.selected = theme.name === desiredThemeName; |
| 104 | + } |
102 | 105 | } else {
|
103 |
| - alert("Error changing theme!") |
| 106 | + alert("Error changing theme!"); |
104 | 107 | }
|
105 | 108 | }
|
106 | 109 | </script>
|
|
146 | 149 | </div>
|
147 | 150 | </template> <!-- /!site -->
|
148 | 151 | <template x-if="site">
|
149 |
| - <div> |
150 |
| - <h1 class="text-2xl text-center" x-text="site.domain"></h1> |
151 |
| - <div class="flex justify-center items-center mt-12"> |
152 |
| - <div> |
153 |
| - <div class="w-full mt-24"> |
154 |
| - <select id="selectTheme"> |
155 |
| - <template x-for="t in themes"> |
156 |
| - <option x-bind:value="t.name" x-text="t.name" x-bind:selected="t.selected"></option> |
157 |
| - </template> |
158 |
| - </select> |
159 |
| - </div> |
160 |
| - <div class="w-full mt-24"> |
161 |
| - <button x-on:click="await saveConfig(site, document.getElementById('selectTheme').value);" class="btn btn-primary mt-1">Save</button> |
| 152 | + |
| 153 | + <div class="mt-12"> |
| 154 | + <h1 class="text-2xl text-center" x-text="site.domain"></h1> |
| 155 | + <div class="w-full mt-24"> |
| 156 | + <div class="grid gap-4 justify-between grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4"> |
| 157 | + <template x-for="theme in themes"> |
| 158 | + <div :class="theme.selected ? 'bg-primary text-primary-content' : 'bg-neutral text-neutral-content'" class="card w-96 card-xs shadow-sm"> |
| 159 | + <div class="card-body"> |
| 160 | + <h2 class="card-title" x-text="theme.name"></h2> |
| 161 | + <p x-text="theme.description"></p> |
| 162 | + <p>License: <span x-text="theme.license"></span></p> |
| 163 | + <div class="justify-end card-actions"> |
| 164 | + <button :class="{'btn-primary': !theme.selected}" class="btn" x-on:click="let changed = await saveConfig(site, themes, theme.name); if (changed) { }">Select</button> |
| 165 | + </div> |
| 166 | + </div> |
| 167 | + </div> |
| 168 | + </template> |
162 | 169 | </div>
|
163 | 170 | </div>
|
164 | 171 | </div>
|
165 |
| - </div> |
166 | 172 | </template> <!-- /site -->
|
167 | 173 | </div> <!-- /main -->
|
168 | 174 | </div>
|
|
0 commit comments