Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add character page #8

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,25 @@
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation.
* This is especially useful for Docker builds.
*/
!process.env.SKIP_ENV_VALIDATION && (await import("./src/env/server.mjs"));
!process.env.SKIP_ENV_VALIDATION && (await import('./src/env/server.mjs'));

/** @type {import("next").NextConfig} */
const config = {
reactStrictMode: true,
/* If trying out the experimental appDir, comment the i18n config out
* @see https://github.com/vercel/next.js/issues/41980 */
i18n: {
locales: ["en"],
defaultLocale: "en",
locales: ['en'],
defaultLocale: 'en',
},
images: {
remotePatterns: [
{
protocol: 'https',
hostname: '**',
},
],
},
};

export default config;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"build": "next build",
"dev": "next dev",
"postinstall": "prisma generate",
"lint": "next lint && eslint --fix --max-warnings=0 && prettier --config .prettierrc.json '**/*.{tsx,ts}' --write",
"lint": "next lint && eslint --fix --max-warnings=0 && prettier --config .prettierrc.json \"**/*.{tsx,ts}\" --write",
"start": "next start",
"prepare": "husky install"
},
Expand Down
Binary file added public/LordOfRingLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
110 changes: 110 additions & 0 deletions src/pages/character/[id].tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import { useRouter } from 'next/router';
VishruthR marked this conversation as resolved.
Show resolved Hide resolved
import { api } from '../../utils/api';

import {
Card,
CardHeader,
CardBody,
CardFooter,
Stack,
Heading,
VishruthR marked this conversation as resolved.
Show resolved Hide resolved
Text,
Button,
Box,
Flex,
Center,
Image,
AspectRatio,
} from '@chakra-ui/react';

const Post = () => {
const router = useRouter();
const { id } = router.query;

// https://trpc.io/docs/nextjs#6-make-an-api-request
const characterRequest = api.characterRouter.getCharacter.useQuery({
id: id ? +id : 0,
});

const characterInfo = characterRequest.data;

return (
<Box w="100%" h="100vh" bg="black">
<Center pb={4}>
<Image src="/LordOfRingLogo.png" alt="Logo" width="300px" />
</Center>
<Center>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the Figma, we want the card to be centered on the page---maybe try putting the image & the card in the same Center component & giving the image absolute positioning

<Card
direction={{ base: 'column', sm: 'row' }}
overflow="hidden"
variant="outline"
bg="black"
borderRadius="0"
border="none"
>
<Stack>
<CardBody>
<Heading color="white" py={2} size="lg">
{characterInfo?.name}
</Heading>

<Heading size="sm" color="white" py={2}>
General Information
</Heading>
<Box
overflow="hidden"
backgroundColor="gray.900"
border="none"
borderRadius="none"
p={3}
mb={3}
>
<Text py="1" color="white">
Gender: {characterInfo?.gender}
</Text>
<Text py="1" color="white">
Race: {characterInfo?.race}
</Text>
<Text py="1" color="white">
Realm: {characterInfo?.realm}
</Text>
</Box>

<Heading size="sm" color="white" py={2}>
Wiki URL
</Heading>
<Box
overflow="hidden"
backgroundColor="gray.900"
border="none"
borderRadius="none"
p={2}
>
<Text color="white">{characterInfo?.wikiUrl}</Text>
</Box>
</CardBody>

<CardFooter>
<Button variant="solid" colorScheme="yellow" borderRadius="0">
Edit Character
</Button>
</CardFooter>
</Stack>
{characterInfo && (
<Center boxSize="sm">
<AspectRatio maxH="350px" ratio={3 / 4} flex="1 1 auto">
VishruthR marked this conversation as resolved.
Show resolved Hide resolved
<Image
src={characterInfo.imageUrl}
alt={`Picture of ${characterInfo.name}`}
objectFit="cover"
/>
</AspectRatio>
</Center>
)}
</Card>
</Center>
</Box>
);
};

export default Post;
14 changes: 14 additions & 0 deletions src/server/api/routers/character.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,18 @@ export const characterRouter = createTRPCRouter({
const count = await ctx.prisma.character.count();
return count;
}),
getCharacter: publicProcedure
.input(z.object({ id: z.number() }))
.query(async ({ ctx, input }) => {
// Implement the getCharacter procedure in src/server/api/routers/character.ts so that the procedure returns a character given the character's id
// https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#findunique
const character = await ctx.prisma.character.findUnique({
where: { id: input.id },
});
return character;
}),
getAllCharacters: publicProcedure.query(async ({ ctx }) => {
const allCharacters = await ctx.prisma.character.findMany();
return allCharacters;
}),
});
2 changes: 2 additions & 0 deletions src/server/api/trpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type CreateContextOptions = Record<string, never>;
* - trpc's `createSSGHelpers` where we don't have req/res
* @see https://create.t3.gg/en/usage/trpc#-servertrpccontextts
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const createInnerTRPCContext = (_opts: CreateContextOptions) => {
return {
prisma,
Expand All @@ -42,6 +43,7 @@ const createInnerTRPCContext = (_opts: CreateContextOptions) => {
* process every request that goes through your tRPC endpoint
* @link https://trpc.io/docs/context
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const createTRPCContext = (_opts: CreateNextContextOptions) => {
return createInnerTRPCContext({});
};
Expand Down
Loading