Skip to content

Commit 3abb0f4

Browse files
authored
Merge branch 'main' into main
2 parents 4c3fb0c + 45682d6 commit 3abb0f4

File tree

14 files changed

+147
-100
lines changed

14 files changed

+147
-100
lines changed

CONTRIBUTING.md

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,43 +34,45 @@ If you are getting WSL error when you launch your desktop docker application, go
3434

3535
To get started with Code Racer locally, follow these steps
3636

37-
1. Fork the repo
37+
1. Make sure you have installed Docker locally (See above Prerequisites)
3838

39-
2. Clone your fork
39+
2. Fork the repo
40+
41+
3. Clone your fork
4042

4143
```sh
4244
git clone https://github.com/<YOUR_GITHUB_ACCOUNT_NAME>/code-racer.git
4345
```
4446

45-
3. Navigate to the project directory
47+
4. Navigate to the project directory
4648

4749
```sh
4850
cd code-racer
4951
```
5052

51-
4. Create a .env file inside the project's packages/app directory.
53+
5. Create a .env file inside the project's packages/app directory.
5254

53-
5. Copy and paste variables from `packages/app/.env.example` into `packages/app/.env`
55+
6. Copy and paste variables from `packages/app/.env.example` into `packages/app/.env`
5456

55-
6. Install NPM packages
57+
7. Install NPM packages
5658

5759
```sh
5860
npm i
5961
```
6062

61-
7. Start the database
63+
8. Start the database
6264

6365
```sh
6466
npm run dev:db
6567
```
6668

67-
8. Start the app dev server
69+
9. Start the app dev server
6870

6971
```sh
7072
npm run dev:app
7173
```
7274

73-
9. Start the web socket server
75+
10. Start the web socket server
7476

7577
```sh
7678
npm run dev:wss
@@ -80,9 +82,14 @@ Open your browser and visit <http://localhost:3000> to see the application runni
8082

8183
## Working on New Features
8284

83-
If you're new to github and working with open source repositories, I made a video a while back which walks you through the process:
85+
If you're new to Github and working with open source repositories, I made a video a while back which walks you through the process:
8486
[![How to make a pull request on an open source project](https://img.youtube.com/vi/8A4TsoXJOs8/0.jpg)](https://youtu.be/8A4TsoXJOs8)
8587

88+
There is also a new video explaining how you can contribute to this project:
89+
<br/>
90+
[How to contribute to open source projects (our community project walkthrough)](https://www.youtube.com/watch?v=dLRA1lffWBw)
91+
92+
8693
If you want to work on a new feature, follow these steps.
8794

8895
1. Fork the repo
@@ -105,15 +112,15 @@ git checkout main
105112
git pull upstream main
106113
```
107114

108-
## Before Submitting Pull Request
115+
## Before Submitting a Pull Request
109116
Before submitting a **Pull Request**, you should
110117
1. Check your code safety with Linter and TypeScript, and make sure your code can build successfully.
111118

112119
```sh
113120
npm run pr:precheck
114121
```
115122

116-
2. (Optional) Do an E2E test to ensure application function properly
123+
2. (Optional) Do an E2E test to ensure application functions properly
117124

