diff options
Diffstat (limited to 'frontend')
-rw-r--r-- | frontend/adminpanel.ts | 28 | ||||
-rw-r--r-- | frontend/helper.ts | 8 | ||||
-rw-r--r-- | frontend/pwmodal.ts | 14 | ||||
-rw-r--r-- | frontend/style.sass | 5 |
4 files changed, 45 insertions, 10 deletions
diff --git a/frontend/adminpanel.ts b/frontend/adminpanel.ts new file mode 100644 index 0000000..aef7a31 --- /dev/null +++ b/frontend/adminpanel.ts @@ -0,0 +1,28 @@ +import { e } from "./helper.ts" + +let user: string | undefined = undefined +let pw: string | undefined = undefined + +interface PendingBang { + bang: string, + name: string, + url: string, + email: string | undefined, +} + +export async function tryLoadAdminPanel(user_: string, pw_: string) { + user = user_ + pw = pw_ + + const r = await fetch("/pendingBangs", { + headers: { + Accept: "application/json", + Authorization: "Basic " + btoa(`${user}:${pw}`), + } + }) + if (!r.ok) + throw (await r.json()).message + + const pending = await r.json() as PendingBang[] + console.log(pending) +} diff --git a/frontend/helper.ts b/frontend/helper.ts index 879d322..827a204 100644 --- a/frontend/helper.ts +++ b/frontend/helper.ts @@ -11,14 +11,14 @@ interface Opts<E> { href?: string, method?: string, placeholder?: string, - onclick?: (e: E) => void, - onchange?: (e: E) => void, + onclick?: (e: Event) => void, + onchange?: (e: Event) => void, } function apply_opts<E extends HTMLElement>(e: E, o: Opts<E>) { if (o.id) e.id = o.id - if (o.onclick) e.onclick = () => o.onclick!(e) - if (o.onchange) e.onchange = () => o.onchange!(e) + if (o.onclick) e.onclick = ev => o.onclick!(ev) + if (o.onchange) e.onchange = ev => o.onchange!(ev) // TODO can we do this properly? if (o.for) (e as unknown as HTMLLabelElement).htmlFor = o.for if (o.type && (e instanceof HTMLInputElement || e instanceof HTMLLinkElement)) e.type = o.type diff --git a/frontend/pwmodal.ts b/frontend/pwmodal.ts index 3d783c6..594db49 100644 --- a/frontend/pwmodal.ts +++ b/frontend/pwmodal.ts @@ -1,15 +1,16 @@ import { e } from "./helper.ts" - -export let username: string | undefined = undefined; -export let password: string | undefined = undefined; +import { tryLoadAdminPanel } from "./adminpanel.ts" export function pw_modal() { const inp_name = e("input", {type: "text", placeholder: "Username"}) const inp_pw = e("input", {type: "password", placeholder: "Password"}) + const error_msg = e("span", {class: "error-msg"}, "") const login_btn = e("button", { - onclick: () => { - username = inp_name.value - password = inp_pw.value + onclick: ev => { + ev.preventDefault() + tryLoadAdminPanel(inp_name.value, inp_pw.value).catch(err => { + error_msg.textContent = err + }) } }, "Login") @@ -18,6 +19,7 @@ export function pw_modal() { inp_name, inp_pw, login_btn, + error_msg, ) ) } diff --git a/frontend/style.sass b/frontend/style.sass index c0a7a5f..5828f41 100644 --- a/frontend/style.sass +++ b/frontend/style.sass @@ -149,3 +149,8 @@ a transition: color 0.2s &:hover color: $ac-light + +span.error-msg + margin-left: 1em + color: #ffe600 + font-size: 0.8em |