From 067132b92b3c84240900d8152dd113e7a1781b57 Mon Sep 17 00:00:00 2001 From: Ayo Date: Thu, 2 Apr 2020 22:04:32 +0800 Subject: [PATCH] update url in readme; transfer unused method to separate file --- README.md | 2 +- src/modules/leader-board/leader-board.js | 39 ---------------------- src/modules/leader-board/timestamp-fix.js | 40 +++++++++++++++++++++++ 3 files changed, 41 insertions(+), 40 deletions(-) create mode 100644 src/modules/leader-board/timestamp-fix.js diff --git a/README.md b/README.md index d47525c..0acf8f0 100644 --- a/README.md +++ b/README.md @@ -12,4 +12,4 @@ To start the dev server, first run `npm run watch:dev` then in another terminal, ## Live Demo -The current live site is here: (https://mnswpr.fullhacker.com) \ No newline at end of file +The current live site is here: (https://mnswpr.com) \ No newline at end of file diff --git a/src/modules/leader-board/leader-board.js b/src/modules/leader-board/leader-board.js index 44be8d5..6760ced 100644 --- a/src/modules/leader-board/leader-board.js +++ b/src/modules/leader-board/leader-board.js @@ -12,7 +12,6 @@ const db = dbService.store; const user = new UserService(); let previousLevel; - export class LeaderBoardService { constructor(leaders, all, configuration) { this.leaders = db.collection(leaders); @@ -27,44 +26,6 @@ export class LeaderBoardService { .catch(err => console.error(err)); } - updateTimeStampsLeaders() { - const levels = ['beginner', 'intermediate', 'expert']; - - levels.forEach(level => { - const collection = this.leaders.doc(level).collection('games'); - collection.get() - .then(res => { - const levelArray = res.docs.map(doc => ({id: doc.id, ...doc.data()})) - // console.log(level+": ", levelArray); - - levelArray.forEach(leaderGame => { - // const leaderGame = levelArray[0]; - const leaderTime = leaderGame.time; - const browser = leaderGame.browserId; - this.all.doc(browser).collection('games') - .get().then(games => { - const allGames = games.docs.map(doc => ({id: doc.id, games: {...doc.data()}})); - console.log(level + '...........' + browser); - allGames.forEach(day => { - const keys = Object.keys(day.games); - const winningKeys = keys.filter(key => day.games[key].status === 'win'); - winningKeys.forEach(key => { - const game = day.games[key]; - const dateString = [day.id, key].join(' ').replace(/_/g, ' '); - const newGame = {time_stamp: new Date(dateString), ...leaderGame}; - if (game.time === leaderTime) { - console.log('updated', newGame); - // collection.doc(leaderGame.id).get().then(res => console.log(res.data())); - collection.doc(leaderGame.id).set(newGame); - } - }) - }); - }); - }) - }); - }) - } - update(level, displayElement, title) { if (level !== previousLevel) { loadingService.addLoading(displayElement); diff --git a/src/modules/leader-board/timestamp-fix.js b/src/modules/leader-board/timestamp-fix.js new file mode 100644 index 0000000..9176235 --- /dev/null +++ b/src/modules/leader-board/timestamp-fix.js @@ -0,0 +1,40 @@ + + + + updateTimeStampsLeaders() { + const levels = ['beginner', 'intermediate', 'expert']; + + levels.forEach(level => { + const collection = this.leaders.doc(level).collection('games'); + collection.get() + .then(res => { + const levelArray = res.docs.map(doc => ({id: doc.id, ...doc.data()})) + // console.log(level+": ", levelArray); + + levelArray.forEach(leaderGame => { + // const leaderGame = levelArray[0]; + const leaderTime = leaderGame.time; + const browser = leaderGame.browserId; + this.all.doc(browser).collection('games') + .get().then(games => { + const allGames = games.docs.map(doc => ({id: doc.id, games: {...doc.data()}})); + console.log(level + '...........' + browser); + allGames.forEach(day => { + const keys = Object.keys(day.games); + const winningKeys = keys.filter(key => day.games[key].status === 'win'); + winningKeys.forEach(key => { + const game = day.games[key]; + const dateString = [day.id, key].join(' ').replace(/_/g, ' '); + const newGame = {time_stamp: new Date(dateString), ...leaderGame}; + if (game.time === leaderTime) { + console.log('updated', newGame); + // collection.doc(leaderGame.id).get().then(res => console.log(res.data())); + collection.doc(leaderGame.id).set(newGame); + } + }) + }); + }); + }) + }); + }) + } \ No newline at end of file