implement route for channel switching and use json for received data

This commit is contained in:
Infi
2024-08-25 17:06:00 +02:00
parent 1d7153fc50
commit d0802a8d7a
3 changed files with 74 additions and 15 deletions
+29 -2
View File
@@ -38,8 +38,20 @@ function updateChannelHint(label) {
}
document.getElementById('channel-select').addEventListener('change', (event) => {
// TODO: send new channel to "backend"
// ws.send(...);
(async () => {
const rawResponse = await fetch('/channel', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({channel: event.target.value})
});
const content = await rawResponse.json();
// TODO use the response
console.log(content);
})();
});
function updateChannelOptions(channels) {
@@ -122,6 +134,21 @@ document.querySelector('#input > form').addEventListener('submit', (event) => {
}
});
(async () => {
const rawResponse = await fetch('/send', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({message: message})
});
const content = await rawResponse.json();
// TODO use the response
console.log(content);
})();
chatInput.value = '';
});