mirror of
https://github.com/massbug/judge4c.git
synced 2025-05-17 14:56:36 +00:00
feat(submissions): add login requirement for submissions page
- Add SubmissionLoginButton component for unauthenticated users - Modify submissions page to check auth session - Filter submissions by current user when logged in
This commit is contained in:
parent
30ee16fbf0
commit
f39bbf76e7
@ -1,8 +1,10 @@
|
||||
import prisma from "@/lib/prisma";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { notFound } from "next/navigation";
|
||||
import { getUserLocale } from "@/i18n/locale";
|
||||
import SubmissionsTable from "@/components/submissions-table";
|
||||
import { ScrollArea, ScrollBar } from "@/components/ui/scroll-area";
|
||||
import SubmissionLoginButton from "@/components/submission-login-button";
|
||||
|
||||
interface SubmissionsPageProps {
|
||||
params: Promise<{ id: string }>;
|
||||
@ -10,15 +12,26 @@ interface SubmissionsPageProps {
|
||||
|
||||
export default async function SubmissionsPage({ params }: SubmissionsPageProps) {
|
||||
const { id } = await params;
|
||||
const session = await auth();
|
||||
|
||||
if (!id) {
|
||||
return notFound();
|
||||
}
|
||||
|
||||
if (!session?.user?.id) {
|
||||
return (
|
||||
<SubmissionLoginButton />
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
const problem = await prisma.problem.findUnique({
|
||||
where: { id },
|
||||
select: {
|
||||
submissions: {
|
||||
where: {
|
||||
userId: session.user.id,
|
||||
},
|
||||
include: {
|
||||
testcaseResults: {
|
||||
include: {
|
||||
|
@ -16,7 +16,7 @@ export default function ProblemDescriptionFooter({
|
||||
className={cn("h-9 flex flex-none items-center bg-muted px-3 py-2", className)}
|
||||
>
|
||||
<div className="w-full flex items-center justify-center">
|
||||
<span className="truncate">Description of {title}</span>
|
||||
<span className="truncate">{title}</span>
|
||||
</div>
|
||||
</footer>
|
||||
);
|
||||
|
@ -16,7 +16,7 @@ export default function ProblemSolutionFooter({
|
||||
className={cn("h-9 flex flex-none items-center bg-muted px-3 py-2", className)}
|
||||
>
|
||||
<div className="w-full flex items-center justify-center">
|
||||
<span className="truncate">Solution of {title}</span>
|
||||
<span className="truncate">{title}</span>
|
||||
</div>
|
||||
</footer>
|
||||
);
|
||||
|
36
src/components/submission-login-button.tsx
Normal file
36
src/components/submission-login-button.tsx
Normal file
@ -0,0 +1,36 @@
|
||||
"use client";
|
||||
|
||||
import { CodeXmlIcon } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { usePathname, useRouter, useSearchParams } from "next/navigation";
|
||||
|
||||
export default function SubmissionLoginButton() {
|
||||
const router = useRouter();
|
||||
const pathname = usePathname();
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
const handleLogIn = () => {
|
||||
const params = new URLSearchParams(searchParams.toString());
|
||||
params.set("redirectTo", pathname);
|
||||
router.push(`/sign-in?${params.toString()}`);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col items-center justify-start gap-2 pt-[10vh]">
|
||||
<div className="flex items-center gap-3">
|
||||
<CodeXmlIcon
|
||||
className="shrink-0 text-blue-500"
|
||||
size={16}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<p className="text-base font-medium">Join Judge4c to Code!</p>
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
View your Submission records here
|
||||
</p>
|
||||
<Button size="sm" onClick={handleLogIn}>
|
||||
Log In
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue
Block a user