Compare commits
No commits in common. "6c46188d38590e12601f348b2f9aea82eae6252b" and "7c2a3329a7d16885da9bdb9c2ed0f831de23e636" have entirely different histories.
6c46188d38
...
7c2a3329a7
@ -1,32 +0,0 @@
|
|||||||
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<User> getUserInfo(
|
|
||||||
@AuthenticationPrincipal User player
|
|
||||||
) {
|
|
||||||
return ResponseEntity.ok(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -26,5 +26,6 @@
|
|||||||
|
|
||||||
.game-header a:hover:not(.active) {
|
.game-header a:hover:not(.active) {
|
||||||
color: cadetblue;
|
color: cadetblue;
|
||||||
box-shadow: 0 1.5px 0 0 currentColor;
|
|
||||||
|
/* box-shadow: 0 1.5px 0 0 currentColor; */
|
||||||
}
|
}
|
@ -3,7 +3,3 @@
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
tr.username {
|
|
||||||
background-color:aliceblue;
|
|
||||||
}
|
|
||||||
|
@ -20,7 +20,7 @@ export default function Leaderboard() {
|
|||||||
const tableRows = Object.keys(data.leaderboard).map(playerName => {
|
const tableRows = Object.keys(data.leaderboard).map(playerName => {
|
||||||
var rank = data.leaderboard[playerName];
|
var rank = data.leaderboard[playerName];
|
||||||
|
|
||||||
return <tr key={playerName} className={data.isCurrentUser(playerName) && 'username'}>
|
return <tr key={playerName}>
|
||||||
<td>{playerName}</td>
|
<td>{playerName}</td>
|
||||||
<td>{rank.gamesPlayed}</td>
|
<td>{rank.gamesPlayed}</td>
|
||||||
<td>{rank.gamesWon}</td>
|
<td>{rank.gamesWon}</td>
|
||||||
|
@ -11,7 +11,7 @@ import { useState, useCallback, useEffect, } from "react"
|
|||||||
|
|
||||||
export default function Poll(url, interval_sec, offlineMode) {
|
export default function Poll(url, interval_sec, offlineMode) {
|
||||||
const [dataCache, setDataCache] = useState(null)
|
const [dataCache, setDataCache] = useState(null)
|
||||||
const [fetching , setFetching ] = useState(false)
|
const [fetching, setFetching] = useState(false)
|
||||||
const [timeoutID, setTimeoutID] = useState(null)
|
const [timeoutID, setTimeoutID] = useState(null)
|
||||||
|
|
||||||
const fecthData = useCallback(() => {
|
const fecthData = useCallback(() => {
|
||||||
@ -35,7 +35,7 @@ export default function Poll(url, interval_sec, offlineMode) {
|
|||||||
clearTimeout(timeoutID) // cancel already scheduled fetch
|
clearTimeout(timeoutID) // cancel already scheduled fetch
|
||||||
setTimeoutID(null) // & stop interval fetching
|
setTimeoutID(null) // & stop interval fetching
|
||||||
}
|
}
|
||||||
else if (timeoutID === null && typeof interval_sec === 'number') {
|
else if (timeoutID === null) {
|
||||||
const timeoutID = setTimeout(fecthData, interval_sec * 1000)
|
const timeoutID = setTimeout(fecthData, interval_sec * 1000)
|
||||||
setTimeoutID(timeoutID)
|
setTimeoutID(timeoutID)
|
||||||
console.log("Fetch '" +url +"' scheduled in " +interval_sec +" sec")
|
console.log("Fetch '" +url +"' scheduled in " +interval_sec +" sec")
|
||||||
|
@ -14,7 +14,6 @@ export const AppDataProvider = ({ children }) => {
|
|||||||
|
|
||||||
const [games, gamesFetching ] = Poll('/api/gamestate' , 30, data.offlineMode)
|
const [games, gamesFetching ] = Poll('/api/gamestate' , 30, data.offlineMode)
|
||||||
const [leaderboard, leaderboardFetching ] = Poll('/api/leaderboard', 60, data.offlineMode)
|
const [leaderboard, leaderboardFetching ] = Poll('/api/leaderboard', 60, data.offlineMode)
|
||||||
const [user] = Poll('api/user') // once
|
|
||||||
|
|
||||||
data.games = games
|
data.games = games
|
||||||
data.gamesFetching = gamesFetching
|
data.gamesFetching = gamesFetching
|
||||||
@ -22,19 +21,9 @@ export const AppDataProvider = ({ children }) => {
|
|||||||
data.leaderboard = leaderboard
|
data.leaderboard = leaderboard
|
||||||
data.leaderboardFetching = leaderboardFetching
|
data.leaderboardFetching = leaderboardFetching
|
||||||
|
|
||||||
data.isCurrentUser = (otherUsername) => {
|
|
||||||
return user?.username && ciEquals(user.username, otherUsername) ? true : null
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AppData.Provider value={[data, dispatchData]}>
|
<AppData.Provider value={[data, dispatchData]}>
|
||||||
{children}
|
{children}
|
||||||
</AppData.Provider>
|
</AppData.Provider>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function ciEquals(a, b) {
|
|
||||||
return typeof a === 'string' && typeof b === 'string'
|
|
||||||
? a.localeCompare(b, undefined, { sensitivity: 'accent' }) === 0
|
|
||||||
: a === b;
|
|
||||||
}
|
|
@ -19,7 +19,5 @@ export const initialState = {
|
|||||||
leaderboard: null,
|
leaderboard: null,
|
||||||
leaderboardFetching: false,
|
leaderboardFetching: false,
|
||||||
|
|
||||||
isCurrentUser: () => false,
|
|
||||||
|
|
||||||
offlineMode: false
|
offlineMode: false
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user