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

Chat backend+Frontend added #16

Open
wants to merge 26 commits into
base: backend-development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
bc1a58a
Connect creteRoom from backend
dongjin2008 Sep 13, 2023
283f205
Custom url for each room added
dongjin2008 Sep 13, 2023
98bd3ae
style: Format code with prettier and standardjs
deepsource-autofix[bot] Sep 13, 2023
c7ce1b8
Switched to cn in the button component
FleetAdmiralJakob Sep 14, 2023
65945a3
Removed unnecessary abstractions and added a little bit of stuff to t…
FleetAdmiralJakob Sep 14, 2023
59f83b8
style: Format code with prettier and standardjs
deepsource-autofix[bot] Sep 14, 2023
4c6b8c6
Working
dongjin2008 Sep 16, 2023
168536f
Merge remote-tracking branch 'origin/dev-pairplay' into dev-pairplay
dongjin2008 Sep 16, 2023
59f5198
Chat backend+fronted added
dongjin2008 Sep 17, 2023
1555f5b
style: format code with Prettier and StandardJS
deepsource-autofix[bot] Sep 17, 2023
7e0b6c0
Updated some stuff
FleetAdmiralJakob Sep 17, 2023
e9132d4
style: format code with Prettier and StandardJS
deepsource-autofix[bot] Sep 17, 2023
1f49928
Typed
dongjin2008 Sep 17, 2023
8fc20f0
style: format code with Prettier and StandardJS
deepsource-autofix[bot] Sep 17, 2023
cd1db61
Updated all package
dongjin2008 Sep 17, 2023
5efd4b3
Merge remote-tracking branch 'origin/dev-pairplay' into dev-pairplay
dongjin2008 Sep 17, 2023
55ec1f5
style: format code with Prettier and StandardJS
deepsource-autofix[bot] Sep 17, 2023
708358b
Updated some stuff
FleetAdmiralJakob Sep 17, 2023
3e898a6
style: format code with Prettier and StandardJS
deepsource-autofix[bot] Sep 17, 2023
a95dd39
Chat added
dongjin2008 Sep 17, 2023
2f9e14f
style: format code with Prettier and StandardJS
deepsource-autofix[bot] Sep 17, 2023
5268cf5
Fixed the border radius issue
dongjin2008 Sep 17, 2023
c715186
Merge remote-tracking branch 'origin/dev-pairplay' into dev-pairplay
dongjin2008 Sep 17, 2023
12d846b
style: format code with Prettier and StandardJS
deepsource-autofix[bot] Sep 17, 2023
88ef5ea
Merge branch 'backend-development' into dev-pairplay
FleetAdmiralJakob Sep 17, 2023
63815d6
style: format code with Prettier and StandardJS
deepsource-autofix[bot] Sep 17, 2023
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
4 changes: 2 additions & 2 deletions .gitignore
Copy link
Member

Choose a reason for hiding this comment

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

@dongjin2008 Remove all changes here

Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ yarn-error.log*
# local env files
# do not commit any .env files to git, except for the .env.example file. https://create.t3.gg/en/usage/env-variables#using-environment-variables
.env
.env*.local
.env

# vercel
.vercel

# typescript
*.tsbuildinfo

.env.local
.env
2 changes: 1 addition & 1 deletion convex/_generated/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* THIS CODE IS AUTOMATICALLY GENERATED.
*
* Generated by convex@1.2.1.
* Generated by convex@1.3.1.
* To regenerate, run `npx convex dev`.
* @module
*/
Expand Down
2 changes: 1 addition & 1 deletion convex/_generated/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* THIS CODE IS AUTOMATICALLY GENERATED.
*
* Generated by convex@1.2.1.
* Generated by convex@1.3.1.
* To regenerate, run `npx convex dev`.
* @module
*/
Expand Down
2 changes: 1 addition & 1 deletion convex/_generated/dataModel.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* THIS CODE IS AUTOMATICALLY GENERATED.
*
* Generated by convex@1.2.1.
* Generated by convex@1.3.1.
* To regenerate, run `npx convex dev`.
* @module
*/
Expand Down
2 changes: 1 addition & 1 deletion convex/_generated/server.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* THIS CODE IS AUTOMATICALLY GENERATED.
*
* Generated by convex@1.2.1.
* Generated by convex@1.3.1.
* To regenerate, run `npx convex dev`.
* @module
*/
Expand Down
2 changes: 1 addition & 1 deletion convex/_generated/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* THIS CODE IS AUTOMATICALLY GENERATED.
*
* Generated by convex@1.2.1.
* Generated by convex@1.3.1.
* To regenerate, run `npx convex dev`.
* @module
*/
Expand Down
5 changes: 4 additions & 1 deletion convex/openai.ts
Copy link
Member

