Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

Feat/tooltips and lints (#279)

Sean Boultcff9b7f4c226
diff --git a/src/app/admin/report/[id]/page.tsx b/src/app/admin/report/[id]/page.tsx
index ee8c5c13..280a8ab9 100644
--- a/src/app/admin/report/[id]/page.tsx
+++ b/src/app/admin/report/[id]/page.tsx
@@ -1,4 +1,3 @@
-import { prisma } from '~/server/db';
import { redirect } from 'next/navigation';
import Text from '~/components/ui/typography/typography';
import Link from 'next/link';
@@ -23,19 +22,8 @@ const Report = async function (props: Props) {
return redirect('/admin');
}
// Grab the items.
- const {
- author,
- challenge,
- derogatory,
- id,
- moderatorId,
- moderator,
- createdAt,
- updatedAt,
- unclear,
- text,
- status,
- } = await getChallenge(idNum);
+ const { author, challenge, derogatory, id, moderatorId, moderator, unclear, text } =
+ await getChallenge(idNum);
return (
<div className="container ">
diff --git a/src/app/admin/report/[id]/report.action.ts b/src/app/admin/report/[id]/report.action.ts
index 8623c115..d6d2cf31 100644
--- a/src/app/admin/report/[id]/report.action.ts
+++ b/src/app/admin/report/[id]/report.action.ts
@@ -14,8 +14,8 @@ export async function getReports() {
});
const otherReports = await prisma.report.findMany({
where: {
- type: {not: 'CHALLENGE'},
- }
+ type: { not: 'CHALLENGE' },
+ },
});
return {
challengeReports,
diff --git a/src/app/admin/report/page.tsx b/src/app/admin/report/page.tsx
index 73d88dfa..3b1814ca 100644
--- a/src/app/admin/report/page.tsx
+++ b/src/app/admin/report/page.tsx
@@ -1,4 +1,3 @@
-import { getChallengeReports } from '~/components/admin/admin.actions';
import React from 'react';
import { prisma } from '~/server/db';
import { ReportType } from '@prisma/client';
@@ -28,51 +27,46 @@ const f = cva('border p-4 rounded-xl', {
[ReportType.USER]: 'border-green-300',
[ReportType.COMMENT]: 'border-yellow-400',
[ReportType.SOLUTION]: 'border-pink-300',
- }
+ },
},
defaultVariants: {
- type: 'USER'
- }
+ type: 'USER',
+ },
});
export default async function ReportPage() {
const reports = await getReports();
const bob = reports.reduce((all, cur) => {
- if(!all[cur.type]) all[cur.type] = [];
+ if (!all[cur.type]) all[cur.type] = [];
all[cur.type].push(cur);
return all;
- }, {} as Record<ReportType, (typeof reports[0])[]>);
-
+ }, {} as Record<ReportType, (typeof reports)[0][]>);
+
return (
<div className="container">
- {
- Object.entries(bob)
- .map(([key, reports]) => {
- return (
- <div key={`types-${key}`}>
- <header className="mb-4">
- <Text intent="h1">
- {key}
- </Text>
- </header>
- <section>
- {
- reports.map(report => (
- <div className={f({ type: report.type })} key={`report-${report.id}`}>
- Reported By:
- {report.reporter.name} <br />
- {report.type === 'CHALLENGE' && report.challenge && report.challenge.name}
- <br />User being reported:
- {report.type === 'USER' && report.user && report.user.name}<br />
- </div>
- ))
- }
- </section>
- </div>
- )
- })
- }
+ {Object.entries(bob).map(([key, reports]) => {
+ return (
+ <div key={`types-${key}`}>
+ <header className="mb-4">
+ <Text intent="h1">{key}</Text>
+ </header>
+ <section>
+ {reports.map((report) => (
+ <div className={f({ type: report.type })} key={`report-${report.id}`}>
+ Reported By:
+ {report.reporter.name} <br />
+ {report.type === 'CHALLENGE' && report.challenge && report.challenge.name}
+ <br />
+ User being reported:
+ {report.type === 'USER' && report.user && report.user.name}
+ <br />
+ </div>
+ ))}
+ </section>
+ </div>
+ );
+ })}
</div>
);
}
diff --git a/src/app/challenge/[id]/left-wrapper.tsx b/src/app/challenge/[id]/left-wrapper.tsx
index dcdbaf71..efc80c9b 100644
--- a/src/app/challenge/[id]/left-wrapper.tsx
+++ b/src/app/challenge/[id]/left-wrapper.tsx
@@ -28,10 +28,7 @@ export function LeftWrapper({ challengeId, children }: Props) {
}, [pathname]);
return (
- <Tabs
- defaultValue={selectedTab}
- className="flex h-full w-full flex-col overflow-hidden"
- >
+ <Tabs defaultValue={selectedTab} className="flex h-full w-full flex-col overflow-hidden">
<TabsList className="sticky top-0 z-10 grid h-auto w-full grid-cols-3 rounded-none rounded-tl-2xl rounded-tr-xl border-b border-zinc-300 bg-background/90 backdrop-blur-sm dark:border-zinc-700 dark:bg-muted/90">
<TabsTrigger
value="description"
diff --git a/src/app/challenge/[id]/solutions/[solutionId]/page.tsx b/src/app/challenge/[id]/solutions/[solutionId]/page.tsx
index 55ca0da1..b1be1eea 100644
--- a/src/app/challenge/[id]/solutions/[solutionId]/page.tsx
+++ b/src/app/challenge/[id]/solutions/[solutionId]/page.tsx
@@ -23,15 +23,14 @@ async function getSolution(solutionId: string) {
include: {
challenge: true,
user: true,
-
},
});
const f = await prisma.comment.findMany({
where: {
rootType: 'SOLUTION',
- rootSolutionId: +solutionId
- }
+ rootSolutionId: +solutionId,
+ },
});
return {
diff --git a/src/components/admin/admin.actions.tsx b/src/components/admin/admin.actions.tsx
index 28ce02ec..00b78384 100644
--- a/src/components/admin/admin.actions.tsx
+++ b/src/components/admin/admin.actions.tsx
@@ -7,26 +7,31 @@ import { prisma } from '~/server/db';
export type AdminReportDetails = Awaited<ReturnType<typeof getChallengeReports>>;
// FML this was obnoxious to do
-export type ChallengeInfo = {type: 'CHALLENGE'} & Omit<Report, 'id' | 'userId' | 'type' | 'status'>;
-export type UserInfo = {type: 'USER'} & Omit<Report, 'id' | 'challengeId' | 'type' | 'status'>;
+export type ChallengeInfo = { type: 'CHALLENGE' } & Omit<
+ Report,
+ 'id' | 'userId' | 'type' | 'status'
+>;
+export type UserInfo = { type: 'USER' } & Omit<Report, 'id' | 'challengeId' | 'type' | 'status'>;
/**
- *
+ *
* @param info the info needed to create the Report instance
* @param issues any issues types that are connected to this.
* @returns the newly created report information.
*/
-export async function addReport(info: ChallengeInfo | UserInfo, issues: Prisma.ReportIssueCreateManyReportInput[] = [{ type: 'OTHER' }]) {
-
+export async function addReport(
+ info: ChallengeInfo | UserInfo,
+ issues: Prisma.ReportIssueCreateManyReportInput[] = [{ type: 'OTHER' }],
+) {
return prisma.report.create({
data: {
status: 'PENDING',
...info,
issues: {
createMany: {
- data: issues
+ data: issues,
},
- }
+ },
},
});
}
diff --git a/src/components/challenge/comments/comment.action.ts b/src/components/challenge/comments/comment.action.ts
index 3281aef0..dfe65bc8 100644
--- a/src/components/challenge/comments/comment.action.ts
+++ b/src/components/challenge/comments/comment.action.ts
@@ -4,25 +4,31 @@ import { type Prisma } from '@prisma/client';
import { getServerAuthSession } from '~/server/auth';
import { prisma } from '~/server/db';
-export type ChallengeComment = Omit<Prisma.CommentCreateManyInput, 'rootType' | 'rootSolutionId' | 'userId' > & { rootType: 'CHALLENGE' };
+export type ChallengeComment = Omit<
+ Prisma.CommentCreateManyInput,
+ 'rootType' | 'rootSolutionId' | 'userId'
+> & { rootType: 'CHALLENGE' };
-export type SolutionComment = Omit<Prisma.CommentCreateManyInput, 'rootType' | 'rootChallengeId' | 'userId'> & { rootType: 'SOLUTION' }
+export type SolutionComment = Omit<
+ Prisma.CommentCreateManyInput,
+ 'rootType' | 'rootChallengeId' | 'userId'
+> & { rootType: 'SOLUTION' };
/**
- *
+ *
* @param comment a Challenge or Solution-based comment.
* @returns the prisma create response.
*/
export async function addComment(comment: ChallengeComment | SolutionComment) {
const session = await getServerAuthSession();
- if(!session?.user.id) return 'unauthorized';
- if(comment.text.length === 0) return 'text_is_empty';
+ if (!session?.user.id) return 'unauthorized';
+ if (comment.text.length === 0) return 'text_is_empty';
return await prisma.comment.create({
data: {
...comment,
- userId: session.user.id
- }
+ userId: session.user.id,
+ },
});
}
diff --git a/src/components/challenge/comments/comment.tsx b/src/components/challenge/comments/comment.tsx
index 1f23972f..eac2eb43 100644
--- a/src/components/challenge/comments/comment.tsx
+++ b/src/components/challenge/comments/comment.tsx
@@ -1,6 +1,5 @@
'use client';
import { Trash2, Reply, Share } from 'lucide-react';
-import { useState } from 'react';
import { z } from 'zod';
import type { ChallengeRouteData } from '~/app/challenge/[id]/getChallengeRouteData';
import { getRelativeTime } from '~/utils/relativeTime';
@@ -36,8 +35,6 @@ const commentReportSchema = z
export type CommentReportSchemaType = z.infer<typeof commentReportSchema>;
const Comment = ({ comment }: CommentProps) => {
- const [dialogOpen, setDialogOpen] = useState(false);
-
async function copyPathNotifyUser() {
try {
await copyCommentUrlToClipboard();
@@ -106,7 +103,7 @@ const Comment = ({ comment }: CommentProps) => {
<ReportDialog reportType="COMMENT" commentId={comment.id}>
<button
onClick={() => {
- setDialogOpen(true);
+ // do somehting
}}
className="flex cursor-pointer items-center text-sm text-neutral-400 duration-200 hover:text-neutral-500 hover:underline dark:text-neutral-600 dark:hover:text-neutral-500"
>
diff --git a/src/components/challenge/comments/getCommentRouteData.ts b/src/components/challenge/comments/getCommentRouteData.ts
index 81588252..70d807fd 100644
--- a/src/components/challenge/comments/getCommentRouteData.ts
+++ b/src/components/challenge/comments/getCommentRouteData.ts
@@ -9,7 +9,7 @@ interface QueryParams {
lastCursor?: number;
}
-export async function getInfiniteComments({ challengeId, take = 10, lastCursor }: QueryParams) {
+export async function getInfiniteComments({ challengeId, lastCursor }: QueryParams) {
const results = await prisma.comment.findMany({
where: {
rootType: 'CHALLENGE',
@@ -26,22 +26,26 @@ export async function getInfiniteComments({ challengeId, take = 10, lastCursor }
},
include: {
user: true,
- }
+ },
});
const last = results.at(-1);
- const hasNextPage = last && last.id ?
- await prisma.comment.findMany({
- where: {
- rootChallengeId: challengeId,
- }
- }).then(f => f.length > 0) : false;
-
+ const hasNextPage =
+ last && last.id
+ ? await prisma.comment
+ .findMany({
+ where: {
+ rootChallengeId: challengeId,
+ },
+ })
+ .then((f) => f.length > 0)
+ : false;
+
return {
data: results,
metaData: {
lastCursor: last ? last.id : null,
hasNextPage,
- }
+ },
};
}
diff --git a/src/components/challenge/description/index.tsx b/src/components/challenge/description/index.tsx
index 94fef268..9c40bc08 100644
--- a/src/components/challenge/description/index.tsx
+++ b/src/components/challenge/description/index.tsx
@@ -7,18 +7,17 @@ import { useSession } from 'next-auth/react';
import { useRouter } from 'next/navigation';
import { useRef, useState } from 'react';
-import { useForm } from 'react-hook-form';
-
import { Bookmark as BookmarkIcon, Share, ThumbsUp } from 'lucide-react';
import { Button } from '~/components/ui/button';
import { UserBadge } from '~/components/ui/user-badge';
import {
Dialog,
- DialogContent, DialogHeader,
+ DialogContent,
+ DialogHeader,
DialogTitle,
- DialogTrigger
+ DialogTrigger,
} from '~/components/ui/dialog';
-import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '~/components/ui/tooltip';
+import { Tooltip, TooltipContent, TooltipTrigger } from '~/components/ui/tooltip';
import { TypographyH3 } from '~/components/ui/typography/h3';
import { DifficultyBadge } from '~/components/ui/difficulty-badge';
import { ActionMenu } from '~/components/ui/action-menu';
@@ -73,69 +72,65 @@ export function Description({ challenge }: Props) {
}, 500),
).current;
- const form = useForm<FormValues>({
- defaultValues: {
- comments: '',
- other: false,
- examples: false,
- derogatory: false,
- },
- });
-
return (
- <div className="custom-scrollable-element overflow-y-auto h-full px-4 pt-3 pb-36">
+ <div className="custom-scrollable-element h-full overflow-y-auto px-4 pb-36 pt-3">
{/* NOTE: collapse this element */}
<div className="flex items-center gap-4">
<TypographyH3 className="mb-2 mr-auto max-w-[75%] items-center truncate text-2xl font-bold">
{challenge.name}
</TypographyH3>
{/* TODO: split this mess into components, make buttons have bigger horizontal padding and decrease the gap value on container above */}
- <TooltipProvider>
- <Tooltip delayDuration={0.05} open={session?.data?.user?.id ? false : undefined}>
- <TooltipTrigger asChild>
- <span>
- <Button
- variant="ghost"
- className="p-1"
- disabled={!session?.data?.user?.id}
- onClick={() => {
- let shouldBookmark = false;
- if (hasBookmarked) {
- shouldBookmark = false;
- setHasBookmarked(false);
- } else {
- shouldBookmark = true;
- setHasBookmarked(true);
- }
- debouncedBookmark(
- challenge.id,
- session?.data?.user?.id as string,
- shouldBookmark,
- )?.catch((e) => {
- console.error(e);
- });
- }}
- >
- <BookmarkIcon
- className={clsx(
- {
- 'fill-blue-500 stroke-blue-500': hasBookmarked,
- 'stroke-zinc-500': !hasBookmarked,
- },
- 'h-4 w-4 hover:stroke-zinc-400',
- )}
- />
- </Button>
- </span>
- </TooltipTrigger>
- <TooltipContent>
- <p>Login to Bookmark</p>
- </TooltipContent>
- </Tooltip>
- </TooltipProvider>
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <span>
+ <Button
+ variant="ghost"
+ className="p-1"
+ disabled={!session?.data?.user?.id}
+ onClick={() => {
+ let shouldBookmark = false;
+ if (hasBookmarked) {
+ shouldBookmark = false;
+ setHasBookmarked(false);
+ } else {
+ shouldBookmark = true;
+ setHasBookmarked(true);
+ }
+ debouncedBookmark(
+ challenge.id,
+ session?.data?.user?.id as string,
+ shouldBookmark,
+ )?.catch((e) => {
+ console.error(e);
+ });
+ }}
+ >
+ <BookmarkIcon
+ className={clsx(
+ {
+ 'fill-blue-500 stroke-blue-500': hasBookmarked,
+ 'stroke-zinc-500': !hasBookmarked,
+ },
+ 'h-4 w-4 hover:stroke-zinc-400',
+ )}
+ />
+ </Button>
+ </span>
+ </TooltipTrigger>
+ <TooltipContent>
+ <p>{session?.data?.user?.id ? 'Bookmark' : 'Login to Bookmark'}</p>
+ </TooltipContent>
+ </Tooltip>
<Dialog>
<DialogTrigger>
- <Share className="h-4 w-4 stroke-zinc-500 hover:stroke-zinc-400" />
+ <Tooltip>
+ <TooltipTrigger asChild>
+ <Share className="h-4 w-4 stroke-zinc-500 hover:stroke-zinc-400" />
+ </TooltipTrigger>
+ <TooltipContent>
+ <p>Share challenge</p>
+ </TooltipContent>
+ </Tooltip>
</DialogTrigger>
<DialogContent className="w-[200px]">
<DialogHeader>
@@ -146,7 +141,7 @@ export function Description({ challenge }: Props) {
</div>
</DialogContent>
</Dialog>
- <Tooltip delayDuration={0.05} open={session?.data?.user?.id ? false : undefined}>
+ <Tooltip>
<TooltipTrigger asChild>
<span>
<Button
@@ -198,7 +193,7 @@ export function Description({ challenge }: Props) {
</span>
</TooltipTrigger>
<TooltipContent>
- <p>Login to Upvote</p>
+ <p>{session?.data?.user?.id ? 'Upvote' : 'Login to Upvote'}</p>
</TooltipContent>
</Tooltip>
<ReportDialog reportType="CHALLENGE" challengeId={challenge.id}>
@@ -215,7 +210,6 @@ export function Description({ challenge }: Props) {
}}
/>
</ReportDialog>
-
</div>
<div className="mb-6 flex items-center gap-4">
diff --git a/src/components/challenge/solutions/getSolutionData.ts b/src/components/challenge/solutions/getSolutionData.ts
index cc3e1ac3..151a2abb 100644
--- a/src/components/challenge/solutions/getSolutionData.ts
+++ b/src/components/challenge/solutions/getSolutionData.ts
@@ -1,5 +1,5 @@
'use server';
-import { prisma } from "~/server/db";
+import { prisma } from '~/server/db';
export interface SolutionCommentQueryParams {
solutionId: number;
@@ -7,25 +7,25 @@ export interface SolutionCommentQueryParams {
lastCursor?: number;
}
-export async function getInfiniteComments(
- { solutionId, take = 10, lastCursor }: SolutionCommentQueryParams,
-) {
+export async function getInfiniteComments({
+ solutionId,
+ take = 10,
+ lastCursor,
+}: SolutionCommentQueryParams) {
const results = await prisma.comment.findMany({
where: {
- rootType: "SOLUTION",
+ rootType: 'SOLUTION',
rootSolutionId: solutionId,
},
take,
- ...(
- lastCursor && {
- skip: 1,
- cursor: {
- id: lastCursor,
- },
- }
- ),
+ ...(lastCursor && {
+ skip: 1,
+ cursor: {
+ id: lastCursor,
+ },
+ }),
orderBy: {
- createdAt: "desc",
+ createdAt: 'desc',
},
include: {
user: true,
@@ -33,24 +33,27 @@ export async function getInfiniteComments(
});
const last = results.at(-1);
- const hasNextPage = last && last.id
- ? await prisma.comment.findMany({
- where: {
- rootSolutionId: solutionId,
- },
- skip: 1,
- take: 1,
- cursor: {
- id: last.id,
- },
- }).then((f) => f.length > 0)
- : false;
-
+ const hasNextPage =
+ last && last.id
+ ? await prisma.comment
+ .findMany({
+ where: {
+ rootSolutionId: solutionId,
+ },
+ skip: 1,
+ take: 1,
+ cursor: {
+ id: last.id,
+ },
+ })
+ .then((f) => f.length > 0)
+ : false;
+
return {
data: results,
metaData: {
- lastCursor: last? last.id : null,
+ lastCursor: last ? last.id : null,
hasNextPage,
- }
+ },
};
}
diff --git a/src/components/challenge/solutions/index.tsx b/src/components/challenge/solutions/index.tsx
index 8725efcf..a79bcfdd 100644
--- a/src/components/challenge/solutions/index.tsx
+++ b/src/components/challenge/solutions/index.tsx
@@ -31,20 +31,20 @@ export function Solutions({ challenge }: Props) {
{challenge.sharedSolution.length !== 0 ? (
<>
{(loggedInUserHasSolution || !session?.data?.user) && (
- <div className="absolute right-0 top-0 w-full flex justify-end border-b border-zinc-300 bg-background/70 p-2 backdrop-blur-sm dark:border-zinc-700 dark:bg-muted/70">
+ <div className="absolute right-0 top-0 flex w-full justify-end border-b border-zinc-300 bg-background/70 p-2 backdrop-blur-sm dark:border-zinc-700 dark:bg-muted/70">
<SubmitSolution setView={setView} />
</div>
)}
- <div className="h-full pt-12 overflow-y-auto custom-scrollable-element">
+ <div className="custom-scrollable-element h-full overflow-y-auto pt-12">
{challenge?.sharedSolution.map((solution) => (
<SolutionRow
- key={solution.id}
- solution={solution}
- handleClick={() => {
- setView('details');
- }}
+ key={solution.id}
+ solution={solution}
+ handleClick={() => {
+ setView('details');
+ }}
/>
- ))}
+ ))}
</div>
</>
) : (
@@ -73,7 +73,7 @@ function SolutionRow({
className="group flex cursor-pointer flex-col gap-2 p-4 duration-300 hover:bg-neutral-100 dark:hover:bg-zinc-700/50"
href={`/challenge/${solution.challengeId}/solutions/${solution.id}`}
>
- <h3 className="font-bold truncate">{solution.title}</h3>
+ <h3 className="truncate font-bold">{solution.title}</h3>
<div className="flex items-center gap-1 text-neutral-600 dark:text-neutral-400">
<UserBadge username={solution.user?.name ?? ''} />
<div className="mr-auto text-sm text-neutral-500">
diff --git a/src/components/challenge/solutions/solution-detail.tsx b/src/components/challenge/solutions/solution-detail.tsx
index c245ac29..61b0c720 100644
--- a/src/components/challenge/solutions/solution-detail.tsx
+++ b/src/components/challenge/solutions/solution-detail.tsx
@@ -30,12 +30,12 @@ export function SolutionDetails({ solution }: Props) {
return (
<div className="relative flex h-full flex-col">
- <div className="sticky right-0 top-0 w-full flex border-b border-zinc-300 bg-background/90 p-2 backdrop-blur-sm dark:border-zinc-700 dark:bg-muted/90">
+ <div className="sticky right-0 top-0 flex w-full border-b border-zinc-300 bg-background/90 p-2 backdrop-blur-sm dark:border-zinc-700 dark:bg-muted/90">
<Link href={`/challenge/${solution.challengeId}/solutions`}>
<X size={20} className="stroke-gray-500 hover:stroke-gray-400" />
</Link>
</div>
- <div className="flex-1 overflow-y-auto custom-scrollable-element px-4 py-3">
+ <div className="custom-scrollable-element flex-1 overflow-y-auto px-4 py-3">
<div className="mb-5 flex flex-col gap-3">
<div className="flex items-center gap-2">
<Avatar>
@@ -51,7 +51,7 @@ export function SolutionDetails({ solution }: Props) {
key: 'report',
label: 'Report',
icon: 'Flag',
- }
+ },
]}
onChange={() => {
// do nothing
diff --git a/src/components/challenge/solutions/solution-editor.tsx b/src/components/challenge/solutions/solution-editor.tsx
index aa54932f..bf3c70d8 100644
--- a/src/components/challenge/solutions/solution-editor.tsx
+++ b/src/components/challenge/solutions/solution-editor.tsx
@@ -84,8 +84,8 @@ export function SolutionEditor({ dismiss, challenge }: Props) {
return (
<Form {...form}>
{/* eslint-disable-next-line @typescript-eslint/no-misused-promises */}
- <form className="flex h-full relative flex-col" onSubmit={form.handleSubmit(onSubmit)}>
- <div className="sticky right-0 top-0 w-full z-10 flex items-center justify-between gap-2 border-b border-zinc-300 bg-background/90 bg-opacity-20 p-1 pr-2 backdrop-blur-sm dark:border-zinc-700 dark:bg-muted/90">
+ <form className="relative flex h-full flex-col" onSubmit={form.handleSubmit(onSubmit)}>
+ <div className="sticky right-0 top-0 z-10 flex w-full items-center justify-between gap-2 border-b border-zinc-300 bg-background/90 bg-opacity-20 p-1 pr-2 backdrop-blur-sm dark:border-zinc-700 dark:bg-muted/90">
<div className="flex-1">
<FormField
control={form.control}
diff --git a/src/components/challenge/submissions/index.tsx b/src/components/challenge/submissions/index.tsx
index 0c3ac190..55a467c3 100644
--- a/src/components/challenge/submissions/index.tsx
+++ b/src/components/challenge/submissions/index.tsx
@@ -26,9 +26,9 @@ export function Submissions({ submissions }: Props) {
return submissions.filter(predicate);
}, [selectedStatus, submissions]);
return (
- <div className="h-full relative">
+ <div className="relative h-full">
{submissions.length !== 0 ? (
- <div className="absolute w-full right-0 top-0 z-10 flex gap-2 border-b border-zinc-300 bg-background/70 p-2 px-4 backdrop-blur-sm dark:border-zinc-700 dark:bg-muted/70">
+ <div className="absolute right-0 top-0 z-10 flex w-full gap-2 border-b border-zinc-300 bg-background/70 p-2 px-4 backdrop-blur-sm dark:border-zinc-700 dark:bg-muted/70">
<div
className={`flex cursor-pointer gap-2 rounded-lg px-4 py-1 duration-300 ${
selectedStatus === 'all'
@@ -65,7 +65,7 @@ export function Submissions({ submissions }: Props) {
<NoSubmissions />
)}
- <ul className="overflow-y-auto pt-12 h-full custom-scrollable-element flex flex-col">
+ <ul className="custom-scrollable-element flex h-full flex-col overflow-y-auto pt-12">
{filteredSubmissions.map((submission) => {
return (
<SubmissionRow
diff --git a/src/components/create/explore-card-inputs.tsx b/src/components/create/explore-card-inputs.tsx
index ced6a828..9e9edbd6 100644
--- a/src/components/create/explore-card-inputs.tsx
+++ b/src/components/create/explore-card-inputs.tsx
@@ -1,15 +1,10 @@
'use client';
// TODO: unify this with the explore card into single component (maybe? idk how that'd work, too many changes)
import { MessageCircle, ThumbsUp } from 'lucide-react';
-
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '../ui/card';
-
import { getRelativeTime } from '~/utils/relativeTime';
-
import { Select, SelectContent, SelectItem, SelectTrigger } from '~/components/ui/select';
-
import { type Difficulty } from '@prisma/client';
-import { useState } from 'react';
import { Button } from '../ui/button';
import { DifficultyBadge } from '../ui/difficulty-badge';
@@ -41,10 +36,6 @@ const ExploreCardInputs = ({
shortDescription,
setShortDescription,
}: Props) => {
- const [isPreviewing, setIsPreviewing] = useState({
- shortDescription: false,
- });
-
return (
<Card
className={`overflow-hidden duration-300
diff --git a/src/components/explore/explore-card.tsx b/src/components/explore/explore-card.tsx
index 5962a1ee..d2485fc7 100644
--- a/src/components/explore/explore-card.tsx
+++ b/src/components/explore/explore-card.tsx
@@ -4,7 +4,6 @@ import { getRelativeTime } from '~/utils/relativeTime';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '../ui/card';
import { type ExploreChallengeData } from './';
import { DifficultyBadge } from '../ui/difficulty-badge';
-import { Button } from '../ui/button';
interface ExploreCardProps {
challenge: Pick<
diff --git a/src/components/landing/features.tsx b/src/components/landing/features.tsx
index 010c8a4a..7dbbfcee 100644
--- a/src/components/landing/features.tsx
+++ b/src/components/landing/features.tsx
@@ -1,5 +1,2 @@
-const Features = () => (
- <>
- </>
-)
-export default Features
\ No newline at end of file
+const Features = () => <></>;
+export default Features;
diff --git a/src/components/report/index.tsx b/src/components/report/index.tsx
index 8f35881d..75f2d3c4 100644
--- a/src/components/report/index.tsx
+++ b/src/components/report/index.tsx
@@ -1,7 +1,21 @@
-import { type IssueType, ReportIssue, ReportType } from '@prisma/client';
+import { type IssueType } from '@prisma/client';
import React from 'react';
-import { type ChallengeReport, type UserReport, type CommentReport, addReport, type SolutionReport } from '~/components/report/report.action';
-import { Dialog, DialogContent, DialogHeader, DialogFooter, DialogTitle, DialogDescription, DialogTrigger } from '~/components/ui/dialog';
+import {
+ type ChallengeReport,
+ type UserReport,
+ type CommentReport,
+ addReport,
+ type SolutionReport,
+} from '~/components/report/report.action';
+import {
+ Dialog,
+ DialogContent,
+ DialogHeader,
+ DialogFooter,
+ DialogTitle,
+ DialogDescription,
+ DialogTrigger,
+} from '~/components/ui/dialog';
import { Button } from '~/components/ui/button';
import { useForm } from 'react-hook-form';
import { FormField, FormItem } from '~/components/ui/form';
@@ -12,11 +26,10 @@ import { toast } from '~/components/ui/use-toast';
export interface ReportDialogPropsBase {
triggerAsChild?: boolean;
- // reportType?: ReportType;
}
export interface ReportUserDialogProps extends ReportDialogPropsBase {
- reportType: 'USER'
+ reportType: 'USER';
userId: string;
}
@@ -35,8 +48,18 @@ export interface ReportSolutionDialogProps extends ReportDialogPropsBase {
solutionId: number;
}
-export default function ReportDialog({ children, triggerAsChild = false, reportType = 'COMMENT', ...props }: React.PropsWithChildren<ReportUserDialogProps | ReportChallengeDialogProps | ReportCommentDialogProps | ReportSolutionDialogProps>) {
- const { handleSubmit, formState: { errors }, register, control, setValue } = useForm({
+export default function ReportDialog({
+ children,
+ triggerAsChild = false,
+ reportType = 'COMMENT',
+ ...props
+}: React.PropsWithChildren<
+ | ReportUserDialogProps
+ | ReportChallengeDialogProps
+ | ReportCommentDialogProps
+ | ReportSolutionDialogProps
+>) {
+ const { handleSubmit, register, control, setValue } = useForm({
defaultValues: {
derogatory: false,
unclear: false,
@@ -45,7 +68,7 @@ export default function ReportDialog({ children, triggerAsChild = false, reportT
hateSpeech: false,
threat: false,
comments: '',
- }
+ },
});
const [show, setShow] = React.useState(false);
@@ -67,104 +90,97 @@ export default function ReportDialog({ children, triggerAsChild = false, reportT
}
return (
- <Dialog open={show} onOpenChange={e => {
- setShow(e);
- }}>
- <DialogTrigger asChild={triggerAsChild}>
- {children}
- </DialogTrigger>
+ <Dialog
+ open={show}
+ onOpenChange={(e) => {
+ setShow(e);
+ }}
+ >
+ <DialogTrigger asChild={triggerAsChild}>{children}</DialogTrigger>
<DialogContent>
- <form onSubmit={handleSubmit(async (e) => {
- let args = {} as UserReport | ChallengeReport | CommentReport | SolutionReport;
- switch(reportType) {
- case 'CHALLENGE':
- args = {
- ...props,
- text: e.comments,
- type: reportType,
- } as ChallengeReport;
- break;
- case 'COMMENT':
- args = {
- ...props,
- text: e.comments,
- type: reportType,
- } as CommentReport;
- break;
- case 'USER':
- args = {
- ...props,
- text: e.comments,
- type: reportType,
- } as UserReport;
- break;
- case 'SOLUTION':
- args = {
- ...props,
- text: e.comments,
- type: reportType,
- } as SolutionReport;
- }
+ <form
+ onSubmit={handleSubmit(async (e) => {
+ let args = {} as UserReport | ChallengeReport | CommentReport | SolutionReport;
+ switch (reportType) {
+ case 'CHALLENGE':
+ args = {
+ ...props,
+ text: e.comments,
+ type: reportType,
+ } as ChallengeReport;
+ break;
+ case 'COMMENT':
+ args = {
+ ...props,
+ text: e.comments,
+ type: reportType,
+ } as CommentReport;
+ break;
+ case 'USER':
+ args = {
+ ...props,
+ text: e.comments,
+ type: reportType,
+ } as UserReport;
+ break;
+ case 'SOLUTION':
+ args = {
+ ...props,
+ text: e.comments,
+ type: reportType,
+ } as SolutionReport;
+ }
+
+ // This shit is like... extra jank.
+ const issues = Object.entries(e).reduce((all, [key, value]) => {
+ if (key === 'comments') return all;
+ if (value)
+ all.push({
+ type: key.toUpperCase() as IssueType,
+ });
+ return all;
+ }, [] as { type: IssueType }[]);
- // This shit is like... extra jank.
- const issues = Object.entries(e).reduce((all, [key, value]) => {
- if(key === 'comments') return all;
- if(value)
- all.push({
- type: key.toUpperCase() as IssueType,
- });
- return all;
- }, [] as { type: IssueType }[]);
+ const value = await addReport({
+ ...args,
+ issues,
+ });
- const value = await addReport({
- ...args,
- issues,
- });
-
- switch(value) {
- case 'already_exists':
- toast({
- title: 'Already reported',
- description: (
- <p>You have already made a report with this information.</p>
- )
- })
- break;
- case 'created':
- toast({
- title: 'Created',
- variant: 'success',
- description: (
- <p>
- A report has been made.
- </p>
- )
- });
- break;
- case 'not_logged_in':
- toast({
- title: 'Not Logged In',
- variant: 'destructive',
- description: (
- <p>You must be logged in to make a report.</p>
- )
- })
- }
- setShow(false);
- })}>
+ switch (value) {
+ case 'already_exists':
+ toast({
+ title: 'Already reported',
+ description: <p>You have already made a report with this information.</p>,
+ });
+ break;
+ case 'created':
+ toast({
+ title: 'Created',
+ variant: 'success',
+ description: <p>A report has been made.</p>,
+ });
+ break;
+ case 'not_logged_in':
+ toast({
+ title: 'Not Logged In',
+ variant: 'destructive',
+ description: <p>You must be logged in to make a report.</p>,
+ });
+ }
+ setShow(false);
+ })}
+ >
<DialogHeader>
<DialogTitle>{desc}</DialogTitle>
<DialogDescription>Please be as thorough in your report as you can.</DialogDescription>
</DialogHeader>
<div className="mt-4 flex flex-col gap-2">
- <Text intent="leading">
- Please select all that apply:
- </Text>
+ <Text intent="leading">Please select all that apply:</Text>
<FormField
- name='derogatory'
- render={({ field }) => (
+ name="derogatory"
+ render={() => (
<FormItem>
- <div className="flex gap-2 items-center">
+ <div className="flex items-center gap-2">
<Checkbox
{...register('derogatory')}
onCheckedChange={(e) => setValue('derogatory', e as boolean)}
@@ -176,10 +192,10 @@ export default function ReportDialog({ children, triggerAsChild = false, reportT
control={control}
/>
<FormField
- name='derogatory'
- render={({ field }) => (
+ name="derogatory"
+ render={() => (
<FormItem>
- <div className="flex gap-2 items-center">
+ <div className="flex items-center gap-2">
<Checkbox
{...register('bullying')}
onCheckedChange={(e) => setValue('bullying', e as boolean)}
@@ -191,26 +207,25 @@ export default function ReportDialog({ children, triggerAsChild = false, reportT
control={control}
/>
<FormField
- name='hateSpeech'
- render={({ field }) => (
+ name="hateSpeech"
+ render={() => (
<FormItem>
- <div className="flex gap-2 items-center">
+ <div className="flex items-center gap-2">
<Checkbox
{...register('hateSpeech')}
onCheckedChange={(e) => setValue('hateSpeech', e as boolean)}
/>
<div>Hate speech</div>
</div>
-
</FormItem>
)}
control={control}
/>
<FormField
- name='spam'
- render={({ field }) => (
+ name="spam"
+ render={() => (
<FormItem>
- <div className="flex gap-2 items-center">
+ <div className="flex items-center gap-2">
<Checkbox
{...register('spam')}
onCheckedChange={(e) => setValue('spam', e as boolean)}
@@ -222,10 +237,10 @@ export default function ReportDialog({ children, triggerAsChild = false, reportT
control={control}
/>
<FormField
- name='threat'
- render={({ field }) => (
+ name="threat"
+ render={() => (
<FormItem>
- <div className="flex gap-2 items-center">
+ <div className="flex items-center gap-2">
<Checkbox
{...register('threat')}
onCheckedChange={(e) => setValue('threat', e as boolean)}
@@ -236,33 +251,34 @@ export default function ReportDialog({ children, triggerAsChild = false, reportT
)}
control={control}
/>
- {
- reportType === 'CHALLENGE' && (
- <FormField
- name='unclear'
- render={({ field }) => (
- <FormItem>
- <div className="flex gap-2 items-center">
- <Checkbox
- {...register('unclear')}
- onCheckedChange={(e) => setValue('unclear', e as boolean)}
- />
- <div>Unclear</div>
- </div>
- </FormItem>
- )}
- control={control}
- />
- )
- }
+ {reportType === 'CHALLENGE' && (
+ <FormField
+ name="unclear"
+ render={() => (
+ <FormItem>
+ <div className="flex items-center gap-2">
+ <Checkbox
+ {...register('unclear')}
+ onCheckedChange={(e) => setValue('unclear', e as boolean)}
+ />
+ <div>Unclear</div>
+ </div>
+ </FormItem>
+ )}
+ control={control}
+ />
+ )}
<FormField
- name='comments'
- render={({ field }) => (
- <FormItem className='my-3'>
+ name="comments"
+ render={() => (
+ <FormItem className="my-3">
<div className="flex flex-col gap-3">
<div>Other information</div>
- <Textarea {...register('comments')} placeholder="Any extra information to help our moderator team when reviewing this report." />
+ <Textarea
+ {...register('comments')}
+ placeholder="Any extra information to help our moderator team when reviewing this report."
+ />
</div>
</FormItem>
)}
@@ -271,14 +287,19 @@ export default function ReportDialog({ children, triggerAsChild = false, reportT
</div>
<DialogFooter>
- <Button variant="outline" onClick={e => {
- e.preventDefault();
- setShow(false);
- }}>Cancel</Button>
+ <Button
+ variant="outline"
+ onClick={(e) => {
+ e.preventDefault();
+ setShow(false);
+ }}
+ >
+ Cancel
+ </Button>
<Button type="submit">Send report</Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
- )
-}
\ No newline at end of file
+ );
+}
diff --git a/src/components/report/report.action.ts b/src/components/report/report.action.ts
index 667047b4..40985714 100644
--- a/src/components/report/report.action.ts
+++ b/src/components/report/report.action.ts
@@ -1,46 +1,33 @@
-"use server";
+'use server';
-import { prisma } from "~/server/db";
-import type { FormValues } from "../challenge/description";
-import { type Report, type Prisma } from "@prisma/client";
-import { getServerAuthSession } from "~/server/auth";
+import { prisma } from '~/server/db';
+import type { FormValues } from '../challenge/description';
+import { type Report, type Prisma } from '@prisma/client';
+import { getServerAuthSession } from '~/server/auth';
export type ReportBase = {
- issues: Prisma.ReportIssueCreateWithoutReportInput[]
-}
-
-export type ChallengeReport =
- & Omit<
- Report,
- "id" | "type" | "userId" | "commentId" | "reporterId" | "status" | "solutionId"
- >
- & { type: "CHALLENGE" }
- & ReportBase;
+ issues: Prisma.ReportIssueCreateWithoutReportInput[];
+};
-export type UserReport =
- & Omit<
- Report,
- "id" | "type" | "challengeId" | "commentId" | "reporterId" | "status" | "solutionId"
- >
- & { type: "USER" }
- & ReportBase;
+export type ChallengeReport = Omit<
+ Report,
+ 'id' | 'type' | 'userId' | 'commentId' | 'reporterId' | 'status' | 'solutionId'
+> & { type: 'CHALLENGE' } & ReportBase;
-export type CommentReport =
- & Omit<
- Report,
- "id" | "type" | "challengeId" | "userId" | "reporterId" | "status" | "solutionId"
- >
- & { type: "COMMENT" }
- & ReportBase;
+export type UserReport = Omit<
+ Report,
+ 'id' | 'type' | 'challengeId' | 'commentId' | 'reporterId' | 'status' | 'solutionId'
+> & { type: 'USER' } & ReportBase;
-export type SolutionReport =
- & Omit<
- Report,
- "id" | "type" | "challengeId" | "userId" | "reporterId" | "status" | "commentId"
- >
- & { type: "SOLUTION" }
- & ReportBase;
+export type CommentReport = Omit<
+ Report,
+ 'id' | 'type' | 'challengeId' | 'userId' | 'reporterId' | 'status' | 'solutionId'
+> & { type: 'COMMENT' } & ReportBase;
+export type SolutionReport = Omit<
+ Report,
+ 'id' | 'type' | 'challengeId' | 'userId' | 'reporterId' | 'status' | 'commentId'
+> & { type: 'SOLUTION' } & ReportBase;
/**
* @param report a report object specific to a user, challenge, or comment report type
@@ -50,11 +37,11 @@ export async function addReport(
report: ChallengeReport | UserReport | CommentReport | SolutionReport,
) {
const reporter = await getServerAuthSession();
- if (!reporter?.user.id) return "not_logged_in";
+ if (!reporter?.user.id) return 'not_logged_in';
let filterData;
switch (report.type) {
- case "CHALLENGE":
+ case 'CHALLENGE':
filterData = {
challengeId: report.challengeId,
};
@@ -66,12 +53,12 @@ export async function addReport(
break;
case 'USER':
filterData = {
- userId: report.userId
+ userId: report.userId,
};
break;
case 'SOLUTION':
filterData = {
- solutionId: report.solutionId
+ solutionId: report.solutionId,
};
break;
}
@@ -79,13 +66,13 @@ export async function addReport(
const alreadyReported = await prisma.report.findFirst({
where: {
type: report.type,
- status: "PENDING",
+ status: 'PENDING',
reporterId: reporter.user.id,
...filterData,
},
});
- if (alreadyReported) return "already_exists";
+ if (alreadyReported) return 'already_exists';
await prisma.report.create({
data: {
@@ -94,22 +81,17 @@ export async function addReport(
issues: {
createMany: {
data: report.issues,
- }
+ },
},
- status: "PENDING",
-
+ status: 'PENDING',
},
});
- return "created";
+ return 'created';
}
-export async function addChallengeReport(
- challengeId: number,
- userId: string,
- data: FormValues,
-) {
- if (userId === undefined) return "not_logged_in";
+export async function addChallengeReport(challengeId: number, userId: string, data: FormValues) {
+ if (userId === undefined) return 'not_logged_in';
const report = await prisma.challengeReport.findMany({
where: {
@@ -119,7 +101,7 @@ export async function addChallengeReport(
});
if (report.length > 0) {
console.info(report);
- return "report_already_made";
+ return 'report_already_made';
}
await prisma.challengeReport.create({
@@ -132,5 +114,5 @@ export async function addChallengeReport(
},
});
- return "created";
+ return 'created';
}
diff --git a/src/components/settings/index.tsx b/src/components/settings/index.tsx
index b758d573..90dd60d6 100644
--- a/src/components/settings/index.tsx
+++ b/src/components/settings/index.tsx
@@ -1,17 +1,16 @@
'use client';
import { zodResolver } from '@hookform/resolvers/zod';
-import { Controller, useFieldArray, useForm, useWatch } from 'react-hook-form';
+import { useFieldArray, useForm, useWatch } from 'react-hook-form';
import * as z from 'zod';
import { Button } from '../ui/button';
-import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage } from '../ui/form';
+import { Form, FormField, FormItem, FormMessage } from '../ui/form';
import { Input } from '../ui/input';
import { RichMarkdownEditor } from '../ui/rich-markdown-editor';
import { toast } from '../ui/use-toast';
import { updateProfile } from './settings.action';
import Link from 'next/link';
import { MagicIcon } from '../ui/magic-icon';
-import { Select, SelectTrigger } from '@radix-ui/react-select';
export interface UserLinkType {
id: string | null;
@@ -88,7 +87,7 @@ export const Settings = ({
<Form {...form}>
<form action={() => onSubmit(getValues())}>
- <div >
+ <div>
<FormField
control={form.control}
name="bio"
diff --git a/src/components/user/dashboard/index.tsx b/src/components/user/dashboard/index.tsx
index 87d53913..aad2277b 100644
--- a/src/components/user/dashboard/index.tsx
+++ b/src/components/user/dashboard/index.tsx
@@ -59,9 +59,9 @@ export default async function Dashboard({ user }: Props) {
return (
<div className="container">
- <div className="flex-1 space-y-4 mt-10">
+ <div className="mt-10 flex-1 space-y-4">
<div className="flex gap-4">
- <div className="flex pace-x-2">
+ <div className="pace-x-2 flex">
<Image
className="rounded-3xl"
alt="user avatar"
diff --git a/src/components/user/dashboard/user-header.tsx b/src/components/user/dashboard/user-header.tsx
index aea82590..fe9022d1 100644
--- a/src/components/user/dashboard/user-header.tsx
+++ b/src/components/user/dashboard/user-header.tsx
@@ -1,18 +1,15 @@
'use client';
-import Text from "~/components/ui/typography/typography";
-import { UserData } from './index'
-import { type User } from "@prisma/client";
-import ReportDialog from "~/components/report";
-import { ActionMenu } from "~/components/ui/action-menu";
+import Text from '~/components/ui/typography/typography';
+import { type User } from '@prisma/client';
+import ReportDialog from '~/components/report';
+import { ActionMenu } from '~/components/ui/action-menu';
export interface UserHeaderProps {
user: User;
}
-export default function UserHeader({
- user,
-}: UserHeaderProps) {
+export default function UserHeader({ user }: UserHeaderProps) {
return (
<div className="flex gap-4">
<Text intent="h1">{user.name}</Text>
@@ -23,7 +20,7 @@ export default function UserHeader({
key: 'report',
label: 'Report',
icon: 'Flag',
- }
+ },
]}
onChange={() => {
// do nothing
@@ -31,5 +28,5 @@ export default function UserHeader({
/>
</ReportDialog>
</div>
- )
-}
\ No newline at end of file
+ );
+}
diff --git a/src/components/user/profile.tsx b/src/components/user/profile.tsx
index 1764ead6..a33f4d06 100644
--- a/src/components/user/profile.tsx
+++ b/src/components/user/profile.tsx
@@ -22,7 +22,7 @@ export async function Profile({ username: usernameFromQuery }: Props) {
},
include: {
userLinks: true,
- }
+ },
});
if (!user || !username) {
diff --git a/src/utils/relativeTime.ts b/src/utils/relativeTime.ts
index ddb6182c..1a2dafe8 100644
--- a/src/utils/relativeTime.ts
+++ b/src/utils/relativeTime.ts
@@ -5,4 +5,4 @@ export const getRelativeTime = (date: Date | string) => {
return formatDistanceToNowStrict(date, {
addSuffix: true,
});
-};
\ No newline at end of file
+};