Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: cognitive-engineering-lab/rqst-async
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: bf3156c6622f6b5f4665dc2cbb39ea553c8c87fd
Choose a base ref
..
head repository: cognitive-engineering-lab/rqst-async
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: f4561fc89187df716aba769ad386abb029321b2e
Choose a head ref
Showing with 14 additions and 11 deletions.
  1. +14 −11 crates/server/index.html
25 changes: 14 additions & 11 deletions crates/server/index.html
Original file line number Diff line number Diff line change
@@ -37,17 +37,20 @@ <h1>ChatABC</h1>
let spinnerEl = document.getElementById("spinner");

async function fetchChat(chat) {
let promise = fetch("/chat", {
method: "post",
headers: {"Content-Type": "application/json"},
body: JSON.stringify(chat)
});
spinnerEl.classList.add("active");

let response = await promise;
spinnerEl.classList.remove("active");

return await response.json();
textEl.setAttribute("disabled", "");
try {
let response = await fetch("/chat", {
method: "post",
headers: {"Content-Type": "application/json"},
body: JSON.stringify(chat)
});
if (!response.ok) throw new Error(response.statusText);
return await response.json();
} finally {
spinnerEl.classList.remove("active");
textEl.removeAttribute("disabled");
}
}

function updateChat(newChat) {
@@ -62,7 +65,7 @@ <h1>ChatABC</h1>
event.preventDefault();
chat.messages.push(textEl.value);
textEl.value = "";
fetchChat(chat).then(updateChat);
fetchChat(chat).then(updateChat);
}

function main() {