Choose a reason for hiding this comment

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

@dongjin2008 Remove all changes here

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import { action } from "./_generated/server";
import { v } from "convex/values";
import { api } from "../convex/_generated/api";
import OpenAI from "openai";
import dotenv from "dotenv";

dotenv.config();
const apiKey: string = process.env.OPENAI_API_KEY || "";
// Initialize the OpenAI client with the given API key
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY, // This is also the default, can be omitted
apiKey: apiKey,
});
// start a game
export const startGames = action({
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
"@total-typescript/ts-reset": "^0.5.1",
"clsx": "^2.0.0",
"convex": "^1.2.1",
"next": "^13.4.2",
"dotenv": "^16.3.1",
Copy link
Member

Choose a reason for hiding this comment

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

Remove this dependency

"next": "^13.4.19",
"openai": "^4.5.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"valtio": "^1.11.2",
"zod": "^3.21.4"
},
"devDependencies": {
Expand Down
55 changes: 54 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions src/app/ConvexClientProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use client";
import { ReactNode } from "react";
import { ConvexProvider, ConvexReactClient } from "convex/react";
import * as process from "process";

const convex = new ConvexReactClient(process.env.NEXT_PUBLIC_CONVEX_URL!);
Copy link
Member

Choose a reason for hiding this comment

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

Pls. use the ~/env.mjs file not dotenv!!! no process.env!


export default function ConvexClientProvider({
children,
}: {
children: ReactNode;
}) {
return <ConvexProvider client={convex}>{children}</ConvexProvider>;
}
3 changes: 2 additions & 1 deletion src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import "~/styles/globals.css";
import { Poppins } from "next/font/google";
import { cn } from "~/lib/utils";
import ConvexClientProvider from "~/app/ConvexClientProvider";

const poppins = Poppins({
variable: "--font-poppins",
Expand All @@ -23,7 +24,7 @@ export default function RootLayout({
return (
<html lang="en">
<body className={cn("bg-background text-primary", poppins.className)}>
{children}
<ConvexClientProvider>{children}</ConvexClientProvider>
</body>
</html>
);
Expand Down
64 changes: 58 additions & 6 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,79 @@
"use client";
import { Button } from "~/ui/button";
import { Input } from "~/ui/input";
import { Switch } from "~/ui/switch";
import { useMutation } from "convex/react";
import { useState } from "react";
import { api } from "../../convex/_generated/api";
import { SmallInput } from "~/ui/small-input";
import { useRouter } from "next/navigation";
import { useSnapshot } from "valtio";
import { state } from "~/app/state";

export default function HomePage() {
const [chatEnabled, setChatEnabled] = useState(false);
const [pairs, setPairs] = useState(false);
const [timeLimit, setTimeLimit] = useState(600);
const [username, setUsername] = useState("");
const createRoom = useMutation(api.rooms.createRoom);
const router = useRouter();
const snap = useSnapshot(state);

const handleClick = async () => {
try {
const result = await createRoom({
username: username,
chatEnabled: chatEnabled,
timeLimit: timeLimit,
pairs: pairs,
});
const roomId = result.roomId;
const playId = result.playId;
snap.setPlayerId(playId);
snap.setUsername(username);
router.push(`/room/${roomId}`);
} catch (error) {
console.log(error);
}
};

return (
<main className="w-screen flex min-h-fullDVH flex-col items-center justify-between">
<main className="w-screen flex min-h-screen flex-col items-center justify-between">
<h1 className="text-[2.9375rem] sm:text-[5.75rem] mt-6 font-extrabold">
SketchIt
</h1>
<form className="flex flex-col gap-6 w-full sm:w-auto max-w-[20rem] sm:max-w-none">
<Input placeholder="Enter the username" />
<Button className="font-bold" type="submit">
<Input
placeholder="Enter the username"
onChange={(event) => setUsername(event.target.value)}
/>
<Button
className="font-bold"
type="submit"
onClick={(event) => {
{
event.preventDefault();
handleClick().catch((error) => console.log(error));
}
}}
>
Create Room
</Button>
<div className="mt-10 flex justify-between">
<Switch description="Chat" />
<Switch
description="Chat"
onCheckedChange={(checked) => setChatEnabled(checked)}
/>
<SmallInput
type="number"
defaultValue={600}
description="Time limit"
description="Time Limit"
onChange={(event) => setTimeLimit(parseInt(event.target.value))}
/>
<Switch
description="Pairplay"
onCheckedChange={(checked) => setPairs(checked)}
/>
<Switch description="Pairplay" />
</div>
</form>
<div />
Expand Down
24 changes: 24 additions & 0 deletions src/app/room/[slug]/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"use client";
import React from "react";
import Navbar from "../../../ui/navbar";
import Profile from "../../../ui/Profile";
import { useSnapshot } from "valtio";
import { state } from "~/app/state";

export default function playerLayout({
children,
}: {
children: React.ReactNode;
}) {
const snap = useSnapshot(state);
return (
<section className="h-screen px-10 py-14 flex flex-col">
<Navbar>
Copy link
Member

@FleetAdmiralJakob FleetAdmiralJakob Sep 17, 2023

Choose a reason for hiding this comment

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

Why do we need the navbar component? Pls. remove the navbar component and put the logic into this file. Or you have a good reason to do it.

<Profile type="nav" initial={snap.user.charAt(0).toUpperCase()} />
<Profile type="nav" initial={snap.user.charAt(0).toUpperCase()} />
Copy link
Member

@FleetAdmiralJakob FleetAdmiralJakob Sep 17, 2023

Choose a reason for hiding this comment

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

Pls. make them into buttons! Use the ~/ui/button for that

<Profile type="nav" initial={snap.user.charAt(0).toUpperCase()} />
</Navbar>
{children}
</section>
);
}
10 changes: 10 additions & 0 deletions src/app/room/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Chat from "~/ui/chat";

export default function RoomPage({ params }: { params: { slug: string } }) {
return (
<main className="h-full flex justify-between min-h-0 gap-12">
<div className="h-full w-full"></div>
<Chat roomId={params.slug} />
</main>
);
}
13 changes: 13 additions & 0 deletions src/app/state.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { proxy } from "valtio";

export const state = proxy({
playerId: "",
setPlayerId: (id: string) => {
state.playerId = id;
},

user: "",
setUsername: (username: string) => {
state.user = username;
},
});
20 changes: 20 additions & 0 deletions src/ui/Profile.tsx
Copy link
Member

Choose a reason for hiding this comment

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

rename this file to profile.tsx

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const Profile = ({ type, initial }) => {
return (
<div>
{type === "nav" && (
<div className="flex flex-col items-center justify-center w-[99px] h-[79px] bg-primary rounded-3xl">
<div className="w-[46px] h-[46px] bg-background rounded-full flex justify-center items-center">
<p className="text-primary font-extrabold text-2xl">{initial}</p>
</div>
</div>
)}
{type === "chat" && (
<div className="w-[37px] h-[37px] bg-background rounded-full flex justify-center items-center">
<p className="text-primary font-extrabold text-2xl">{initial}</p>
</div>
)}
</div>
);
};

export default Profile;
5 changes: 3 additions & 2 deletions src/ui/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import * as React from "react";
import { experimental_useFormStatus } from "react-dom";
import { twMerge } from "tailwind-merge";
import { cn } from "~/lib/utils";

export const Button = React.forwardRef<
HTMLButtonElement,
Expand All @@ -12,8 +13,8 @@ export const Button = React.forwardRef<

return (
<button
className={twMerge(
"inline-flex w-full items-center justify-center rounded-[1.25rem] bg-primary py-[0.63rem] px-5 text-3xl sm:text-[2.9375rem] leading-[4.438rem] font-medium text-background ring-offset-background transition-colors hover:bg-primary/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
className={cn(
"inline-flex w-full items-center justify-center rounded-[1.25rem] bg-primary py-[0.63rem] px-5 text-[2.9375rem] leading-[4.438rem] font-bold text-background ring-offset-background transition-colors hover:bg-primary/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
className,
)}
disabled={props.disabled || pending}
Expand Down
Loading