Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added async/await to fix firefox issue + other things #16

Merged
merged 7 commits into from
Jan 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ services:
- "33060:3306"
environment:
TZ: "America/New York"
MYSQL_ROOT_PASSWORD: "root"
MYSQL_ROOT_PASSWORD: "root"
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "headsup",
"version": "1.1.1",
"version": "1.1.2",
"description": "RPIA's digital whiteboard system",
"main": "server.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions public/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
</form>
</div>
</div>
</div>
</body>
<script type="text/javascript" src="public/js/admin.js"></script>
</html>
50 changes: 27 additions & 23 deletions public/js/admin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
async function getNotes() {
const response = await fetch('/notes');
checkResult(response);
const notes = (await response.json()).data;
let html = '';
if (notes.length !== 0) {
Expand All @@ -25,35 +26,23 @@ async function getNotes() {
}

// eslint-disable-next-line
function createNote() {
async function createNote() {
const note = document.querySelector('#add-a-note').value;
fetch('/note/create', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
redirect: 'follow',
body: JSON.stringify({ note })
});
window.location.reload();
if (note === '') return;
await postToServer('/note/create', {note: note});
document.querySelector('#add-a-note').value = '';
await getNotes();
}

// eslint-disable-next-line
async function deleteNote(note_id) {
await fetch('/note/delete', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
redirect: 'follow',
body: JSON.stringify({ note: note_id })
});
document.querySelector('#notes').innerHTML = '';
getNotes();
await postToServer('/note/delete', {note: note_id});
await getNotes();
}

async function generateCategoryDropdown() {
const response = await fetch('/public/js/call-categories.json');
checkResult(response);
const categories = await response.json();
for (const category of categories) {
const option = document.createElement('option');
Expand All @@ -71,15 +60,30 @@ async function addCall() {
const category = document.querySelector('#category').value;
const response = document.querySelector('#response').value;
const call_data = { prid, cc, driver, category, response };
fetch('/call/create', {
await postToServer('/call/create',call_data);
document.querySelector('#prid').value = '';
document.querySelector('#tic').value = '';
document.querySelector('#driver').value = '';
document.querySelector('#category').value = '';
document.querySelector('#response').value = '';
}

async function postToServer(endpoint, body) {
const response = await fetch(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
redirect: 'follow',
body: JSON.stringify(call_data)
body: JSON.stringify(body)
});
window.location.reload();
checkResult(response);
}

function checkResult(response) {
if (!response.ok) {
throw response.statusText;
}
}

getNotes();
Expand Down