Skip to content

Commit 6348e28

Browse files
committed
Use theme API in admin.
1 parent f554a41 commit 6348e28

File tree

3 files changed

+14
-18
lines changed

3 files changed

+14
-18
lines changed

admin/index.html

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,17 @@
7070
themes.length = 0;
7171

7272
let endpoint = `${getSiteApiBaseUrl(site.domain)}/api/config`;
73-
const res = await fetch(new URL(endpoint), {
74-
headers: { authorization: await getNostrAuthHeader(endpoint, 'GET') }
73+
let res = await fetch(new URL(endpoint), {
74+
headers: { authorization: await getNostrAuthHeader(endpoint, 'GET') }
7575
});
76-
let config = await res.json();
77-
for (t of config['available_themes']) {
78-
themes.push({theme: t, selected: t == config['theme']});
76+
let configResponse = await res.json();
77+
endpoint = `${getSiteApiBaseUrl(site.domain)}/api/themes`;
78+
res = await fetch(new URL(endpoint), {
79+
headers: { authorization: await getNostrAuthHeader(endpoint, 'GET') }
80+
});
81+
let themesResponse = await res.json();
82+
for (t of themesResponse['themes']) {
83+
themes.push({name: t.name, selected: t.name == configResponse['theme']});
7984
}
8085
}
8186

@@ -148,7 +153,7 @@ <h1 class="text-2xl text-center" x-text="site.domain"></h1>
148153
<div class="w-full mt-24">
149154
<select id="selectTheme">
150155
<template x-for="t in themes">
151-
<option x-bind:value="t.theme" x-text="t.theme" x-bind:selected="t.selected"></option>
156+
<option x-bind:value="t.name" x-text="t.name" x-bind:selected="t.selected"></option>
152157
</template>
153158
</select>
154159
</div>

docs/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ A `GET` to `/api/sites` can be used to get a list of all the sites belonging to
88

99
### `/api/config`
1010

11-
A `GET` to `/api/config` will return the list of available themes and the currently selected theme.
11+
A `GET` to `/api/config` will return the currently selected theme.
1212

1313
A `PUT` to `/api/config` can be used to change the site's theme.
1414

src/main.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -610,18 +610,9 @@ async fn handle_get_site_config(request: Request<State>) -> tide::Result<Respons
610610
}
611611
};
612612

613-
let themes: Vec<String> = request
614-
.state()
615-
.themes
616-
.read()
617-
.unwrap()
618-
.keys()
619-
.cloned()
620-
.collect();
621-
622613
Ok(Response::builder(StatusCode::Ok)
623614
.content_type(mime::JSON)
624-
.body(json!({"theme": site.config.theme, "available_themes": themes}).to_string())
615+
.body(json!({"theme": site.config.theme}).to_string())
625616
.build())
626617
}
627618

@@ -1522,7 +1513,7 @@ mod tests {
15221513
let mut res: Response = app.respond(req).await?;
15231514
assert_eq!(res.status(), StatusCode::Ok);
15241515
let body_json: serde_json::Value = res.body_json().await?;
1525-
assert_eq!(body_json, json!({"theme": "hyde", "available_themes": []}));
1516+
assert_eq!(body_json, json!({"theme": "hyde"}));
15261517

15271518
// Change the theme to an inexistant one
15281519
let mut req = with_nostr_auth_header(

0 commit comments

Comments
 (0)