+
+ {/*
*/}
- [
- { href: `/character/${player.name}`, text: player.name },
- { text: player.level },
- { text: vocationIdToName[player.vocation] },
+ [
+ { href: `/character/${player.name}`, text: player.name },
+ { text: player.level },
+ { text: vocationIdToName[player.vocation] },
- // {
- // type: 'button',
- // text: 'Edit',
- // href: `/account/editcharacter/${player.name}`,
- // },
- ])}
- />
-
-
+ // {
+ // type: 'button',
+ // text: 'Edit',
+ // href: `/account/editcharacter/${player.name}`,
+ // },
+ ])}
+ />
+
+
+
>
);
}
diff --git a/src/pages/character/[name].tsx b/src/pages/character/[name].tsx
index d3e5d84..4cae501 100644
--- a/src/pages/character/[name].tsx
+++ b/src/pages/character/[name].tsx
@@ -5,111 +5,124 @@ import { useRouter } from "next/router";
import StrippedTable from "src/components/StrippedTable";
import Label from "src/components/Label";
import { trpc } from "../../utils/trpc";
+import { Content } from "@component/Content";
+import Loader from "@component/Loader";
+
+// TODO: refactor this view, because its really ugly
export default function Character() {
const router = useRouter();
const { name } = router.query;
- const player = trpc.player.singleByName.useQuery({ name: String(name) });
- const townId = player.data?.town_id;
- const town = trpc.town.singleById.useQuery(
- { id: townId as number },
- {
- enabled: !!townId,
- },
- );
+ const characterData = trpc.player.singleByName.useQuery({ name: String(name) });
- if (!player.isFetched || !town.isFetched) {
- return
;
+ if (characterData.isLoading) {
+ return (
+
+ Character
+
+
+
+
+ );
}
- if (!player.data) {
+ if (characterData.error) {
return (
-
-
-
+
+ Character
+
+
+
+
);
}
- const lastLoginDate = player.data.lastlogin > 0 ? timestampToDate(player.data.lastlogin) : "Never logged in";
- const isPremium = player.data.accounts.premium_ends_at >= Date.now();
+ const playerData = characterData.data.player;
+ const townData = characterData.data.town;
- return (
- <>
-
- 0
- // ? [
- // {
- // text: "Guild",
- // },
- // {
- // text: player.data.guilds[0].name,
- // },
- // ]
- // : []),
- [{ text: "Last Login" }, { text: lastLoginDate }],
- // [
- // { text: "Online Time" },
- // {
- // text: player.data.onlinetime > 0 ? secondsToTime(player.data.onlinetime) : "Never logged in",
- // },
- // ],
- ]}
- />
-
+ const lastLoginDate = playerData.lastlogin > 0 ? timestampToDate(playerData.lastlogin) : "Never logged in";
+ const isPremium = playerData.accounts.premium_ends_at >= Date.now();
-
- 1 ? [[{ text: "Position" }, { text: groupToName[player.data.group_id] }]] : []),
- // [
- // { text: "Created" },
- // {
- // text: player.data.creation > 0 ? timestampToDate(player.data.creation) : "Unknown",
- // },
- // ],
- [
- { text: "Account Status" },
- {
- text: `${isPremium ? "Premium" : "Free"} Account`,
- },
- ],
- ]}
- />
-
+ return (
+
+ Character
+
+
+ 0
+ // ? [
+ // {
+ // text: "Guild",
+ // },
+ // {
+ // text: playerData.guilds[0].name,
+ // },
+ // ]
+ // : []),
+ [{ text: "Last Login" }, { text: lastLoginDate }],
+ // [
+ // { text: "Online Time" },
+ // {
+ // text: playerData.onlinetime > 0 ? secondsToTime(playerData.onlinetime) : "Never logged in",
+ // },
+ // ],
+ ]}
+ />
+
- {player.data.player_deaths.length > 0 && (
-
+
[
- { text: timestampToDate(death.time) },
- { text: `Died at level ${death.level} by ${death.killed_by}` },
- ])}
+ body={[
+ ...(playerData.group_id > 1 ? [[{ text: "Position" }, { text: groupToName[playerData.group_id] }]] : []),
+ // [
+ // { text: "Created" },
+ // {
+ // text: playerData.creation > 0 ? timestampToDate(playerData.creation) : "Unknown",
+ // },
+ // ],
+ [
+ { text: "Account Status" },
+ {
+ text: `${isPremium ? "Premium" : "Free"} Account`,
+ },
+ ],
+ ]}
/>
- )}
- {/* Deleted */}
+ {playerData.player_deaths.length > 0 && (
+
+ [
+ { text: timestampToDate(death.time) },
+ { text: `Died at level ${death.level} by ${death.killed_by}` },
+ ])}
+ />
+
+ )}
-
- [
- { href: `/character/${player.name}`, text: player.name },
- { text: player.level },
- { text: vocationIdToName[player.vocation] },
- // { text: player.players_online ? "Online" : "Offline" },
- ])}
- />
-
- >
+ {/* Deleted */}
+
+
+ [
+ { href: `/character/${player.name}`, text: player.name },
+ { text: player.level },
+ { text: vocationIdToName[player.vocation] },
+ // { text: player.players_online ? "Online" : "Offline" },
+ ])}
+ />
+
+
+
);
}
diff --git a/src/pages/character/index.tsx b/src/pages/character/index.tsx
index 5024f30..6473cc5 100644
--- a/src/pages/character/index.tsx
+++ b/src/pages/character/index.tsx
@@ -1,11 +1,12 @@
-import Panel from "src/components/Panel";
import { useRouter } from "next/router";
import { SubmitHandler, useForm } from "react-hook-form";
import { z } from "zod";
import { zodResolver } from "@hookform/resolvers/zod";
-import { Container, VStack } from "@chakra-ui/react";
+import { VStack } from "@chakra-ui/react";
import TextInput from "@component/TextInput";
import { FormField } from "@component/FormField";
+import { Content } from "@component/Content";
+import Button from "@component/Button";
const schema = z.object({
name: z.string(),
@@ -15,7 +16,8 @@ export default function Character() {
const {
register,
handleSubmit,
- formState: { errors },
+
+ formState: { errors, isValid, isSubmitting },
} = useForm
>({
resolver: zodResolver(schema),
});
@@ -26,16 +28,26 @@ export default function Character() {
};
return (
-
-
-
+
+
+
);
}
diff --git a/src/server/routers/player.ts b/src/server/routers/player.ts
index ae6fbc9..e538a74 100644
--- a/src/server/routers/player.ts
+++ b/src/server/routers/player.ts
@@ -1,6 +1,7 @@
import { z } from "zod";
import { procedure, router } from "../trpc";
import prisma from "../../prisma";
+import { TRPCError } from "@trpc/server";
export const playerRouter = router({
singleByName: procedure.input(z.object({ name: z.string() })).query(async ({ input }) => {
@@ -27,7 +28,19 @@ export const playerRouter = router({
},
});
- return player;
+ if (!player) {
+ throw new TRPCError({ code: "NOT_FOUND", message: "Character not found" });
+ }
+
+ const town = await prisma.towns.findFirst({
+ where: { id: player.town_id },
+ select: { name: true },
+ });
+
+ return {
+ player,
+ town,
+ };
}),
online: procedure.query(async () => {
const players = await prisma.players_online.findMany({
diff --git a/src/shared/enums/Sex.ts b/src/shared/enums/Sex.ts
index d5c998d..4eacced 100644
--- a/src/shared/enums/Sex.ts
+++ b/src/shared/enums/Sex.ts
@@ -3,4 +3,12 @@ export enum Sex {
Male = 1,
}
+export const getSexNames = () => {
+ return Object.keys(Sex).filter(([key]) => Number.isNaN(Number(key)));
+};
+
+export const getSexByName = (name: keyof typeof Sex) => {
+ return Sex[name] || Sex.Female;
+};
+
export type SexType = keyof typeof Sex;
diff --git a/src/shared/enums/Vocation.ts b/src/shared/enums/Vocation.ts
index b737d3b..dd15928 100644
--- a/src/shared/enums/Vocation.ts
+++ b/src/shared/enums/Vocation.ts
@@ -6,6 +6,10 @@ export enum Vocation {
Knight = 4,
}
+export const getVocationNames = () => {
+ return Object.keys(Vocation).filter(([key]) => Number.isNaN(Number(key)));
+};
+
export type VocationType = keyof typeof Vocation;
export const getVocationByName = (name: keyof typeof Vocation): Vocation => {