From fb8da2b9894c897e26152db908998813b109bd5d Mon Sep 17 00:00:00 2001 From: Daithi Hearn Date: Sat, 20 May 2023 15:31:06 +0200 Subject: [PATCH 1/2] Fixing player ordering in StartNewGame --- package.json | 2 +- public/manifest.json | 2 +- src/components/StartNewGame/StartNewGame.tsx | 22 ++++++++++++-------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 64f20f2..423a647 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "frontend", - "version": "7.0.5", + "version": "7.0.6", "description": "React frontend for the Cards 110", "author": "Daithi Hearn", "license": "MIT", diff --git a/public/manifest.json b/public/manifest.json index ac73884..65a779c 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -1,7 +1,7 @@ { "short_name": "Cards 110", "name": "Cards 110", - "version": "7.0.5", + "version": "7.0.6", "icons": [ { "src": "./assets/favicon.png", diff --git a/src/components/StartNewGame/StartNewGame.tsx b/src/components/StartNewGame/StartNewGame.tsx index a02475c..1149107 100644 --- a/src/components/StartNewGame/StartNewGame.tsx +++ b/src/components/StartNewGame/StartNewGame.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useState } from "react" +import React, { useCallback, useMemo, useState } from "react" import GameService from "services/GameService" import { getPlayerProfiles } from "caches/PlayerProfilesSlice" @@ -40,6 +40,17 @@ const StartNewGame = () => { [], ) + const orderedPlayers = useMemo(() => { + if (!allPlayers || allPlayers.length < 1) return [] + console.log(JSON.stringify(allPlayers)) + // Sort by last lastAccess which is a string timestamp in the form 1970-01-01T00:00:00 + return [...allPlayers].sort((a, b) => { + const aDate = new Date(a.lastAccess) + const bDate = new Date(b.lastAccess) + return bDate.getTime() - aDate.getTime() + }) + }, [allPlayers]) + const togglePlayer = useCallback( (player: PlayerProfile) => { if (selectedPlayers.includes(player)) { @@ -150,7 +161,7 @@ const StartNewGame = () => { - {allPlayers.map(player => ( + {orderedPlayers.map(player => ( @@ -176,13 +187,6 @@ const StartNewGame = () => { src={player.picture} className="avatar-large" /> - - - {FormatName( - player.name, - )} - - From f8a74856dfe8218ad9e9c7cce6a48ea87748ae5b Mon Sep 17 00:00:00 2001 From: Daithi Hearn Date: Sat, 20 May 2023 15:31:41 +0200 Subject: [PATCH 2/2] Removing logging --- src/components/StartNewGame/StartNewGame.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/StartNewGame/StartNewGame.tsx b/src/components/StartNewGame/StartNewGame.tsx index 1149107..8df0d26 100644 --- a/src/components/StartNewGame/StartNewGame.tsx +++ b/src/components/StartNewGame/StartNewGame.tsx @@ -42,7 +42,6 @@ const StartNewGame = () => { const orderedPlayers = useMemo(() => { if (!allPlayers || allPlayers.length < 1) return [] - console.log(JSON.stringify(allPlayers)) // Sort by last lastAccess which is a string timestamp in the form 1970-01-01T00:00:00 return [...allPlayers].sort((a, b) => { const aDate = new Date(a.lastAccess)