Compare commits

...

2 Commits

Author SHA1 Message Date
6c46188d38 front: isCurrentUser() 2023-10-26 12:26:00 +02:00
8a0401ec59 front: unify path indication css 2023-10-26 09:30:37 +02:00
7 changed files with 53 additions and 5 deletions

View File

@ -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<User> getUserInfo(
@AuthenticationPrincipal User player
) {
return ResponseEntity.ok(player);
}
}

View File

@ -26,6 +26,5 @@
.game-header a:hover:not(.active) {
color: cadetblue;
/* box-shadow: 0 1.5px 0 0 currentColor; */
box-shadow: 0 1.5px 0 0 currentColor;
}

View File

@ -3,3 +3,7 @@
justify-content: center;
align-items: center;
}
tr.username {
background-color:aliceblue;
}

View File

@ -20,7 +20,7 @@ export default function Leaderboard() {
const tableRows = Object.keys(data.leaderboard).map(playerName => {
var rank = data.leaderboard[playerName];
return <tr key={playerName}>
return <tr key={playerName} className={data.isCurrentUser(playerName) && 'username'}>
<td>{playerName}</td>
<td>{rank.gamesPlayed}</td>
<td>{rank.gamesWon}</td>

View File

@ -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")

View File

@ -14,6 +14,7 @@ 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
@ -21,9 +22,19 @@ export const AppDataProvider = ({ children }) => {
data.leaderboard = leaderboard
data.leaderboardFetching = leaderboardFetching
data.isCurrentUser = (otherUsername) => {
return user?.username && ciEquals(user.username, otherUsername) ? true : null
}
return (
<AppData.Provider value={[data, dispatchData]}>
{children}
</AppData.Provider>
)
}
function ciEquals(a, b) {
return typeof a === 'string' && typeof b === 'string'
? a.localeCompare(b, undefined, { sensitivity: 'accent' }) === 0
: a === b;
}

View File

@ -19,5 +19,7 @@ export const initialState = {
leaderboard: null,
leaderboardFetching: false,
isCurrentUser: () => false,
offlineMode: false
}