aboutsummaryrefslogtreecommitdiff
path: root/index.js
diff options
context:
space:
mode:
authorKaran Jayachandra <karan.jayachandra@nxp.com>2025-11-11 16:23:12 +0100
committerKaran Jayachandra <karan.jayachandra@nxp.com>2025-11-11 16:23:12 +0100
commit5dcf65616f82cb9b652f6913c93e26ff50983fdf (patch)
treed5e04b77772b5845d4bd3106ad968322d41739a9 /index.js
parentdd0c6a458ef5229a5fddf0e7cae25fb3a5d495f7 (diff)
Data load added
Diffstat (limited to 'index.js')
-rw-r--r--index.js18
1 files changed, 13 insertions, 5 deletions
diff --git a/index.js b/index.js
index 98236a4..8b146a8 100644
--- a/index.js
+++ b/index.js
@@ -1,22 +1,30 @@
import { Round } from "./game.mjs";
import { generateCourts } from "./court.mjs";
-import { generatePlayers } from "./player.mjs";
+import { csvToPlayers, generatePlayers } from "./player.mjs";
import { addToggleBehaviour } from "./utils.mjs";
// Court handling
let courts = generateCourts();
addToggleBehaviour(courts, "court_");
+
// Regulars handling
let regulars = generatePlayers();
addToggleBehaviour(regulars, "regular_");
-const fileInput = document.querySelector("#file-js input[type=file]");
+const fileInput = document.querySelector("#player-load input[type=file]");
if (fileInput !== null) {
fileInput.onchange = () => {
if (fileInput.files.length > 0) {
- const fileName = document.querySelector("#file-js .file-name");
- fileName.textContent = fileInput.files[0].name;
- console.log(fileInput.files[0]);
+ const file = fileInput.files[0];
+ if (file) {
+ const reader = new FileReader();
+ reader.onload = function(e) {
+ const content = e.target.result;
+ regulars = csvToPlayers(content);
+ addToggleBehaviour(regulars, "regular_");
+ };
+ reader.readAsText(file);
+ }
}
}
};