-
Notifications
You must be signed in to change notification settings - Fork 0
/
data-display.js
54 lines (51 loc) · 1.87 KB
/
data-display.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Function to fetch data from Google Sheets
function fetchData() {
fetch('https://script.google.com/macros/s/AKfycbzY44-trkDJK7VCkY89m6jETLqnW0fRCtBUVMXXlTm1zDS9IjsCV4gC6Sb0u6I9WqXX/exec')
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.catch(error => {
console.error('Error fetching data:', error);
// Display an error message using SweetAlert2
Swal.fire({
icon: 'error',
title: 'Connection Failure !',
text: 'You are not online. Please try again later.'
});
});
}
// Check if username is already stored in local storage
const storedUsername = localStorage.getItem('username');
if (!storedUsername) {
// If username is not stored, prompt user to input their name
promptForUsername();
} else {
// If username is stored, use it to send messages
sendMessage(storedUsername);
}
// Function to prompt user for username
function promptForUsername() {
Swal.fire({
title: 'Enter your name',
input: 'text',
inputAttributes: {
required: 'required'
},
showCancelButton: false,
confirmButtonText: 'Submit',
allowOutsideClick: false,
allowEscapeKey: false,
allowEnterKey: true
}).then((result) => {
if (result.isConfirmed) {
// Save username to local storage
localStorage.setItem('username', result.value);
// Send message with username
sendMessage(result.value);
}
});
console.log('Username prompt displayed.'); // Log when username prompt is displayed
}