-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderer.js
40 lines (38 loc) · 1.46 KB
/
renderer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
document.addEventListener('DOMContentLoaded', () => {
document.getElementById('welcomeBtn').addEventListener('click', () => {
document.getElementById('welcomeMessage').innerText = 'Welcome to EduNexus!';
// Use the exposed getUsers function
window.api.getUsers()
.then(users => {
console.log(users);
// Display users or handle data as needed
})
.catch(err => console.error('Failed to fetch users:', err));
});
});
function fetchDataFromAPI() {
fetch('http://localhost:3000/api/messages') // Adjust the URL to your actual API endpoint
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
console.log(data);
// Example of processing and displaying data in the UI
displayMessages(data);
})
.catch(error => {
console.error('There has been a problem with your fetch operation:', error);
});
}
function displayMessages(messages) {
const messagesContainer = document.getElementById('messagesContainer');
messagesContainer.innerHTML = ''; // Clear previous messages
messages.forEach(message => {
const messageElement = document.createElement('div');
messageElement.innerText = message.content; // Assuming each message has a 'content' field
messagesContainer.appendChild(messageElement);
});
}