Skip to content

Commit

Permalink
fix: Refresh after load
Browse files Browse the repository at this point in the history
  • Loading branch information
bdelbosc committed Aug 13, 2020
1 parent 81d19aa commit b0091c3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
2 changes: 2 additions & 0 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@
}
function evaluationEdit() {
aroma = aroma;
currentTab = 1;
document.getElementById("evaluation").hidden = false;
document.getElementById("user").hidden = true;
document.getElementById("beer").hidden = true;
Expand Down
40 changes: 24 additions & 16 deletions src/Beer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,29 @@
}
function onChooseFile(event) {
if (typeof window.FileReader !== 'function')
throw ("The file API isn't supported on this browser.");
let input = event.target;
if (!input)
throw ("The browser does not properly implement the event object");
if (!input.files)
throw ("This browser does not support the `files` property of the file input.");
if (!input.files[0])
return undefined;
let file = input.files[0];
let fr = new FileReader();
fr.onload = function (e) {
parsePDF(e.target.result, uploadData);
};
fr.readAsText(file);
try {
if (typeof window.FileReader !== 'function')
throw ("The file API isn't supported on this browser.");
let input = event.target;
if (!input)
throw ("The browser does not properly implement the event object");
if (!input.files)
throw ("This browser does not support the `files` property of the file input.");
if (!input.files[0])
return undefined;
let file = input.files[0];
let fr = new FileReader();
fr.onload = function (e) {
try {
parsePDF(e.target.result, uploadData);
} catch (err) {
alert(err);
}
};
fr.readAsText(file);
} catch (err) {
alert(err.message);
}
}
</script>
Expand Down Expand Up @@ -119,7 +127,7 @@
</button>
</div>
<div class="upload">
<label for="upload">You can also upload an existing Scoresheet</label>
<label for="upload">You can also load an existing PDF Scoresheet</label>
<input id='upload' type='file' accept="application/pdf" on:change={() => onChooseFile(event)}/>
</div>

5 changes: 2 additions & 3 deletions src/js/PdfRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ function getLabel(options, id, inappropriate = false) {

function parsePDF(text, updateData) {
if (! text.startsWith('%PDF-1.3')) {
console.log("Not a PDF file abort");
return;
throw ("Invalid file, a beer-feedback PDF Scoresheet is expected");
}
var lines = text.split('\n');
for (var i = 0; i < lines.length; i++) {
Expand All @@ -162,7 +161,7 @@ function parsePDF(text, updateData) {
return;
}
}
console.log("JSON Keyword not found in PDF file!");
throw ("Invalid PDF Scoresheet file, unable to find the JSON data!");
}

export {PdfRenderer, getLabel, getScore, getScoreDescription, parsePDF};
Expand Down

0 comments on commit b0091c3

Please sign in to comment.