Skip to content

Commit bfdb55e

Browse files
committed
Use cards for theme selection.
1 parent 6348e28 commit bfdb55e

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

admin/index.html

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,12 @@
8080
});
8181
let themesResponse = await res.json();
8282
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']});
8484
}
85+
themes.sort((a, b) => a.name.localeCompare(b.name));
8586
}
8687

87-
async function saveConfig(site, theme) {
88+
async function saveConfig(site, themes, desiredThemeName) {
8889
let endpoint = `${getSiteApiBaseUrl(site.domain)}/api/config`;
8990
let response = await fetch(endpoint, {
9091
method: 'PUT',
@@ -94,13 +95,15 @@
9495
'Authorization': await getNostrAuthHeader(endpoint, 'PUT'),
9596
},
9697
body: JSON.stringify({
97-
theme: theme,
98+
theme: desiredThemeName,
9899
}),
99100
});
100101
if (response.ok) {
101-
alert("Theme changed!")
102+
for (let theme of themes) {
103+
theme.selected = theme.name === desiredThemeName;
104+
}
102105
} else {
103-
alert("Error changing theme!")
106+
alert("Error changing theme!");
104107
}
105108
}
106109
</script>
@@ -146,23 +149,26 @@
146149
</div>
147150
</template> <!-- /!site -->
148151
<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>
162169
</div>
163170
</div>
164171
</div>
165-
</div>
166172
</template> <!-- /site -->
167173
</div> <!-- /main -->
168174
</div>

0 commit comments

Comments
 (0)