Skip to content

Commit c9703b3

Browse files
authored
Merge branch 'webdevcody:main' into main
2 parents 2e54e9f + 194a376 commit c9703b3

File tree

7 files changed

+47
-20
lines changed

7 files changed

+47
-20
lines changed

src/app/race/RaceTracker.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default function RaceTracker({
1818
inputLength,
1919
user,
2020
}: RaceTrackerProps) {
21-
const progress = (inputLength / codeLength) * 100;
21+
const progress = ((inputLength / codeLength) * 100) % 100;
2222

2323
return (
2424
<div className="relative mb-5 flex items-center">

src/app/race/no-snippet.tsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@ interface NoSnippetProps {
99
}
1010

1111
export default function NoSnippet({ message, language }: NoSnippetProps) {
12-
const formattedLanguage = snippetLanguages.find(snippet => snippet.value === language)?.label ?? language;
12+
const formattedLanguage =
13+
snippetLanguages.find((snippet) => snippet.value === language)?.label ??
14+
language;
1315
return (
1416
<div className="flex flex-col gap-4 justify-start">
15-
<Heading title={`No ${formattedLanguage} snippet found`} description={message}/>
17+
<Heading
18+
title={`No ${formattedLanguage} snippet found`}
19+
description={message}
20+
/>
1621
<Link href={"/add-snippet"}>
1722
<Button>Create New Snippet</Button>
1823
</Link>
1924
</div>
20-
)
25+
);
2126
}

src/app/result/page.tsx

+5-7
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,11 @@ export default async function ResultsChart({
8181
</Button>
8282
</div>
8383
<div className="my-4">
84-
{user && (
85-
<Voting
86-
snippetId={searchParams.snippetId}
87-
userId={user.id}
88-
usersVote={usersVote ?? undefined}
89-
/>
90-
)}
84+
<Voting
85+
snippetId={searchParams.snippetId}
86+
userId={user?.id ?? undefined}
87+
usersVote={usersVote ?? undefined}
88+
/>
9189
</div>
9290
<div className="flex items-center justify-center space-x-2">
9391
<Badge variant="outline">

src/app/result/voting.tsx

+21-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { toast } from "@/components/ui/use-toast";
1414
import { catchError, cn } from "@/lib/utils";
1515

1616
interface VotingProps {
17-
userId: User["id"];
17+
userId: User["id"] | undefined;
1818
snippetId: Snippet["id"];
1919
usersVote?: SnippetVote;
2020
}
@@ -33,6 +33,7 @@ export function Voting({ userId, snippetId, usersVote }: VotingProps) {
3333
disabled={isPending}
3434
onClick={() => {
3535
startTransition(async () => {
36+
if (userId) {
3637
try {
3738
if (usersVote?.type === "UP") {
3839
await deleteVoteAction({ snippetId });
@@ -48,6 +49,13 @@ export function Voting({ userId, snippetId, usersVote }: VotingProps) {
4849
} catch (err) {
4950
catchError(err);
5051
}
52+
} else {
53+
toast({
54+
title: "Warning",
55+
description: "You should sign in first to vote.",
56+
variant: "middle",
57+
});
58+
}
5159
});
5260
}}
5361
>
@@ -63,6 +71,7 @@ export function Voting({ userId, snippetId, usersVote }: VotingProps) {
6371
disabled={isPending}
6472
onClick={() => {
6573
startTransition(async () => {
74+
if (userId) {
6675
try {
6776
if (usersVote?.type === "DOWN") {
6877
await deleteVoteAction({
@@ -76,11 +85,18 @@ export function Voting({ userId, snippetId, usersVote }: VotingProps) {
7685
title: "Success.",
7786
description:
7887
"Thanks for your feedback! We will consider it.",
79-
variant: "default",
80-
});
88+
variant: "default",
89+
});
90+
}
91+
} catch (err) {
92+
catchError(err);
8193
}
82-
} catch (err) {
83-
catchError(err);
94+
} else {
95+
toast({
96+
title: "Warning",
97+
description: "You should sign in first to vote.",
98+
variant: "middle",
99+
});
84100
}
85101
});
86102
}}

src/components/header.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export async function Header() {
1414
<div className="flex-1">
1515
<MainNav items={siteConfig.getHeaderLinks(!!user)} />
1616
</div>
17-
<MobileNav />
17+
<MobileNav user={user} />
1818
<nav className="items-center hidden space-x-4 md:flex">
1919
<UserDropdown user={user} />
2020
<ModeToggle />

src/components/mobile-nav.tsx

+10-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,16 @@ import Link, { LinkProps } from "next/link";
1212
import { ModeToggle } from "./mode-toggle";
1313
import { useRouter } from "next/navigation";
1414
import { useSession } from "next-auth/react";
15+
import type { User } from "next-auth";
16+
import { UserRole } from "@prisma/client";
1517

16-
export function MobileNav() {
18+
interface MobileNavProps {
19+
user?: User & {
20+
role: UserRole;
21+
};
22+
}
23+
24+
export function MobileNav({ user }: MobileNavProps) {
1725
const [open, setOpen] = useState(false);
1826
const isLoggedIn = !!useSession().data;
1927

@@ -32,7 +40,7 @@ export function MobileNav() {
3240
<SheetContent side="right" className="w-[300px] sm:w-[540px]">
3341
<ScrollArea className="my-4 h-[calc(100vh-9rem)] pb-10">
3442
<div className="flex flex-col items-center justify-center gap-10 py-2">
35-
<UserDropdown />
43+
<UserDropdown user={user} />
3644
<nav className="flex flex-col items-center justify-center flex-1 space-y-4">
3745
{siteConfig.getHeaderLinks(isLoggedIn).map((item) => (
3846
<MobileLink

src/components/user-dropdown.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import { signOut, useSession } from "next-auth/react";
3+
import { signOut } from "next-auth/react";
44
import Image from "next/image";
55
import Link from "next/link";
66
import { Icons } from "./icons";

0 commit comments

Comments
 (0)