-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
79 lines (72 loc) · 2.74 KB
/
index.html
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<html>
<head>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<br />
<h1>AWS Notes</h1>
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="Name" aria-label="Name" id="name" />
</div>
<h3>Write A Note</h3>
<div class="input-group mb-3">
<textarea type="text" class="form-control" placeholder="Note" aria-label="Note" id="note"></textarea>
</div>
<input class="btn btn-primary" type="button" value="Save Note" onclick="submitNote()">
<input class="btn btn-primary" type="button" value="Get Notes" onclick="getNotes()">
<div id="noteData"></div>
</div>
<script>
// Put your API URL here!!
const API_URL = "https://YOUR_URL.amazonaws.com/"
function submitNote() {
const name = document.getElementById('name').value;
const note = document.getElementById('note').value;
if (!name || !note) return alert("Please fill out name and note!");
const data = {
name: name,
data: note
};
fetch(`${API_URL}/notes`, {
method: 'POST',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json'
}
}).then(response => {
if (response.ok) {
alert("Note saved!");
} else {
alert("Failed to save note!");
}
}).catch(error => {
console.error(error);
alert("Failed to save note!");
});
}
function getNotes() {
document.getElementById("noteData").innerHTML = "";
const name = document.getElementById('name').value;
if (!name) return alert("Please fill out name!");
fetch(`${API_URL}/notes/${name}`).then(async response => {
if (response.ok) {
const data = await response.json();
let html = "<br /><ul>"
for (let item of data) {
html += `<li>${item.data.S}</li>`;
}
html += "</ul>";
document.getElementById('noteData').innerHTML = html;
} else {
alert("Failed to get notes!");
}
}).catch(error => {
console.error(error);
alert("Failed to get notes!");
});
}
</script>
</body>
</html>