@@ -64,6 +69,7 @@ export default class Body extends React.Component {
if (!Settings.has("tableJSON")) {
let tableJSON = await generate("C:\\Users\\Paoda\\Downloads", template);
+ console.log("Initialize: ", tableJSON)
this.setState({ table: tableJSON });
saveTable(tableJSON);
diff --git a/src/components/Body/Table.js b/src/components/Body/Table.js
index 74a1ae4..a7dc05d 100644
--- a/src/components/Body/Table.js
+++ b/src/components/Body/Table.js
@@ -10,6 +10,8 @@ import Settings from 'electron-settings';
var active = document.createElement("tr");
active.classList.toggle("active");
+const usedTableIDs = [];
+
const mp = new MusicPlayer();
var JSXcache;
@@ -228,15 +230,36 @@ export async function generate(path, template) {
}
const t2 = performance.now();
- console.log(
- "Time Taken (Table Data Creation): " +
- Math.floor(t2 - t1) / 1000 +
- "s"
- );
+ console.log(
+ "Time Taken (Table Data Creation): " +
+ Math.floor(t2 - t1) / 1000 +
+ "s"
+ );
- return new Promise((res, rej) => {
- res(table);
- });
+ // assign unique ID to Table.
+
+ table.id = createID(25);
+
+ return new Promise((res, rej) => {
+ res(table);
+ });
+ }
+
+ function createID(length) {
+ const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+ let id;
+
+ do {
+ id = "";
+ for (let i = 0; i < length; i++) id += chars[randInt(0, chars.length)];
+ } while(usedTableIDs.includes(id));
+
+ usedTableIDs.push(id);
+ return id;
+
+ function randInt(min, max) {
+ return ~~(Math.random() * (max - min) + min);
+ }
}
}
diff --git a/src/components/Modal/SettingsManager.js b/src/components/Modal/SettingsManager.js
index 6e4b389..55ab722 100644
--- a/src/components/Modal/SettingsManager.js
+++ b/src/components/Modal/SettingsManager.js
@@ -25,6 +25,7 @@ export default class SettingsManager extends Modal {
Settings
@@ -39,22 +40,25 @@ export default class SettingsManager extends Modal {
deleteTable() {
if (Settings.has("tableJSON")) Settings.delete("tableJSON");
- else console.warn("There was no Table Saved to Delete!");
+ else console.info("There was no Table Saved to Delete!");
- Emitter.emit("newTable", this.template)
+ const template = this.template;
+
+ template.id = "-1"; //Impossible ID.
+
+ Emitter.emit("newTable", this.template);
}
-
/**
* Regenerates a Table
* TODO: Make this a function w/ the one inside of Body.js
*/
async regenTable() {
if (Settings.has("tableJSON")) Settings.delete("tableJSON");
- else console.warn("there was no Table Saved to Delete!")
+ else console.info("There was no Table Saved to Delete!")
- let tableJSON = await generate("C:\\Users\\Paoda\\Downloads", this.template);
+ const tableJSON = await generate("C:\\Users\\Paoda\\Downloads", this.template);
Emitter.emit("newTable", tableJSON);