From 31b01d56f0f7812ea0fbb45e5924ce4eb0de7383 Mon Sep 17 00:00:00 2001 From: Vika Date: Sun, 9 May 2021 16:22:50 +0300 Subject: Fixed Micropub client channels and sending payload --- src/index.html | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'src/index.html') diff --git a/src/index.html b/src/index.html index 15ccfc0..1fc2a96 100644 --- a/src/index.html +++ b/src/index.html @@ -66,7 +66,6 @@ } async function query_channels() { - return ["main", "likes", "bookmarks"] const response = await fetch(form.action + "?q=config", { headers: { "Authorization": `Bearer ${form.elements.access_token.value}` @@ -86,10 +85,10 @@ const template = document.getElementById("channel_selector").content.cloneNode(true) const input = template.querySelector("input") const label = template.querySelector("label") - input.id = `channel_selector_option_${channel}` - input.value = channel + input.id = `channel_selector_option_${channel.uid}` + input.value = channel.uid label.for = input.id - label.innerHTML = `${channel}` + label.innerHTML = `${channel.name}` channel_list.appendChild(template) }) @@ -98,13 +97,24 @@ form.onsubmit = async (event) => { event.preventDefault() console.log(JSON.stringify(construct_body(form))) - return - const response = await fetch(form.action, { - headers: { - "Authorization": `Bearer ${form.elements.access_token.value}` - }, - body: construct_body(form) - }) + try { + const response = await fetch(form.action, { + method: form.method, + headers: { + "Authorization": `Bearer ${form.elements.access_token.value}`, + "Content-Type": "application/json" + }, + body: JSON.stringify(construct_body(form)) + }) + if (response.status != 201 || response.status != 202) { + console.error(await response.json()); + } + if (response.headers.get("Location")) { + window.location.href = response.headers.get("Location"); + } + } catch (e) { + console.error(e) + } } -- cgit 1.4.1