Skip to content

Commit

Permalink
fix(fe): add score field at contestProblem (#2019)
Browse files Browse the repository at this point in the history
Co-authored-by: jimin9038 <jimin9038@g.skku.edu>
  • Loading branch information
youznn and jimin9038 authored Aug 27, 2024
1 parent 0c41588 commit e1413ab
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 7 deletions.
16 changes: 14 additions & 2 deletions apps/frontend/app/admin/contest/[id]/edit/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ export default function Page({ params }: { params: { id: string } }) {
id: problem.problemId,
title: problem.problem.title,
order: problem.order,
difficulty: problem.problem.difficulty
difficulty: problem.problem.difficulty,
score: problem.score ?? 0 // Score 기능 완료되면 수정해주세요!!
}
})
localStorage.setItem(
Expand All @@ -134,6 +135,10 @@ export default function Page({ params }: { params: { id: string } }) {
} else {
const parsedData = JSON.parse(importedProblems)
if (parsedData.length > 0) {
console.log(parsedData)
parsedData.forEach((problem: ContestProblem) => {
problem.score = problem.score ?? 0 // Score 기능 완료되면 수정해주세요!!
})
setProblems(parsedData)
const orderArray = parsedData.map(
// eslint-disable-next-line
Expand Down Expand Up @@ -198,14 +203,21 @@ export default function Page({ params }: { params: { id: string } }) {
variables: {
groupId: 1,
contestId: Number(id),
problemIds
problemIdsWithScore: problems.map((problem) => {
return {
problemId: problem.id,
score: problem.score
}
})
}
})

const orders: number[] = []
orderArray.forEach((order: number, index: number) => {
orders[order] = problemIds[index]
})
console.log(orders)

await updateContestProblemsOrder({
variables: {
groupId: 1,
Expand Down
15 changes: 14 additions & 1 deletion apps/frontend/app/admin/contest/create/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export default function Page() {
return
}
const orderArray = JSON.parse(storedData)

if (orderArray.length !== problemIds.length) {
toast.error('Problem order not set')
return
Expand Down Expand Up @@ -101,14 +102,22 @@ export default function Page() {
variables: {
groupId: 1,
contestId,
problemIds
problemIdsWithScore: problems.map((problem) => {
return {
problemId: problem.id,
score: problem.score
}
})
}
}).then(() => {
console.log('Problems imported')
})

const orders: number[] = []
orderArray.forEach((order: number, index: number) => {
orders[order] = problemIds[index]
})
console.log(orders, problemIds)
await updateContestProblemsOrder({
variables: {
groupId: 1,
Expand Down Expand Up @@ -155,6 +164,10 @@ export default function Page() {
const importedProblems = JSON.parse(
localStorage.getItem('importProblems') || '[]'
)
importedProblems?.forEach((problem: ContestProblem) => {
problem.score = problem.score ?? 0 // Score 기능 완료되면 수정해주세요!!
})

setProblems(importedProblems)

// eslint-disable-next-line
Expand Down
1 change: 1 addition & 0 deletions apps/frontend/app/admin/contest/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ export interface ContestProblem {
title: string
order: number
difficulty: string
score: number
}
5 changes: 3 additions & 2 deletions apps/frontend/components/DataTableAdmin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,13 @@ export function DataTableAdmin<TData, TValue>({

const handleImportProblems = async () => {
const selectedProblems = table.getSelectedRowModel().rows as {
original: { id: number; title: string; difficulty: string }
original: { id: number; title: string; difficulty: string; score: number }
}[]
const problems = selectedProblems.map((problem) => ({
id: problem.original.id,
title: problem.original.title,
difficulty: problem.original.difficulty
difficulty: problem.original.difficulty,
score: problem.original.score ?? 0 // Score 기능 완료되면 수정해주세요!!
}))
if (contestId === null) {
localStorage.setItem('importProblems', JSON.stringify(problems))
Expand Down
4 changes: 2 additions & 2 deletions apps/frontend/graphql/contest/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ const IMPORT_PROBLEMS_TO_CONTEST = gql(`
mutation ImportProblemsToContest(
$groupId: Int!,
$contestId: Int!,
$problemIds: [Int!]!
$problemIdsWithScore: [ProblemScoreInput!]!
) {
importProblemsToContest(
groupId: $groupId,
contestId: $contestId,
problemIds: $problemIds
problemIdsWithScore: $problemIdsWithScore
) {
contestId
problemId
Expand Down
1 change: 1 addition & 0 deletions apps/frontend/graphql/problem/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const GET_CONTEST_PROBLEMS = gql(`
query GetContestProblems($groupId: Int!, $contestId: Int!) {
getContestProblems(groupId: $groupId, contestId: $contestId) {
order
score
problemId
problem {
title
Expand Down

0 comments on commit e1413ab

Please sign in to comment.