Skip to content

Commit 8311666

Browse files
committed
Use trpc for easier communication
1 parent fe1d1a5 commit 8311666

32 files changed

+603
-656
lines changed

package-lock.json

+111-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "shibaac",
3+
"version": "0.0.1",
34
"private": true,
45
"scripts": {
56
"dev": "next dev",
@@ -25,6 +26,11 @@
2526
"@emotion/styled": "^11.13.5",
2627
"@prisma/client": "^5.22.0",
2728
"@stripe/stripe-js": "^5.2.0",
29+
"@tanstack/react-query": "^4.36.1",
30+
"@trpc/client": "^10.45.2",
31+
"@trpc/next": "^10.45.2",
32+
"@trpc/react-query": "^10.45.2",
33+
"@trpc/server": "^10.45.2",
2834
"@types/jsonwebtoken": "^9.0.7",
2935
"@types/multer": "^1.4.12",
3036
"@types/nodemailer": "^6.4.17",
@@ -52,7 +58,8 @@
5258
"shibaac": "file:",
5359
"speakeasy": "^2.0.0",
5460
"stripe": "^17.4.0",
55-
"yup": "^1.4.0"
61+
"yup": "^1.4.0",
62+
"zod": "^3.23.8"
5663
},
5764
"devDependencies": {
5865
"@testing-library/jest-dom": "^6.6.3",

src/components/Button.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import React from "react";
22
import Link from "next/link";
3-
import { Button as ChakraButton } from "@chakra-ui/react";
3+
import { Button as ChakraButton, ButtonProps as ChakraButtonProps } from "@chakra-ui/react";
44

55
const btnTypeToColor = { danger: "red", primary: "violet" };
66

77
export type ButtonType = "button" | "submit" | "reset";
88
export type ButtonColorType = "danger" | "primary";
99

10-
export interface ButtonProps {
10+
export interface ButtonProps extends ChakraButtonProps {
1111
value: string;
1212
size?: string;
1313
type?: ButtonType;

src/components/StrippedTable.tsx

+2-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Table, Thead, Tbody, Tr, Th, Td } from "@chakra-ui/react";
44

55
export interface StripedTableProps {
66
head?: { text: string }[];
7-
body: { text: string; href?: string }[][];
7+
body: { text: string | number; href?: string }[][];
88
}
99

1010
const StripedTable = ({ head, body }: StripedTableProps) => {
@@ -23,13 +23,7 @@ const StripedTable = ({ head, body }: StripedTableProps) => {
2323
{body.map((row, index) => (
2424
<Tr key={`${index}`}>
2525
{row.map((data, dataIndex) => (
26-
<Td key={`${data.text} ${dataIndex}`}>
27-
{data.href ? (
28-
<Link href={data.href} text={data.text} />
29-
) : (
30-
data.text
31-
)}
32-
</Td>
26+
<Td key={`${data.text} ${dataIndex}`}>{data.href ? <Link href={data.href} text={data.text} /> : data.text}</Td>
3327
))}
3428
</Tr>
3529
))}

src/layout/Head.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const Head = ({ title = "shibaac", description = "Automatic Account Creator" }:
2525
description: description,
2626
//url: properties.canonical,
2727
locale: "en",
28-
site_name: "SHIBAac",
28+
site_name: "shibaac",
2929
}}
3030
/>
3131
</>

src/layout/SideBar.tsx

+9-12
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,22 @@ import Link from "../components/Link";
66
import { Box, LayoutProps } from "@chakra-ui/react";
77
import StripedTable from "../components/StrippedTable";
88
import { type ProtocolStatusCache } from "../cache/protocolStatus";
9-
import { players } from ".prisma/client";
9+
import { trpc } from "@util/trpc";
1010

1111
const SideBar = (props: LayoutProps) => {
1212
const [serverStatus, setServerStatus] = useState<ProtocolStatusCache>();
13-
const [topPlayers, setTopPlayers] = useState<players[]>();
13+
14+
const topPlayers = trpc.player.top5.useQuery();
1415
const [isLoading, setIsLoading] = useState(false);
1516

1617
useEffect(() => {
1718
const fetchData = async () => {
1819
setIsLoading(true);
1920

20-
const [players, status] = await Promise.all([
21-
fetchApi<{ players: any[] }>("GET", `/api/player/top5`),
22-
fetchApi<{ status: ProtocolStatusCache }>("GET", `/api/status`),
23-
]);
21+
const [status] = await Promise.all([fetchApi<{ status: ProtocolStatusCache }>("GET", `/api/status`)]);
2422

25-
if (players.success && status.success) {
23+
if (status.success) {
2624
setIsLoading(false);
27-
setTopPlayers(players.players || []);
2825
setServerStatus(status.status);
2926
}
3027
};
@@ -34,7 +31,7 @@ const SideBar = (props: LayoutProps) => {
3431

3532
return (
3633
<Box minWidth="15em" {...props}>
37-
<Panel header="Server Status" isLoading={isLoading}>
34+
<Panel header="Server Status" isLoading={isLoading || !topPlayers.data}>
3835
<table className="table table-condensed table-content table-striped">
3936
<tbody>
4037
<tr>
@@ -51,14 +48,14 @@ const SideBar = (props: LayoutProps) => {
5148
<StripedTable
5249
head={[{ text: "Name" }, { text: "Level" }]}
5350
body={
54-
topPlayers && topPlayers.length > 0
55-
? topPlayers.map((player, index) => [
51+
topPlayers.data && topPlayers.data.length > 0
52+
? topPlayers.data.map((player, index) => [
5653
{
5754
text: `${index + 1}. ${player.name}`,
5855
href: `/character/${player.name}`,
5956
},
6057
{
61-
text: player.level,
58+
text: player.level.toString(),
6259
},
6360
])
6461
: [

src/pages/_app.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import { UserContextWrapper } from "../hooks/useUser";
33
import { ChakraProvider } from "@chakra-ui/react";
44
import { Theme, Fonts } from "../layout/theme";
55
import React from "react";
6+
import { trpc } from "../utils/trpc";
67

78
// @ts-ignore
89
BigInt.prototype.toJSON = function () {
910
const int = Number.parseInt(this.toString());
1011
return int ?? this.toString();
1112
};
1213

13-
export default function MyApp({ Component, pageProps }) {
14+
const MyApp = ({ Component, pageProps }) => {
1415
return (
1516
<UserContextWrapper>
1617
<ChakraProvider theme={Theme}>
@@ -21,4 +22,6 @@ export default function MyApp({ Component, pageProps }) {
2122
</ChakraProvider>
2223
</UserContextWrapper>
2324
);
24-
}
25+
};
26+
27+
export default trpc.withTRPC(MyApp);

0 commit comments

Comments
 (0)