moved createID to MiscMethods.js

began work on playlist management.
This commit is contained in:
Paoda
2019-02-20 14:21:43 -06:00
parent 5fbc1a0ea1
commit 8d8dd3dfe6
6 changed files with 82 additions and 35 deletions

View File

@@ -29,12 +29,14 @@ export default class Body extends React.Component {
this.initialize();
}
shouldComponentUpdate(nextProps, state) {
if (this.state.table.id) return this.state.table.id !== state.table.id;
if (this.state.table) return this.state.table.id !== state.table.id;
else return false;
// On Feb 13 2019 Had problem wehre this.state.table.id was undefined.
// Unable to replicate issue, but it's a serous one. Probably should fix this yeah?
}
render() {
console.log("Render TableID: " + this.state.table.id);
if (this.state.table) console.log("Render TableID: " + this.state.table.id);
else console.warn("No Table Present");
return (
<div className="wrapper">
<div id="searchBar">

View File

@@ -1,7 +1,7 @@
import React from "react";
import Song from "../../melodii/Song";
import MusicPlayer from "../../melodii/MusicPlayer";
import Misc from "../MiscMethods";
import Misc, { createID } from "../MiscMethods";
import Emitter from "../../melodii/Events";
import Filepath from "../../melodii/Filepath";
import Settings from 'electron-settings';
@@ -10,8 +10,6 @@ import Settings from 'electron-settings';
var active = document.createElement("tr");
active.classList.toggle("active");
const usedTableIDs = [];
const mp = new MusicPlayer();
var JSXcache;
@@ -152,7 +150,7 @@ export default class Table extends React.Component {
let filepath = e.currentTarget.dataset.filepath;
let song = new Song(filepath);
mp.load(song);
mp.loadSong(song);
mp.play();
song = await Song.getMetadata(song);
@@ -173,7 +171,7 @@ export default class Table extends React.Component {
let filepath = e.currentTarget.dataset.filepath;
let song = new Song(filepath);
mp.load(song);
mp.loadSong(song);
mp.play();
song = await Song.getMetadata(song);
@@ -243,29 +241,6 @@ export async function generate(path, template) {
res(table);
});
}
/**
* Creates a unique ID that is not UUID compliant.
* - used to distinguish table objects from one another.
* @param {Number} length
* @return {String}
*/
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);
}
}
}
/**

View File

@@ -1,5 +1,7 @@
import Song from "../melodii/Song";
const usedTableIDs = [];
/**
* - Every Method in this file must be Static and _probably_ Synchronous
* - The Methods contained in this class must only be methods that don't really fit anywhere else
@@ -322,3 +324,26 @@ export default class MiscMethods {
return [stringA, stringB];
}
}
/**
* Creates a unique ID that is not UUID compliant.
* - used to distinguish table objects from one another.
* @param {Number} length
* @return {String}
*/
export 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);
}
}