118125
```
119126
npm run e2e -w @code-racer/app
@@ -124,7 +131,8 @@ npm run e2e -w @code-racer/app
124131

125132
In the interest of fostering an open and welcoming environment, we as
126133
contributors and maintainers pledge to making participation in our project and
127-
our community a friendly experience for everyone, regardless of any experience to give everyone an opportunity to contribute in this project.
134+
our community a friendly experience for everyone, regardless of any experience
135+
to give everyone an opportunity to contribute in this project.
128136

129137
### Our Responsibilities
130138

File renamed without changes.

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div align="center" >
2-
<img src="./packages/app/public/static/logo.png" width="60" alt="">
2+
<img src="./packages/app/public/static/logo.png" width="60" alt="code-racer-logo">
33
<br/>
44
<h1>Code Racer</h1>
55
</div>
@@ -29,10 +29,10 @@
2929

3030
## Technologies Used :computer:
3131

32-
- [Next.js](https://nextjs.org) : A React framework for building server-side rendered and statically generated applications.
33-
- [NextAuth](https://next-auth.js.org) : For user authentication.
34-
- [Prisma](https://www.prisma.io) : Next-generation ORM, it provides a clean and type-safe API for submitting database queries
35-
- [Tailwind CSS](https://tailwindcss.com) : A utility-first CSS framework for rapid UI development.
32+
- [Next.js](https://nextjs.org): A React framework for building server-side rendered and statically generated applications.
33+
- [NextAuth](https://next-auth.js.org): For user authentication.
34+
- [Prisma](https://www.prisma.io): Next-generation ORM, it provides a clean and type-safe API for submitting database queries.
35+
- [Tailwind CSS](https://tailwindcss.com): A utility-first CSS framework for rapid UI development.
3636
- [TypeScript](https://www.typescriptlang.org): A typed superset of JavaScript that provides enhanced tooling and developer productivity.
3737

3838
## Contribution :raised_hands:
@@ -60,18 +60,20 @@ A big thank you to all the developers who have helped shape Code Racer into what
6060

6161
## Contact :mailbox:
6262

63-
If you have any questions, suggestions, or feedback regarding Code Racer, please feel free to reach out to us on the [WebDevCody discord server](https://discord.gg/4kGbBaa).
63+
If you have any questions, suggestions, or feedback regarding Code Racer, please feel free to reach out to us at in the WebDevCody [discord](https://discord.gg/4kGbBaa) server.
6464

6565
Happy coding and enjoy the race!
6666

6767
## Related Youtube Videos & Progress :movie_camera:
6868

6969
1. [Community Project Announcement Video](https://www.youtube.com/watch?v=-n6tV3RPjGc)
7070
2. [First Q&A Livestream and Community Project Live Coding Session](https://www.youtube.com/watch?v=BQXXBsHXfak)
71+
3. [How to contribute to open source projects (our community project walkthrough)](https://www.youtube.com/watch?v=dLRA1lffWBw)
72+
4. [You need to write tests when this starts to happen](https://www.youtube.com/watch?v=PzrhclEQp-M)
7173

7274
<details>
7375
<summary>
74-
<h2>How To(s) - A newbie section</h2>
76+
<h2>How To(s) - A newbie section</h2>
7577
</summary>
7678

7779
### Check the logs of Post

package-lock.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/app/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"class-variance-authority": "^0.6.1",
5151
"clsx": "^1.2.1",
5252
"cmdk": "^0.2.0",
53+
"lodash": "^4.17.21",
5354
"lucide-react": "^0.259.0",
5455
"next": "13.4.9",
5556
"next-auth": "^4.22.1",
@@ -81,6 +82,7 @@
8182
},
8283
"devDependencies": {
8384
"@flydotio/dockerfile": "^0.3.3",
85+
"@types/lodash": "^4.14.197",
8486
"@types/node": "^20.4.1",
8587
"@types/react": "^18.2.15",
8688
"@types/react-dom": "18.2.6",

packages/app/src/app/error.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"use client";
2+
3+
export default function Error() {
4+
return <div>Something went wrong</div>;
5+
}

packages/app/src/app/leaderboard/loaders.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { prisma } from "@/lib/prisma";
2+
import { omit } from "lodash";
23

34
export async function getUsersWithResultCounts({
45
take,
@@ -17,7 +18,13 @@ export async function getUsersWithResultCounts({
1718
_count: order,
1819
},
1920
},
20-
include: {
21+
select: {
22+
id: true,
23+
image: true,
24+
averageAccuracy: true,
25+
averageCpm: true,
26+
name: true,
27+
topLanguages: true,
2128
results: true,
2229
},
2330
where: {
@@ -28,11 +35,19 @@ export async function getUsersWithResultCounts({
2835
},
2936
},
3037
});
38+
39+
// return users.map(omitSensitiveUserFields);
3140
}
3241

3342
export async function getAllUsersWithResults() {
34-
return await prisma.user.findMany({
35-
include: {
43+
const users = await prisma.user.findMany({
44+
select: {
45+
id: true,
46+
averageAccuracy: true,
47+
averageCpm: true,
48+
image: true,
49+
name: true,
50+
topLanguages: true,
3651
results: true,
3752
},
3853
where: {
@@ -43,6 +58,7 @@ export async function getAllUsersWithResults() {
4358
},
4459
},
4560
});
61+
return users;
4662
}
4763

4864
export async function getUsersWithResults({
@@ -56,13 +72,19 @@ export async function getUsersWithResults({
5672
sortBy: string;
5773
order: "asc" | "desc" | undefined;
5874
}) {
59-
return await prisma.user.findMany({
75+
const users = await prisma.user.findMany({
6076
take,
6177
skip,
6278
orderBy: {
6379
[sortBy]: order,
6480
},
65-
include: {
81+
select: {
82+
id: true,
83+
image: true,
84+
averageAccuracy: true,
85+
averageCpm: true,
86+
name: true,
87+
topLanguages: true,
6688
results: true,
6789
},
6890
where: {
@@ -73,6 +95,8 @@ export async function getUsersWithResults({
7395
},
7496
},
7597
});
98+
99+
return users;
76100
}
77101

78102
export async function getTotalUsers() {

packages/app/src/app/leaderboard/page.tsx

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Heading } from "@/components/ui/heading";
22
import { getCurrentUser } from "@/lib/session.js";
3-
import { Result, User } from "@prisma/client";
3+
import { User } from "@prisma/client";
44
import {
55
getAllUsersWithResults,
66
getTotalUsers,
@@ -11,8 +11,7 @@ import {
1111
import { UserRankings } from "./user-rankings";
1212
import { UsersTable } from "./users-table";
1313
import { sortFilters } from "./sort-filters";
14-
15-
type UserWithResults = User & { results: Result[] };
14+
import { UserWithResults } from "./types";
1615

1716
function setUsersRankByValue({
1817
fieldName,
@@ -48,22 +47,16 @@ function setUsersRankByValue({
4847
if (prev && current.value == prev.value) {
4948
userRanks[current.id][fieldName]["shared"] = true;
5049
}
51-
50+
5251
if (next === undefined || current.value === next.value) {
5352
return;
5453
}
5554

5655
currentRank++;
5756
});
58-
59-
6057
}
6158

62-
function calculateUsersRank({
63-
allUsers,
64-
}: {
65-
allUsers: UserWithResults[];
66-
}) {
59+
function calculateUsersRank(allUsers: UserWithResults[]) {
6760
// userRanks stores rank of all users in all category (avgCPM, avgAcc, totalRaces)
6861
/* {
6962
_userID_ : {
@@ -94,7 +87,7 @@ function calculateUsersRank({
9487
// Based on Race Played:
9588
setUsersRankByValue({
9689
fieldName: sortFilters.RacePlayed,
97-
values: allUsers.map((u) => ({ id: u.id, value: u.results.length })),
90+
values: allUsers.map((u) => ({ id: u.id, value: u.results!.length })),
9891
userRanks,
9992
});
10093

@@ -138,7 +131,7 @@ export default async function LeaderboardPage({
138131
typeof sort === "string"
139132
? (sort.split(".") as [
140133
keyof User | sortFilters.RacePlayed | undefined,
141-
"asc" | "desc" | undefined,
134+
"asc" | "desc" | undefined
142135
])
143136
: [];
144137

@@ -173,18 +166,21 @@ export default async function LeaderboardPage({
173166
const allUsers = await getAllUsersWithResults();
174167
const currUserIsRanked =
175168
user !== undefined && allUsers.some((u) => u.id === user.id);
176-
177-
const userRanks = calculateUsersRank({
178-
allUsers: allUsers,
179-
});
169+
170+
const userRanks = calculateUsersRank(allUsers);
180171

181172
return (
182173
<div className="pt-12">
183174
<Heading title="Leaderboard" description="Find your competition" />
184175
{currUserIsRanked ? (
185176
<UserRankings currentUserRankDetail={userRanks[user.id]} />
186177
) : null}
187-
<UsersTable data={users} pageCount={pageCount} ranks={userRanks} field={sortBy}/>
178+
<UsersTable
179+
data={users}
180+
pageCount={pageCount}
181+
ranks={userRanks}
182+
field={sortBy}
183+
/>
188184
</div>
189185
);
190186
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Result, User } from "@prisma/client";
2+
3+
export type UserWithResults = Pick<
4+
User,
5+
"id" | "averageAccuracy" | "averageCpm" | "name" | "topLanguages" | "image"
6+
> & {
7+
results: Result[];
8+
};

0 commit comments

Comments
 (0)