diff --git a/.gitignore b/.gitignore index 67045665..d43eab5c 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,4 @@ dist # TernJS port file .tern-port +backend/package-lock.json diff --git a/backend/.eslintrc b/backend/.eslintrc index c80e33a6..838f5469 100644 --- a/backend/.eslintrc +++ b/backend/.eslintrc @@ -3,6 +3,7 @@ "rules": { "no-console": "off", "implicit-arrow-linebreak": "off", - "no-nested-ternary": "off" + "no-nested-ternary": "off", + "linebreak-style": "off" } } diff --git a/backend/src/controllers/game.controller.js b/backend/src/controllers/game.controller.js index b08c1c45..9e832727 100644 --- a/backend/src/controllers/game.controller.js +++ b/backend/src/controllers/game.controller.js @@ -190,7 +190,7 @@ class GameController { await centrifugoController.publishToSideBar( this.organisation_id, - user_id, + gameDBData.data.owner.user_id, sidebar_update_payload_owner, ); } diff --git a/backend/src/controllers/info.controller.js b/backend/src/controllers/info.controller.js index e1553d70..5d16a055 100644 --- a/backend/src/controllers/info.controller.js +++ b/backend/src/controllers/info.controller.js @@ -144,7 +144,7 @@ class InformationController { this.organisation_id = req.body.organisation_id; this.user_id = req.body.user_id; - const url = `https://api.zuri.chat/organizations/${this.Authorizationorganisation_id}/plugins`; + const url = `https://api.zuri.chat/organizations/${this.organisation_id}/plugins`; await axios.post( url, diff --git a/backend/src/utils/gameWorker.js b/backend/src/utils/gameWorker.js index 3da1a6ac..61fd3317 100644 --- a/backend/src/utils/gameWorker.js +++ b/backend/src/utils/gameWorker.js @@ -2,6 +2,8 @@ const { parentPort } = require('worker_threads'); const globalTime = require('global-time'); const DatabaseConnection = require('../db/database.helper'); +const centrifugoController = require('../controllers/centrifugo.controller'); +const InformationController = require('../controllers/info.controller'); const orgId = process.argv[2]; const gameId = process.argv[3]; @@ -20,6 +22,30 @@ const timer = setInterval(async () => { if (time - game.data.modifiedAt > 5 * 60 * 1000) { await gameRepo.delete(game.data._id, game.data); parentPort.postMessage(`${orgId}:${gameId}`); + + // collect sidebar info for game user + const sidebarUpdatePayloadOwner = await InformationController.sideBarInfo( + orgId, + game.data.owner.user_id, + ); + // publishing collected sidebar info of both owner and opponent + await centrifugoController.publishToSideBar( + orgId, + game.data.owner.user_id, + sidebarUpdatePayloadOwner, + ); + + if (game.data.opponent != null) { + const sidebarUpdatePayloadOpponent = await InformationController.sideBarInfo( + orgId, + game.data.opponent.user_id, + ); + await centrifugoController.publishToSideBar( + orgId, + game.data.opponent.user_id, + sidebarUpdatePayloadOpponent, + ); + } } }, 5 * 60 * 1000); diff --git a/client/src/index.ejs b/client/src/index.ejs index 7508991c..31aa3283 100644 --- a/client/src/index.ejs +++ b/client/src/index.ejs @@ -40,8 +40,8 @@ "react-dom": "//cdn.jsdelivr.net/npm/react-dom@16.13.1/umd/react-dom.production.min.js", "@zuri/root-config": "//chess.zuri.chat/zuri-root-config.js", "@zuri/zuri-plugin-chessboard": "//chess.zuri.chat/zuri-zuri-plugin-chessboard.js", - "@zuri/utilities": "//zuri.chat/zuri-utilities.js", - "@zuri/plugin-header": "//zuri.chat/zuri-plugin-header.js" + "@zuri/utilities": "//staging.zuri.chat/zuri-utilities.js", + "@zuri/plugin-header": "//staging.zuri.chat/zuri-plugin-header.js" } } @@ -57,8 +57,8 @@ "@single-spa/welcome": "//unpkg.com/single-spa-welcome/dist/single-spa-welcome.js", "@zuri/root-config": "//chess.zuri.chat/zuri-root-config.js", "@zuri/zuri-plugin-chessboard": "//chess.zuri.chat/zuri-zuri-plugin-chessboard.js", - "@zuri/utilities": "//zuri.chat/zuri-utilities.js", - "@zuri/plugin-header": "//zuri.chat/zuri-plugin-header.js" + "@zuri/utilities": "//staging.zuri.chat/zuri-utilities.js", + "@zuri/plugin-header": "//staging.zuri.chat/zuri-plugin-header.js" } } diff --git a/frontend/setup.txt b/frontend/setup.txt index 7af6d76c..09392e58 100644 --- a/frontend/setup.txt +++ b/frontend/setup.txt @@ -5,7 +5,7 @@ react-dom https://cdn.jsdelivr.net/npm/react-dom@16.13.1/umd/react-dom.production.min.js @zuri/utilities -https://zuri.chat/zuri-utilities.js +https://staging.zuri.chat/zuri-utilities.js @zuri/plugin-header -https://zuri.chat/zuri-plugin-header.js \ No newline at end of file +https://staging.zuri.chat/zuri-plugin-header.js \ No newline at end of file diff --git a/frontend/src/components/ChessBoardBorder/index.jsx b/frontend/src/components/ChessBoardBorder/index.jsx index e4f4069e..c7ae497e 100644 --- a/frontend/src/components/ChessBoardBorder/index.jsx +++ b/frontend/src/components/ChessBoardBorder/index.jsx @@ -1,15 +1,19 @@ import React from 'react'; +// import { keyframes } from 'styled-components'; // Import CSS for this page // import "./chessboardborder.css"; // Import style for this page import { AlphabetSection, NumberSection } from './styles'; +let count = 0; +const getID = () => count++; + const Alphabets = () => (
{[...'abcdefgh'].map((item) => ( -
+
{item.toUpperCase()}
))} @@ -21,7 +25,7 @@ const Numbers = () => (
{[...'87654321'].map((item) => ( -
+
{item}
))} diff --git a/frontend/src/components/SpectatorSideBar/index.jsx b/frontend/src/components/SpectatorSideBar/index.jsx index a621fd17..d9cc58bb 100644 --- a/frontend/src/components/SpectatorSideBar/index.jsx +++ b/frontend/src/components/SpectatorSideBar/index.jsx @@ -33,6 +33,9 @@ import close from '../../assets/comment/close.svg'; // Import Adapters import { sendComment } from '../../adapters/comments'; +// Import Utilities +import mapTimeStamp from './mapTimeStamp'; + // (lekandev) Commented it out // import style-components // import { @@ -141,7 +144,7 @@ const SpectatorSideBar = ({ type, gameData }) => { avi

{user_name}

-

{timestamp}

+

{mapTimeStamp(timestamp)}

diff --git a/frontend/src/components/SpectatorSideBar/mapTimeStamp.js b/frontend/src/components/SpectatorSideBar/mapTimeStamp.js new file mode 100644 index 00000000..603bacd1 --- /dev/null +++ b/frontend/src/components/SpectatorSideBar/mapTimeStamp.js @@ -0,0 +1,33 @@ +export default (timeStamp) => { + let mappedTimeStamp = ''; + const [date, time, suffix] = timeStamp.split(' '); + const [month, day, year] = date.split('/'); + const [hr, min, sec] = time.split(':'); + const currentDate = new Date( + new Date().toLocaleString('en-US', { + timeZone: 'UTC', + }), + ); + const commentDate = suffix === 'PM' + ? new Date(year.replace(',', ''), Number(month) - 1, day, Number(hr) + 12, min, sec) + : new Date(year.replace(',', ''), Number(month) - 1, day, hr, min, sec); + const diff = currentDate - commentDate; + const diffObj = { + second: diff / 1000, + minute: diff / 1000 / 60, + hour: diff / 1000 / 60 / 60, + day: diff / 1000 / 60 / 60 / 24, + week: diff / 1000 / 60 / 60 / 24 / 7, + month: diff / 1000 / 60 / 60 / 24 / 7 / 4, + year: diff / 1000 / 60 / 60 / 24 / 7 / 4 / 12, + }; + Object.keys(diffObj).forEach((key) => { + const value = Math.floor(diffObj[key]); + if (value === 1) { + mappedTimeStamp = `${value} ${key} ago`; + } else if (value > 1) { + mappedTimeStamp = `${value} ${key}s ago`; + } + }); + return mappedTimeStamp; +};