diff --git a/backend/src/main/java/djmil/cordacheckers/api/UserController.java b/backend/src/main/java/djmil/cordacheckers/api/UserController.java new file mode 100644 index 0000000..66de2ce --- /dev/null +++ b/backend/src/main/java/djmil/cordacheckers/api/UserController.java @@ -0,0 +1,32 @@ +package djmil.cordacheckers.api; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import djmil.cordacheckers.cordaclient.CordaClient; +import djmil.cordacheckers.user.HoldingIdentityResolver; +import djmil.cordacheckers.user.User; + + +@RestController +@RequestMapping("api/user") +public class UserController { + + @Autowired + CordaClient cordaClient; + + @Autowired + HoldingIdentityResolver holdingIdentityResolver; + + @GetMapping + public ResponseEntity getUserInfo( + @AuthenticationPrincipal User player + ) { + return ResponseEntity.ok(player); + } + +} diff --git a/webapp/src/components/Leaderboard/index.css b/webapp/src/components/Leaderboard/index.css index cf658c6..89964b1 100644 --- a/webapp/src/components/Leaderboard/index.css +++ b/webapp/src/components/Leaderboard/index.css @@ -3,3 +3,7 @@ justify-content: center; align-items: center; } + +tr.username { + background-color:aliceblue; +} diff --git a/webapp/src/components/Leaderboard/index.jsx b/webapp/src/components/Leaderboard/index.jsx index fe0eaf3..7d893fb 100644 --- a/webapp/src/components/Leaderboard/index.jsx +++ b/webapp/src/components/Leaderboard/index.jsx @@ -20,7 +20,7 @@ export default function Leaderboard() { const tableRows = Object.keys(data.leaderboard).map(playerName => { var rank = data.leaderboard[playerName]; - return + return {playerName} {rank.gamesPlayed} {rank.gamesWon} diff --git a/webapp/src/context/data/Poll.js b/webapp/src/context/data/Poll.js index 935cf7a..9d6d209 100644 --- a/webapp/src/context/data/Poll.js +++ b/webapp/src/context/data/Poll.js @@ -11,7 +11,7 @@ import { useState, useCallback, useEffect, } from "react" export default function Poll(url, interval_sec, offlineMode) { const [dataCache, setDataCache] = useState(null) - const [fetching, setFetching] = useState(false) + const [fetching , setFetching ] = useState(false) const [timeoutID, setTimeoutID] = useState(null) const fecthData = useCallback(() => { @@ -35,7 +35,7 @@ export default function Poll(url, interval_sec, offlineMode) { clearTimeout(timeoutID) // cancel already scheduled fetch setTimeoutID(null) // & stop interval fetching } - else if (timeoutID === null) { + else if (timeoutID === null && typeof interval_sec === 'number') { const timeoutID = setTimeout(fecthData, interval_sec * 1000) setTimeoutID(timeoutID) console.log("Fetch '" +url +"' scheduled in " +interval_sec +" sec") diff --git a/webapp/src/context/data/index.jsx b/webapp/src/context/data/index.jsx index 6cef507..b2579b0 100644 --- a/webapp/src/context/data/index.jsx +++ b/webapp/src/context/data/index.jsx @@ -14,12 +14,17 @@ export const AppDataProvider = ({ children }) => { const [games, gamesFetching ] = Poll('/api/gamestate' , 30, data.offlineMode) const [leaderboard, leaderboardFetching ] = Poll('/api/leaderboard', 60, data.offlineMode) + const [user] = Poll('api/user') // once data.games = games data.gamesFetching = gamesFetching data.leaderboard = leaderboard data.leaderboardFetching = leaderboardFetching + + data.isCurrentUser = (otherUsername) => { + return user?.username && ciEquals(user.username, otherUsername) ? true : null + } return ( @@ -27,3 +32,9 @@ export const AppDataProvider = ({ children }) => { ) } + +function ciEquals(a, b) { + return typeof a === 'string' && typeof b === 'string' + ? a.localeCompare(b, undefined, { sensitivity: 'accent' }) === 0 + : a === b; +} \ No newline at end of file diff --git a/webapp/src/context/data/reducer.js b/webapp/src/context/data/reducer.js index 7b608bc..770fe57 100644 --- a/webapp/src/context/data/reducer.js +++ b/webapp/src/context/data/reducer.js @@ -19,5 +19,7 @@ export const initialState = { leaderboard: null, leaderboardFetching: false, + isCurrentUser: () => false, + offlineMode: false }