-
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.
Merge pull request #1764 from gettakaro/feature/gameserver-table
Feat: gameservers table view
- Loading branch information
Showing
13 changed files
with
460 additions
and
352 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
77 changes: 77 additions & 0 deletions
77
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,77 @@ | ||
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, | ||
isLoading, | ||
isFetchingNextPage, | ||
} = useInfiniteQuery({ | ||
...gameServersInfiniteQueryOptions(), | ||
}); | ||
|
||
if (isLoading) { | ||
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} | ||
/> | ||
</Fragment> | ||
); | ||
}; |
Oops, something went wrong.