-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0bc7fc2
commit 42f0ac3
Showing
11 changed files
with
451 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
packages/web-main/src/routes/_auth/_global/-gameservers/GameServersCardView.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { useNavigate, Outlet } from '@tanstack/react-router'; | ||
import { gameServersInfiniteQueryOptions } from 'queries/gameserver'; | ||
import { PermissionsGuard } from 'components/PermissionsGuard'; | ||
import { AddCard, CardList, GameServerCard } from 'components/cards'; | ||
import { useInfiniteQuery } from '@tanstack/react-query'; | ||
import { Button, Empty, EmptyPage, InfiniteScroll, Skeleton } from '@takaro/lib-components'; | ||
import { Fragment } from 'react'; | ||
import { PERMISSIONS } from '@takaro/apiclient'; | ||
|
||
export const GameServersCardView = () => { | ||
const navigate = useNavigate(); | ||
|
||
const { | ||
data: gameServers, | ||
isFetching, | ||
hasNextPage, | ||
fetchNextPage, | ||
isPending, | ||
isFetchingNextPage, | ||
} = useInfiniteQuery({ | ||
...gameServersInfiniteQueryOptions(), | ||
}); | ||
|
||
if (isPending) { | ||
return ( | ||
<CardList> | ||
<Skeleton variant="rectangular" height="100%" width="100%" /> | ||
<Skeleton variant="rectangular" height="100%" width="100%" /> | ||
<Skeleton variant="rectangular" height="100%" width="100%" /> | ||
<Skeleton variant="rectangular" height="100%" width="100%" /> | ||
</CardList> | ||
); | ||
} | ||
|
||
if (!gameServers || gameServers.pages.length === 0) { | ||
return ( | ||
<EmptyPage> | ||
<Empty | ||
header="Bro, what are you waiting on?" | ||
description="Create a game server to really get started with Takaro." | ||
actions={[ | ||
<Button | ||
key="gameservers-create" | ||
text="Create a game server" | ||
onClick={() => navigate({ to: '/gameservers/create' })} | ||
/>, | ||
]} | ||
/> | ||
<Outlet /> | ||
</EmptyPage> | ||
); | ||
} | ||
|
||
return ( | ||
<Fragment> | ||
<CardList> | ||
{gameServers.pages | ||
.flatMap((page) => page.data) | ||
.map((gameServer) => ( | ||
<GameServerCard key={gameServer.id} {...gameServer} /> | ||
))} | ||
<PermissionsGuard requiredPermissions={[PERMISSIONS.ManageGameservers]}> | ||
<AddCard title="Gameserver" onClick={() => navigate({ to: '/gameservers/create' })} /> | ||
</PermissionsGuard> | ||
<PermissionsGuard requiredPermissions={[PERMISSIONS.ManageGameservers]}> | ||
<AddCard title="Import from CSMM" onClick={() => navigate({ to: '/gameservers/create/import' })} /> | ||
</PermissionsGuard> | ||
</CardList> | ||
<InfiniteScroll | ||
isFetching={isFetching} | ||
hasNextPage={hasNextPage} | ||
fetchNextPage={fetchNextPage} | ||
isFetchingNextPage={isFetchingNextPage} | ||
/> | ||
<Outlet /> | ||
</Fragment> | ||
); | ||
}; |
Oops, something went wrong.