Skip to content

Commit

Permalink
Merge pull request #231 from Tvick22/main
Browse files Browse the repository at this point in the history
fix too many fetches & update messages every second
  • Loading branch information
XavierTho authored Nov 20, 2024
2 parents 12666b0 + 5bb12f7 commit bd21f72
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions assets/js/revvit/carChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ async function sendMessage() {
}

// 3. Return the data
updateMessageDisplay();
return response.json();
// 4. If we had an error anywhere in the try (stuff above), we will log an error.
} catch (error) {
Expand All @@ -72,9 +73,6 @@ async function getMessages() {
throw new Error(`Failed to get Messages: ${response.status}`);
}

getMessages().then((messages) => {
displayMessages(messages);
});
// 3. Return the data
return response.json();
// 4. If we had an error anywhere in the try (stuff above), we will log an error.
Expand All @@ -97,8 +95,14 @@ function displayMessages(messages) {
});
}

getMessages().then((messages) => {
displayMessages(messages);
});
updateMessageDisplay();

function updateMessageDisplay() {
getMessages().then((messages) => {
displayMessages(messages);
});
}

sendBtn.addEventListener("click", sendMessage);

setInterval(updateMessageDisplay, 1000); // Update the message display every second

0 comments on commit bd21f72

Please # to comment.