Skip to content

Commit dee989a

Browse files
committed
Enhance who is online page
1 parent 810f9d3 commit dee989a

File tree

2 files changed

+31
-22
lines changed

2 files changed

+31
-22
lines changed

src/pages/community/who-is-online/index.tsx

+30-21
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,47 @@
1-
import StrippedTable from "@component/StrippedTable";
21
import Head from "@layout/Head";
32
import Label from "@component/Label";
43
import { trpc } from "@util/trpc";
5-
import { VStack } from "@chakra-ui/react";
4+
import { Table, TableContainer, Thead, Tr, Th, Tbody, Td } from "@chakra-ui/react";
65
import { getVocationNameById } from "@shared/enums/Vocation";
76
import { Content } from "@component/Content";
87

98
export default function WhoIsOnline() {
109
const players = trpc.player.online.useQuery();
1110
const status = trpc.status.status.useQuery();
11+
const onlinePlayers = players.data;
1212

1313
return (
1414
<>
1515
<Head title="Who is online" />
1616
<Content>
17-
<Content.Header>Server Info</Content.Header>
18-
<Content.Body>
19-
<VStack w="40rem" maxW="40rem">
20-
<Label colorScheme="violet" fontSize="sm">
21-
Overall Maximum: {status.data?.maxOnlineCount ?? 0} players. There are currently {players.data?.length ?? 0} players online on
22-
{status.data?.name ?? "..."}
23-
</Label>
24-
{players.data && (
25-
<StrippedTable
26-
isLoading={players.isLoading}
27-
head={[{ text: "Name" }, { text: "Level" }, { text: "Vocation" }]}
28-
body={players.data?.map((player) => [
29-
{ href: `/character/${player.name}`, text: player.name },
30-
{ text: player.level },
31-
{ text: getVocationNameById(player.vocation) },
32-
])}
33-
/>
34-
)}
35-
</VStack>
17+
<Content.Header>Who Is Online</Content.Header>
18+
<Content.Body w="100%" gap={5}>
19+
<Label colorScheme="violet" fontSize="sm">
20+
Overall Maximum: {status.data?.maxOnlineCount ?? 0} players. There are currently {onlinePlayers?.length ?? 0} players online on{" "}
21+
{status.data?.name ? status.data.name : "unknown"}
22+
</Label>
23+
{onlinePlayers && (
24+
<TableContainer>
25+
<Table variant="striped" colorScheme="purple">
26+
<Thead>
27+
<Tr>
28+
<Th>Name</Th>
29+
<Th isNumeric>Level</Th>
30+
<Th>Vocation</Th>
31+
</Tr>
32+
</Thead>
33+
<Tbody>
34+
{onlinePlayers?.map((player) => (
35+
<Tr key={player.name}>
36+
<Td>{player.name}</Td>
37+
<Td isNumeric>{player.level}</Td>
38+
<Td>{getVocationNameById(player.vocation)}</Td>
39+
</Tr>
40+
))}
41+
</Tbody>
42+
</Table>
43+
</TableContainer>
44+
)}
3645
</Content.Body>
3746
</Content>
3847
</>

src/server/routers/player.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export const playerRouter = router({
4444
}),
4545
online: procedure.query(async () => {
4646
const players = await prisma.players_online.findMany({
47-
select: { players: true },
47+
include: { players: { select: { name: true, vocation: true, level: true } } },
4848
});
4949

5050
return players.map((player) => player.players);

0 commit comments

Comments
 (0)