Skip to content

Commit 205e7fe

Browse files
authored
Merge pull request #18 from x-team/dev
Merging dev into main
2 parents e29c3a4 + 67a359c commit 205e7fe

File tree

3 files changed

+52
-29
lines changed

3 files changed

+52
-29
lines changed

Diff for: src/AppMenu.tsx

+48-27
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React from "react";
22
import { Link } from "react-router-dom";
33

4+
import useCurrentUser from "./hooks/useCurrentUser";
5+
46
import playerSvg from "./assets/icons/player.svg";
57
import skull from "./assets/icons/skull.svg";
68
import sword from "./assets/icons/sword.svg";
@@ -12,30 +14,34 @@ interface GamesHQRouteOption {
1214
name: string;
1315
icon: string;
1416
to: string;
17+
necessaryCapability: string;
1518
}
1619
export const AppMenu = ({ children }: { children: JSX.Element }) => {
20+
const { currentUser } = useCurrentUser();
21+
1722
const inspectRoutes = [
18-
{ name: "Inspect Arena", to: "/inspect/arena", icon: playerSvg },
23+
{ name: "Inspect Arena", to: "/inspect/arena", icon: playerSvg, necessaryCapability: "THE_ARENA_READ" },
1924
];
2025

2126
const databaseRoutes = [
2227
/* { name: "Players", to: "/players", icon: playerSvg }, */
23-
{ name: "Weapons", to: "/weapons", icon: sword },
28+
{ name: "Weapons", to: "/weapons", icon: sword, necessaryCapability: "WEAPONS_READ" },
2429
/* { name: "Traits", to: "/traits", icon: trait }, */
2530
];
2631

2732
const towerRoutes = [
28-
{ name: "Tower Game", to: "/tower/status", icon: playerSvg },
29-
{ name: "Enemies", to: "/enemies", icon: skull },
30-
{ name: "Floors", to: "/floors", icon: floor },
33+
{ name: "Tower Game", to: "/tower/status", icon: playerSvg, necessaryCapability: "THE_TOWER_READ" },
34+
{ name: "Enemies", to: "/enemies", icon: skull, necessaryCapability: "ENEMY_READ" },
35+
{ name: "Floors", to: "/floors", icon: floor, necessaryCapability: "THE_TOWER_READ" },
3136
];
3237

33-
const arenaRoutes = [{ name: "Zones", to: "/zones", icon: zone }];
38+
const arenaRoutes = [{ name: "Zones", to: "/zones", icon: zone, necessaryCapability: "ZONE_READ" }];
3439

35-
const gameDevRoutes = [{ name: "Games", to: "/games", icon: games }];
40+
const gameDevRoutes = [{ name: "Games", to: "/games", icon: games, necessaryCapability: "MY_GAME_READ" }];
3641

3742
const generateRouteList = (route: GamesHQRouteOption[]) => {
38-
return route.map((route, i) => (
43+
44+
return route.map((route, i) => ( route.necessaryCapability && currentUser?.capabilities.includes(route.necessaryCapability) &&
3945
<ul className="pt-4" key={i}>
4046
<Link to={route.to} className="items-center">
4147
<li className="flex text-gray-400 hover:text-gray-700 items-center">
@@ -46,6 +52,7 @@ export const AppMenu = ({ children }: { children: JSX.Element }) => {
4652
</ul>
4753
));
4854
};
55+
4956
return (
5057
<div className="flex h-screen bg-white">
5158
<nav className="w-80 font-medium text-base bg-gray-50 h-full py-4">
@@ -54,34 +61,48 @@ export const AppMenu = ({ children }: { children: JSX.Element }) => {
5461
</div>
5562
<div className="px-8 flex-col flex">
5663
<span className="pt-4" />
57-
<span className="uppercase py-1 text-xs text-gray-400 font-semibold">
58-
MY GAMES
59-
</span>
60-
61-
{generateRouteList(gameDevRoutes)}
62-
63-
<span className="uppercase py-1 text-xs text-gray-400 font-semibold mt-12">
64-
INSPECT LIVE GAMES
65-
</span>
66-
67-
{generateRouteList(inspectRoutes)}
64+
{currentUser?.capabilities.includes('MY_GAME_READ') && (
65+
<>
66+
<span className="uppercase py-1 text-xs text-gray-400 font-semibold">
67+
MY GAMES
68+
</span>
69+
70+
{generateRouteList(gameDevRoutes)}
71+
72+
<span className="uppercase py-1 text-xs text-gray-400 font-semibold mt-12">
73+
INSPECT LIVE GAMES
74+
</span>
75+
76+
{generateRouteList(inspectRoutes)}
77+
</>
6878

69-
<span className="uppercase py-1 text-xs text-gray-400 font-semibold mt-12">
70-
GENERAL
71-
</span>
79+
)}
80+
81+
{currentUser?.capabilities.includes('WEAPONS_READ') && (
82+
<>
83+
<span className="uppercase py-1 text-xs text-gray-400 font-semibold mt-12">
84+
GENERAL
85+
</span>
7286

73-
{generateRouteList(databaseRoutes)}
87+
{generateRouteList(databaseRoutes)}
88+
</>
89+
)}
7490

7591
<span className="uppercase py-1 text-xs text-gray-400 font-semibold mt-12">
7692
THE TOWER
7793
</span>
7894

7995
{generateRouteList(towerRoutes)}
80-
<span className="uppercase py-1 text-xs text-gray-400 font-semibold mt-12">
81-
THE ARENA
82-
</span>
8396

84-
{generateRouteList(arenaRoutes)}
97+
{currentUser?.capabilities.includes('THE_ARENA_READ') && (
98+
<>
99+
<span className="uppercase py-1 text-xs text-gray-400 font-semibold mt-12">
100+
THE ARENA
101+
</span>
102+
103+
{generateRouteList(arenaRoutes)}
104+
</>
105+
)}
85106
</div>
86107
</nav>
87108
<div className="w-full min-w-0 px-16 py-8">{children}</div>

Diff for: src/pages/InspectArenaPage.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const InspectArenaPage = function InspectArenaPage(props: any) {
1919

2020
const arenaPlayers = get(
2121
arenaGame,
22-
"_arena._players",
22+
"_arenaPlayers",
2323
[]
2424
) as IArenaPlayer[];
2525

Diff for: src/types.d.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ interface IGame {
167167
endedAt: string;
168168
_gameTypeId: number;
169169
_arena: IArenaGame;
170+
_arenaPlayers: [IArenaPlayer];
170171
}
171172

172173
interface IGameWithTower extends IGame {
@@ -181,7 +182,7 @@ interface IArenaGame {
181182
currentRingDeactivation: number;
182183
inactiveZonePenaltyPower: number;
183184
_gameId: number;
184-
_players: [IArenaPlayer];
185+
185186
}
186187

187188
interface IArenaRoundAction {
@@ -280,6 +281,7 @@ interface GamesAPIUSer {
280281
profilePictureUrl: string;
281282
role: number;
282283
isAdmin: boolean;
284+
capabilities: string[];
283285
}
284286

285287
interface GamesAPISession {

0 commit comments

Comments
 (0)