diff --git a/src/AppMenu.tsx b/src/AppMenu.tsx index 8592342..f633844 100644 --- a/src/AppMenu.tsx +++ b/src/AppMenu.tsx @@ -1,6 +1,8 @@ import React from "react"; import { Link } from "react-router-dom"; +import useCurrentUser from "./hooks/useCurrentUser"; + import playerSvg from "./assets/icons/player.svg"; import skull from "./assets/icons/skull.svg"; import sword from "./assets/icons/sword.svg"; @@ -12,30 +14,34 @@ interface GamesHQRouteOption { name: string; icon: string; to: string; + necessaryCapability: string; } export const AppMenu = ({ children }: { children: JSX.Element }) => { + const { currentUser } = useCurrentUser(); + const inspectRoutes = [ - { name: "Inspect Arena", to: "/inspect/arena", icon: playerSvg }, + { name: "Inspect Arena", to: "/inspect/arena", icon: playerSvg, necessaryCapability: "THE_ARENA_READ" }, ]; const databaseRoutes = [ /* { name: "Players", to: "/players", icon: playerSvg }, */ - { name: "Weapons", to: "/weapons", icon: sword }, + { name: "Weapons", to: "/weapons", icon: sword, necessaryCapability: "WEAPONS_READ" }, /* { name: "Traits", to: "/traits", icon: trait }, */ ]; const towerRoutes = [ - { name: "Tower Game", to: "/tower/status", icon: playerSvg }, - { name: "Enemies", to: "/enemies", icon: skull }, - { name: "Floors", to: "/floors", icon: floor }, + { name: "Tower Game", to: "/tower/status", icon: playerSvg, necessaryCapability: "THE_TOWER_READ" }, + { name: "Enemies", to: "/enemies", icon: skull, necessaryCapability: "ENEMY_READ" }, + { name: "Floors", to: "/floors", icon: floor, necessaryCapability: "THE_TOWER_READ" }, ]; - const arenaRoutes = [{ name: "Zones", to: "/zones", icon: zone }]; + const arenaRoutes = [{ name: "Zones", to: "/zones", icon: zone, necessaryCapability: "ZONE_READ" }]; - const gameDevRoutes = [{ name: "Games", to: "/games", icon: games }]; + const gameDevRoutes = [{ name: "Games", to: "/games", icon: games, necessaryCapability: "MY_GAME_READ" }]; const generateRouteList = (route: GamesHQRouteOption[]) => { - return route.map((route, i) => ( + + return route.map((route, i) => ( route.necessaryCapability && currentUser?.capabilities.includes(route.necessaryCapability) && )); }; + return (
- - MY GAMES - - - {generateRouteList(gameDevRoutes)} - - - INSPECT LIVE GAMES - - - {generateRouteList(inspectRoutes)} + {currentUser?.capabilities.includes('MY_GAME_READ') && ( + <> + + MY GAMES + + + {generateRouteList(gameDevRoutes)} + + + INSPECT LIVE GAMES + + + {generateRouteList(inspectRoutes)} + - - GENERAL - + )} + + {currentUser?.capabilities.includes('WEAPONS_READ') && ( + <> + + GENERAL + - {generateRouteList(databaseRoutes)} + {generateRouteList(databaseRoutes)} + + )} THE TOWER {generateRouteList(towerRoutes)} - - THE ARENA - - {generateRouteList(arenaRoutes)} + {currentUser?.capabilities.includes('THE_ARENA_READ') && ( + <> + + THE ARENA + + + {generateRouteList(arenaRoutes)} + + )}
{children}
diff --git a/src/pages/InspectArenaPage.tsx b/src/pages/InspectArenaPage.tsx index 94d365b..b7b8870 100644 --- a/src/pages/InspectArenaPage.tsx +++ b/src/pages/InspectArenaPage.tsx @@ -19,7 +19,7 @@ const InspectArenaPage = function InspectArenaPage(props: any) { const arenaPlayers = get( arenaGame, - "_arena._players", + "_arenaPlayers", [] ) as IArenaPlayer[]; diff --git a/src/types.d.ts b/src/types.d.ts index 3535b63..bab72b9 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -167,6 +167,7 @@ interface IGame { endedAt: string; _gameTypeId: number; _arena: IArenaGame; + _arenaPlayers: [IArenaPlayer]; } interface IGameWithTower extends IGame { @@ -181,7 +182,7 @@ interface IArenaGame { currentRingDeactivation: number; inactiveZonePenaltyPower: number; _gameId: number; - _players: [IArenaPlayer]; + } interface IArenaRoundAction { @@ -280,6 +281,7 @@ interface GamesAPIUSer { profilePictureUrl: string; role: number; isAdmin: boolean; + capabilities: string[]; } interface GamesAPISession {