Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add eslint rule #2295

Merged
merged 4 commits into from
Jan 12, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,18 @@
}, [currentModal])

useEffect(() => {
if (!templateString) return
if (!templateString) {
return
}
const parsedTemplates = JSON.parse(templateString)
const filteredTemplate = parsedTemplates.filter(
(template: Template) => template.language === language
)
if (filteredTemplate.length === 0) return
if (filteredTemplate.length === 0) {
return
}
setTemplateCode(filteredTemplate[0].code[0].text)
}, [language])

Check warning on line 141 in apps/frontend/app/(client)/(code-editor)/_components/EditorHeader/EditorHeader.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has a missing dependency: 'templateString'. Either include it or remove the dependency array

useEffect(() => {
storageKey.current = getStorageKey(
Expand All @@ -147,7 +151,7 @@
const storedCode = getCodeFromLocalStorage(storageKey.current)
setCode(storedCode || templateCode)
}
}, [userName, problem, contestId, language, templateCode])

Check warning on line 154 in apps/frontend/app/(client)/(code-editor)/_components/EditorHeader/EditorHeader.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has a missing dependency: 'setCode'. Either include it or remove the dependency array

const storeCodeToLocalStorage = (code: string) => {
if (storageKey.current !== undefined) {
Expand Down Expand Up @@ -200,7 +204,9 @@
if (res.status === 401) {
showSignIn()
toast.error('Log in first to submit your code')
} else toast.error('Please try again later.')
} else {
toast.error('Please try again later.')
}
}
}

Expand All @@ -223,16 +229,22 @@
localStorage.setItem(storageKey.current, templateCode)
setCode(templateCode)
toast.success('Successfully reset the code')
} else toast.error('Failed to reset the code')
} else {
toast.error('Failed to reset the code')
}
}

const checkSaved = () => {
const code = getCode()
if (storageKey.current !== undefined) {
const storedCode = getCodeFromLocalStorage(storageKey.current)
if (storedCode && storedCode === code) return true
else if (!storedCode && templateCode === code) return true
else return false
if (storedCode && storedCode === code) {
return true
} else if (!storedCode && templateCode === code) {
return true
} else {
return false
}
}
return true
}
Expand Down Expand Up @@ -273,7 +285,7 @@
window.removeEventListener('beforeunload', handleBeforeUnload)
//window.removeEventListener('popstate', handlePopState)
}
}, [])

Check warning on line 288 in apps/frontend/app/(client)/(code-editor)/_components/EditorHeader/EditorHeader.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has missing dependencies: 'contestId', 'handleBeforeUnload', 'language', 'problem.id', and 'userName'. Either include them or remove the dependency array

useEffect(() => {
const originalPush = router.push
Expand All @@ -295,7 +307,7 @@
return () => {
router.push = originalPush
}
}, [router])

Check warning on line 310 in apps/frontend/app/(client)/(code-editor)/_components/EditorHeader/EditorHeader.tsx

View workflow job for this annotation

GitHub Actions / Lint

React Hook useEffect has a missing dependency: 'checkSaved'. Either include it or remove the dependency array

return (
<div className="flex shrink-0 items-center justify-between border-b border-b-slate-700 bg-[#222939] px-6">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default function RunTestButton({
}
})

