Skip to content

Commit

Permalink
Merge branch 'main' into renovate/all-minor-patch
Browse files Browse the repository at this point in the history
  • Loading branch information
jimin9038 authored May 27, 2024
2 parents b29b40f + b994a02 commit e832c9b
Show file tree
Hide file tree
Showing 24 changed files with 473 additions and 433 deletions.
10 changes: 8 additions & 2 deletions apps/frontend/app/(main)/_components/ProblemCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@ import type { Route } from 'next'
import Link from 'next/link'
import ProblemCard from './ProblemCard'

interface ProblemCardsProps {
data: WorkbookProblem[]
total: number
}

const getProblems = async () => {
const { problems }: { problems: WorkbookProblem[] } = await fetcher
const problems: ProblemCardsProps = await fetcher
.get('problem', {
searchParams: {
take: 3
// workbookId: 1
}
})
.json()
return problems

return problems.data
}

export default async function ProblemCards() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ interface ContestProblemProps {
params: { contestId: string }
}

interface ContestApiResponse {
data: ContestProblem[]
total: number
}

export default async function ContestProblem({ params }: ContestProblemProps) {
const { contestId } = params
const res = await fetcherWithAuth.get(`contest/${contestId}/problem`, {
Expand All @@ -34,10 +39,11 @@ export default async function ContestProblem({ params }: ContestProblemProps) {
)
}

const { problems }: { problems: ContestProblem[] } = await res.json()
const problems: ContestApiResponse = await res.json()

return (
<DataTable
data={problems}
data={problems.data}
columns={columns}
headerStyle={{
order: 'w-[8%]',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ import { fetcher } from '@/lib/utils'
import type { Contest } from '@/types/type'
import { columns } from './Columns'

interface ContestProps {
data: Contest[]
}

export default async function FinishedContestTable() {
const data: {
finished: Contest[]
} = await fetcher.get('contest/finished?take=51').json()
const ContestData: ContestProps = await fetcher
.get('contest/finished?take=51')
.json()

data.finished.forEach((contest) => {
ContestData.data.forEach((contest) => {
contest.status = 'finished'
})

Expand All @@ -17,7 +21,7 @@ export default async function FinishedContestTable() {
<p className="text-xl font-bold md:text-2xl">Finished</p>
{/* TODO: Add search bar */}
<DataTable
data={data.finished}
data={ContestData.data}
columns={columns}
headerStyle={{
title: 'text-left w-2/5 md:w-3/6',
Expand Down
43 changes: 29 additions & 14 deletions apps/frontend/app/(main)/notice/_components/NoticeTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,26 @@ interface Props {
search: string
}

export default async function NoticeTable({ search }: Props) {
const fixedNoticesFetcher: Promise<Notice[]> | Notice[] =
search !== ''
? []
: fetcher
.get('notice', {
searchParams: {
fixed: 'true',
take: '10'
}
})
.json()

const noticesFetcher: Promise<Notice[]> = fetcher
interface NoticeProps {
data: Notice[]
total: number
}

const getFixedNotices = async () => {
const notices: NoticeProps = await fetcher
.get('notice', {
searchParams: {
fixed: 'true',
take: '10'
}
})
.json()

return notices.data
}

const getNotices = async (search: string) => {
const notices: NoticeProps = await fetcher
.get('notice', {
searchParams: {
search,
Expand All @@ -29,6 +35,15 @@ export default async function NoticeTable({ search }: Props) {
})
.json()

return notices.data
}

export default async function NoticeTable({ search }: Props) {
const fixedNoticesFetcher: Promise<Notice[]> | Notice[] =
search !== '' ? [] : getFixedNotices()

const noticesFetcher: Promise<Notice[]> = getNotices(search)

const [fixedNotices, notices] = await Promise.all([
fixedNoticesFetcher,
noticesFetcher
Expand Down
106 changes: 12 additions & 94 deletions apps/frontend/app/admin/contest/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
'use client'

import { gql } from '@generated'
import { DataTableAdmin } from '@/components/DataTableAdmin'
import TextEditor from '@/components/TextEditor'
import { DateTimePickerDemo } from '@/components/date-time-picker-demo'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { ScrollArea } from '@/components/ui/scroll-area'
import {
IMPORT_PROBLEMS_TO_CONTEST,
UPDATE_CONTEST,
REMOVE_PROBLEMS_FROM_CONTEST
} from '@/graphql/contest/mutations'
import { GET_CONTEST } from '@/graphql/contest/queries'
import {
UPDATE_PROBLEM_VISIBLE,
UPDATE_CONTEST_PROBLEMS_ORDER
} from '@/graphql/problem/mutations'
import { GET_CONTEST_PROBLEMS } from '@/graphql/problem/queries'
import { cn } from '@/lib/utils'
import { useMutation, useQuery } from '@apollo/client'
import type { UpdateContestInput } from '@generated/graphql'
Expand All @@ -24,98 +34,6 @@ import { z } from 'zod'
import Label from '../_components/Label'
import { columns } from './_components/Columns'

const GET_CONTEST = gql(`
query GetContest($contestId: Int!) {
getContest(contestId: $contestId) {
id
description
endTime
startTime
title
}
}
`)

const UPDATE_CONTEST = gql(`
mutation UpdateContest($groupId: Int!, $input: UpdateContestInput!) {
updateContest(groupId: $groupId, input: $input) {
id
isRankVisible
isVisible
description
endTime
startTime
title
}
}
`)

const GET_CONTEST_PROBLEMS = gql(`
query GetContestProblems($groupId: Int!, $contestId: Int!) {
getContestProblems(groupId: $groupId, contestId: $contestId) {
order
problemId
problem {
title
difficulty
}
}
}
`)

const IMPORT_PROBLEMS_TO_CONTEST = gql(`
mutation ImportProblemsToContest(
$groupId: Int!,
$contestId: Int!,
$problemIds: [Int!]!
) {
importProblemsToContest(
groupId: $groupId,
contestId: $contestId,
problemIds: $problemIds
) {
contestId
problemId
}
}
`)

const REMOVE_PROBLEMS_FROM_CONTEST = gql(`
mutation RemoveProblemsFromContest(
$groupId: Int!,
$contestId: Int!,
$problemIds: [Int!]!
) {
removeProblemsFromContest(
groupId: $groupId,
contestId: $contestId,
problemIds: $problemIds
) {
contestId
problemId
}
}
`)

const UPDATE_CONTEST_PROBLEMS_ORDER = gql(`
mutation UpdateContestProblemsOrder($groupId: Int!, $contestId: Int!, $orders: [Int!]!) {
updateContestProblemsOrder(groupId: $groupId, contestId: $contestId, orders: $orders) {
order
contestId
problemId
}
}
`)

const EDIT_VISIBLE = gql(`
mutation UpdateVisible($groupId: Int!, $input: UpdateProblemInput!) {
updateProblem(groupId: $groupId, input: $input) {
id
isVisible
}
}
`)

const inputStyle =
'border-gray-200 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-gray-950'

Expand Down Expand Up @@ -230,7 +148,7 @@ export default function Page({ params }: { params: { id: string } }) {
const [updateContest, { error }] = useMutation(UPDATE_CONTEST)
const [importProblemsToContest] = useMutation(IMPORT_PROBLEMS_TO_CONTEST)
const [removeProblemsFromContest] = useMutation(REMOVE_PROBLEMS_FROM_CONTEST)
const [updateVisible] = useMutation(EDIT_VISIBLE)
const [updateVisible] = useMutation(UPDATE_PROBLEM_VISIBLE)
const [updateContestProblemsOrder] = useMutation(
UPDATE_CONTEST_PROBLEMS_ORDER
)
Expand Down
14 changes: 2 additions & 12 deletions apps/frontend/app/admin/contest/_components/Columns.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use client'

import { gql } from '@generated'
import { DataTableColumnHeader } from '@/components/DataTableColumnHeader'
import { Checkbox } from '@/components/ui/checkbox'
import { Switch } from '@/components/ui/switch'
Expand All @@ -10,6 +9,7 @@ import {
TooltipProvider,
TooltipTrigger
} from '@/components/ui/tooltip'
import { UPDATE_CONTEST_VISIBLE } from '@/graphql/contest/mutations'
import { cn, dateFormatter } from '@/lib/utils'
import { useMutation } from '@apollo/client'
import * as TooltipPrimitive from '@radix-ui/react-tooltip'
Expand All @@ -28,18 +28,8 @@ interface DataTableContest {
isRankVisible: boolean
}

const EDIT_VISIBLE = gql(`
mutation UpdateContestVisible($groupId: Int!, $input: UpdateContestInput!) {
updateContest(groupId: $groupId, input: $input) {
id
isVisible
isRankVisible
}
}
`)

function VisibleCell({ row }: { row: Row<DataTableContest> }) {
const [updateVisible] = useMutation(EDIT_VISIBLE)
const [updateVisible] = useMutation(UPDATE_CONTEST_VISIBLE)

return (
<div className="flex space-x-2">
Expand Down
61 changes: 9 additions & 52 deletions apps/frontend/app/admin/contest/create/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use client'

import { gql } from '@generated'
import { DataTableAdmin } from '@/components/DataTableAdmin'
import TextEditor from '@/components/TextEditor'
import { DateTimePickerDemo } from '@/components/date-time-picker-demo'
Expand All @@ -12,6 +11,14 @@ import {
PopoverTrigger
} from '@/components/ui/popover'
import { ScrollArea } from '@/components/ui/scroll-area'
import {
CREATE_CONTEST,
IMPORT_PROBLEMS_TO_CONTEST
} from '@/graphql/contest/mutations'
import {
UPDATE_PROBLEM_VISIBLE,
UPDATE_CONTEST_PROBLEMS_ORDER
} from '@/graphql/problem/mutations'
import { cn } from '@/lib/utils'
import { useMutation } from '@apollo/client'
import type { CreateContestInput } from '@generated/graphql'
Expand All @@ -30,56 +37,6 @@ import { z } from 'zod'
import Label from '../_components/Label'
import { columns } from './_components/Columns'

const CREATE_CONTEST = gql(`
mutation CreateContest($groupId: Int!, $input: CreateContestInput!) {
createContest(groupId: $groupId, input: $input) {
id
isVisible
isRankVisible
description
endTime
startTime
title
}
}
`)

const IMPORT_PROBLEMS_TO_CONTEST = gql(`
mutation ImportProblemsToContest(
$groupId: Int!,
$contestId: Int!,
$problemIds: [Int!]!
) {
importProblemsToContest(
groupId: $groupId,
contestId: $contestId,
problemIds: $problemIds
) {
contestId
problemId
}
}
`)

const UPDATE_CONTEST_PROBLEMS_ORDER = gql(`
mutation UpdateContestProblemsOrder($groupId: Int!, $contestId: Int!, $orders: [Int!]!) {
updateContestProblemsOrder(groupId: $groupId, contestId: $contestId, orders: $orders) {
order
contestId
problemId
}
}
`)

const EDIT_VISIBLE = gql(`
mutation UpdateVisible($groupId: Int!, $input: UpdateProblemInput!) {
updateProblem(groupId: $groupId, input: $input) {
id
isVisible
}
}
`)

const inputStyle =
'border-gray-200 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-gray-950'

Expand Down Expand Up @@ -123,7 +80,7 @@ export default function Page() {

const [createContest, { error }] = useMutation(CREATE_CONTEST)
const [importProblemsToContest] = useMutation(IMPORT_PROBLEMS_TO_CONTEST)
const [updateVisible] = useMutation(EDIT_VISIBLE)
const [updateVisible] = useMutation(UPDATE_PROBLEM_VISIBLE)
const [updateContestProblemsOrder] = useMutation(
UPDATE_CONTEST_PROBLEMS_ORDER
)
Expand Down
Loading

0 comments on commit e832c9b

Please sign in to comment.