Skip to content

Commit

Permalink
Added async/await to fix firefox issue + other things (#16)
Browse files Browse the repository at this point in the history
* Added async/await to fix firefox issue

* Bump Version

* Removed random F

* Made skeleton post fetch function to fix duplicate code.

* Adds checkResult to verify status received is ok on fetch;
Renamed postServer to postToServer;
Prevent notes from being empty;
Removed window reload upon adding note/call;
Added form reset on adding a note/call;
Added refresh of notes on adding a call;
Added await to getNotes in deleteCall();
Added </div> that was missing in the admin.html

Currently the reset of the addCall causes the validator to run (this occurs even with reloading the page). This will need to be looked into for FireFox.

* Change version to align with e04222f
  • Loading branch information
zapdos26 authored and lramos15 committed Jan 18, 2020
1 parent e04222f commit 210f310
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 26 deletions.
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

0 comments on commit 210f310

Please sign in to comment.