Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion src/app/judging/[id]/ProjectScoringPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,24 @@ export default function ProjectScoringPage({
project,
questions,
existingScores,
existingFeedback,
}: {
project: Project;
questions: JudgingQuestion[];
existingScores: JudgingScore[];
existingFeedback: string | null;
}) {
const router = useRouter();

// Seed state from any scores already in the DB so revisiting the page pre-fills inputs.
const [scores, setScores] = useState<Record<number, number>>(
Object.fromEntries(existingScores.map((s) => [s.questionId, s.score])),
);
const [feedback, setFeedback] = useState<string>(
existingFeedback === null ? "" : existingFeedback,
);

const [completing, setCompleting] = useState(false);
const [feedback, setFeedback] = useState<string>("");

// All questions must have a defined score before the judge can mark complete.
const allScored =
Expand Down
4 changes: 4 additions & 0 deletions src/app/judging/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
getProject,
getJudgingQuestions,
getScoresForProject,
getFeedback,
} from "@/src/util/db/judge";
import ProjectScoringPage from "./ProjectScoringPage";
import { ensureJudgePermission } from "@/src/util/judge";
Expand All @@ -28,11 +29,14 @@ export default async function Page({
getScoresForProject(session.user!.id, projectId),
]);

const existingFeedback = await getFeedback(projectId, session.user!.id);

return (
<ProjectScoringPage
project={project}
questions={questions}
existingScores={existingScores}
existingFeedback={existingFeedback}
/>
);
}
23 changes: 23 additions & 0 deletions src/util/db/judge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,29 @@ export async function getTrack(trackId: number): Promise<Track | null> {
};
}

/**
* This function returns the feedback that a specific judge left on a specific project
*
* @param projectId This is the id of the project
* @param judgeId This is the id of the judge
* @returns String that is the feedback
*/
export async function getFeedback(
projectId: number,
judgeId: number,
): Promise<string | null> {
const data =
await sql`SELECT feedback FROM judge_assignments WHERE project_id = ${projectId} and judge_id = ${judgeId}`;

if (data.length === 0) {
return null;
}

const row = data[0];

return row.feedback;
}

/**
* Returns all tracks.
*/
Expand Down
Loading