const submitTest = async () => {
const submitTest = () => {
const code = getCode()
const testcases = getUserTestcases()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { ScrollArea, ScrollBar } from '@/components/shadcn/scroll-area'
import { Tabs, TabsList, TabsTrigger } from '@/components/shadcn/tabs'
import { useLanguageStore, useCodeStore } from '@/stores/editor'
import type { Language, ProblemDetail } from '@/types/type'
import type { ProblemDetail } from '@/types/type'
import type { Route } from 'next'
import Link from 'next/link'
import { usePathname } from 'next/navigation'
Expand Down Expand Up @@ -154,7 +154,7 @@ function CodeEditorInEditorResizablePanel({
return (
<CodeEditor
value={code ?? ''}
language={language as Language}
language={language}
onChange={setCode}
enableCopyPaste={enableCopyPaste}
height="100%"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ function TestSummary({
}

function TestResultDetail({ data }: { data: TestResultDetail | undefined }) {
if (data === undefined) return null
if (data === undefined) {
return null
}

return (
<div className="px-8 pt-5">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function WhitespaceVisualizer({
const visibleLines = lines.slice(0, 3).join('\n')
const truncatedText =
lines.length > 3
? visibleLines + '\n<span style="color: rgb(150, 150, 150);">...</span>'
? `${visibleLines}\n<span style="color: rgb(150, 150, 150);">...</span>`
: visibleLines

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,8 @@ export default function ContestEditorSkeleton() {
<button
type="button"
className="hidden items-center gap-2 rounded-md border-0 px-4 py-1 md:flex"
></button>
<button
type="button"
className="flex gap-2 px-4 py-1 md:hidden"
></button>
/>
<button type="button" className="flex gap-2 px-4 py-1 md:hidden" />
</div>
</div>
</header>
Expand Down Expand Up @@ -76,7 +73,7 @@ export default function ContestEditorSkeleton() {
</div>
</div>
</div>
<div className="relative w-px bg-slate-500" role="separator"></div>
<div className="relative w-px bg-slate-500" role="separator" />
<div className="w-2/3 bg-[#222939]">
<div className="flex h-12 items-center justify-end border-b border-slate-700 bg-[#222939] px-6">
<button className="h-8 w-[77px] rounded-md bg-slate-600 text-red-500">
Expand All @@ -94,7 +91,7 @@ export default function ContestEditorSkeleton() {
<button className="h-8 w-10 rounded-md bg-slate-600">C</button>
</div>
<div className="h-full bg-[#121728] p-4">
<pre className="h-96 overflow-auto rounded-md bg-[#222939] p-4 font-mono text-sm text-gray-300"></pre>
<pre className="h-96 overflow-auto rounded-md bg-[#222939] p-4 font-mono text-sm text-gray-300" />
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import EditorLayout from '@/app/(client)/(code-editor)/_components/EditorLayout'

export default async function layout({
export default function layout({
params,
children
}: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Link from 'next/link'
import { Suspense } from 'react'
import SubmissionDetail from '../_components/SubmissionDetail'

export default async function Page({
export default function Page({
params
}: {
params: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default async function SubmissionDetail({

const submission: SubmissionDetail = res.ok ? await res.json() : dataIfError

if (submission.result == 'Judging') {
if (submission.result === 'Judging') {
revalidateTag(`submission/${submissionId}`)
}

Expand Down Expand Up @@ -107,9 +107,7 @@ export default async function SubmissionDetail({
</Table>
</div>
)}
{res.ok ? (
<></>
) : (
{res.ok ? null : (
<div className="absolute left-0 top-0 z-10 flex h-full w-full flex-col items-center justify-center gap-1 backdrop-blur">
<IoIosLock size={100} />
<p className="mt-4 text-xl font-semibold">Access Denied</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import EditorLayout from '@/app/(client)/(code-editor)/_components/EditorLayout'

export default async function layout({
export default function layout({
params,
children
}: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Link from 'next/link'
import { Suspense } from 'react'
import SubmissionDetail from '../_components/SubmissionDetail'

export default async function Page({
export default function Page({
params
}: {
params: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default async function SubmissionDetail({

const submission: SubmissionDetail = res.ok ? await res.json() : dataIfError

if (submission.result == 'Judging') {
if (submission.result === 'Judging') {
revalidateTag(`submission/${submissionId}`)
}

Expand Down Expand Up @@ -98,9 +98,7 @@ export default async function SubmissionDetail({
</Table>
</div>
)}
{res.ok ? (
<></>
) : (
{res.ok ? null : (
<div className="absolute left-0 top-0 z-10 flex h-full w-full flex-col items-center justify-center gap-1 backdrop-blur">
<p className="mt-4 font-mono text-xl font-semibold">Access Denied</p>
<p className="w-10/12 text-center">
Expand Down
6 changes: 4 additions & 2 deletions apps/frontend/app/(client)/(main)/_components/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ export default function SearchBar({ className }: SearchBarProps) {
// set search data to newParam
if (data.search) {
newParam.set('search', data.search)
} else newParam.delete('search')
} else {
newParam.delete('search')
}
const newParamString = newParam.toString()
router.push(
`${pathname}${newParamString ? '?' + newParamString : ''}` as Route,
`${pathname}${newParamString ? `?${newParamString}` : ''}` as Route,
{
scroll: false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default function RegisterButton({
resolver: zodResolver(schema)
})

const onSubmit = async () => {
const onSubmit = () => {
clickRegister(id)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,17 @@ export default async function ContestTop({ params }: ContestTopProps) {
const startTime = new Date(data.startTime)
const endTime = new Date(data.endTime)
const currentTime = new Date()
const state =
currentTime >= endTime
? 'Finished'
: currentTime < startTime
? 'Upcoming'
: 'Ongoing'
const state = (() => {
if (currentTime >= endTime) {
return 'Finished'
}

if (currentTime < startTime) {
return 'Upcoming'
}

return 'Ongoing'
})()

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ export const columns: ColumnDef<ContestProblem>[] = [
header: () => 'Score',
accessorKey: 'score',
cell: ({ row }) =>
row.original.maxScore != null ? (
`${row.original.score ?? '-'} / ${row.original.maxScore}`
) : (
<></>
)
row.original.maxScore !== null
? `${row.original.score ?? '-'} / ${row.original.maxScore}`
: null
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
TableRow
} from '@/components/shadcn/table'
import { dateFormatter, getResultColor } from '@/libs/utils'
import type { ContestProblem, Language } from '@/types/type'
import type { ContestProblem } from '@/types/type'
import { useSuspenseQuery } from '@tanstack/react-query'

interface SubmissionDetailProps {
Expand Down Expand Up @@ -109,11 +109,7 @@ export function SubmissionDetailContent({
</TableCell>
<TableCell>{item.cpuTime} ms</TableCell>
<TableCell>
{(
(item?.memoryUsage as number) /
(1024 * 1024)
).toFixed(2)}{' '}
MB
{(item?.memoryUsage / (1024 * 1024)).toFixed(2)} MB
</TableCell>
</TableRow>
))}
Expand All @@ -125,7 +121,7 @@ export function SubmissionDetailContent({
<h2 className="mb-3 font-bold">Source Code</h2>
<CodeEditor
value={submission?.code}
language={submission?.language as Language}
language={submission?.language}
readOnly
className="max-h-96 min-h-16 w-full"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,13 @@ function ContestCardCarousel({
const chunks = []

if (itemsPerSlide === 3) {
for (let i = 0; i < data.length; i += 3) chunks.push(data.slice(i, i + 3))
for (let i = 0; i < data.length; i += 3) {
chunks.push(data.slice(i, i + 3))
}
} else if (itemsPerSlide === 2) {
for (let i = 0; i < data.length; i += 2) chunks.push(data.slice(i, i + 2))
for (let i = 0; i < data.length; i += 2) {
chunks.push(data.slice(i, i + 2))
}
}

return (
Expand Down Expand Up @@ -117,15 +121,15 @@ export default async function Contest({
session ? await getRegisteredContests() : await getContests()
).filter(
(contest) =>
contest.status.toLowerCase() === 'registered' + type.toLowerCase() ||
contest.status.toLowerCase() === `registered${type.toLowerCase()}` ||
contest.status.toLowerCase() === type.toLowerCase()
)

data.sort((a, b) => +new Date(a.startTime) - +new Date(b.startTime))
data.sort(
(a, b) => new Date(a.startTime).getTime() - new Date(b.startTime).getTime()
)

return data.length === 0 ? (
<></>
) : (
return data.length === 0 ? null : (
<>
<ContestCardCarousel itemsPerSlide={3} title={title} data={data} />
<ContestCardCarousel itemsPerSlide={2} title={title} data={data} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ export default function ContestTabs({ contestId }: { contestId: string }) {
const pathname = usePathname()

const isCurrentTab = (tab: string) => {
if (tab === '') return pathname === `/contest/${id}`
if (tab === '') {
return pathname === `/contest/${id}`
}
return pathname.startsWith(`/contest/${id}/${tab}`)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ export const columns: ColumnDef<Contest>[] = [
header: 'Period',
accessorKey: 'period',
cell: ({ row }) =>
dateFormatter(row.original.startTime, 'YYYY-MM-DD') +
' ~ ' +
dateFormatter(row.original.endTime, 'YYYY-MM-DD')
`${dateFormatter(row.original.startTime, 'YYYY-MM-DD')} ~ ${dateFormatter(
row.original.endTime,
'YYYY-MM-DD'
)}`
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,16 @@ export default async function RegisteredContestTable({
const data = await getFinishedContests(search)

return (
<>
<DataTable
data={data}
columns={columns}
headerStyle={{
title: 'text-left w-2/5 md:w-1/2',
status: 'w-1/5 md:w-1/6',
participants: 'w-1/5 md:w-1/6',
period: 'w-1/5 md:w-1/3'
}}
linked
/>
</>
<DataTable
data={data}
columns={columns}
headerStyle={{
title: 'text-left w-2/5 md:w-1/2',
status: 'w-1/5 md:w-1/6',
participants: 'w-1/5 md:w-1/6',
period: 'w-1/5 md:w-1/3'
}}
linked
/>
)
}
Loading
Loading