Skip to content

Commit 9b22e86

Browse files
committed
style: reformat codebase
1 parent eac1594 commit 9b22e86

File tree

17 files changed

+178
-143
lines changed

17 files changed

+178
-143
lines changed

app/(app)/challenges/[id]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ export const metadata: Metadata = {
44
title: "挑戰題目",
55
};
66

7-
export default function ChallengePage({ params }: { params: { id: string } }) {
7+
export default function ChallengePage(/* _props: { params: Promise<{ id: string }> } */) {
88
return <div>ChallengePage</div>;
99
}

app/(app)/challenges/_filter/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ export default function FilterSection({
1717
setTags,
1818
}: FilterSectionProps) {
1919
return (
20-
<aside className="flex flex-col gap-8 p-6 bg-gray-100 min-h-[50dvh] w-[25%] rounded">
20+
<aside
21+
className={`
22+
flex min-h-[50dvh] w-[25%] flex-col gap-8 rounded bg-gray-100 p-6
23+
`}
24+
>
2125
<SearchFilterSection value={search} onChange={setSearch} />
2226
<TagFilterSection value={tags} onChange={setTags} />
2327
</aside>

app/(app)/challenges/_filter/search.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ import { Input } from "@/components/ui/input";
22
import { SearchIcon } from "lucide-react";
33

44
export interface SearchFilterSectionProps {
5-
value: string;
6-
onChange: (value: string) => void;
5+
value: string;
6+
onChange: (value: string) => void;
77
}
88

99
export default function SearchFilterSection({ value, onChange }: SearchFilterSectionProps) {
10-
return (
11-
<div className="space-y-2">
12-
<label className="flex items-center gap-2 font-bold">
13-
<SearchIcon className="size-4" />
14-
搜尋
15-
</label>
16-
<Input type="text" placeholder="搜尋" value={value} onChange={(e) => onChange(e.target.value)} />
17-
<p className="text-sm text-muted-foreground">
18-
可以搜尋題目標題、題幹內容,或者是類別。
19-
</p>
20-
</div>
21-
)
10+
return (
11+
<div className="space-y-2">
12+
<label className="flex items-center gap-2 font-bold">
13+
<SearchIcon className="size-4" />
14+
搜尋
15+
</label>
16+
<Input type="text" placeholder="搜尋" value={value} onChange={(e) => onChange(e.target.value)} />
17+
<p className="text-sm text-muted-foreground">
18+
可以搜尋題目標題、題幹內容,或者是類別。
19+
</p>
20+
</div>
21+
);
2222
}

app/(app)/challenges/_filter/tag.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import { Checkbox } from "@/components/ui/checkbox";
22
import { Label } from "@/components/ui/label";
3-
import { FilterIcon } from "lucide-react";
4-
import {
5-
difficultyTranslation,
6-
solvedStatusTranslation,
7-
type Difficulty,
8-
type SolvedStatus,
9-
} from "../model";
103
import { QuestionDifficulty } from "@/gql/graphql";
4+
import { FilterIcon } from "lucide-react";
5+
import { type Difficulty, difficultyTranslation, type SolvedStatus, solvedStatusTranslation } from "../model";
116

127
export interface TagState {
138
solvedStatus: SolvedStatus[];
@@ -60,7 +55,7 @@ export default function TagFilterSection({
6055
標籤
6156
</label>
6257

63-
<div className="space-y-2 text-sm text-muted-foreground mb-4">
58+
<div className="mb-4 space-y-2 text-sm text-muted-foreground">
6459
解題狀態
6560
<div className="mt-2 space-y-2">
6661
<TagCheckbox

app/(app)/challenges/_header/index.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"use client";
22

3-
import { useSuspenseQuery } from "@apollo/client/react";
43
import { GridProgress } from "@/components/ui/grid-progress";
54
import { graphql } from "@/gql";
5+
import { useSuspenseQuery } from "@apollo/client/react";
66

77
const CHALLENGE_STATISTICS_QUERY = graphql(`
88
query ChallengeStatisticsQuery {
@@ -21,8 +21,7 @@ export default function Header() {
2121

2222
const totalQuestions = data.me.submissionStatistics.totalQuestions;
2323
const totalSolvedQuestions = data.me.submissionStatistics.solvedQuestions;
24-
const totalAttemptedQuestions =
25-
data.me.submissionStatistics.attemptedQuestions;
24+
const totalAttemptedQuestions = data.me.submissionStatistics.attemptedQuestions;
2625

2726
return (
2827
<header className="flex items-center justify-between pb-6">
@@ -41,7 +40,12 @@ export default function Header() {
4140
</p>
4241
</div>
4342

44-
<div className="hidden md:block">
43+
<div
44+
className={`
45+
hidden
46+
md:block
47+
`}
48+
>
4549
<GridProgress
4650
variant="primary"
4751
cols={10}
@@ -87,16 +91,13 @@ export function HeaderDescription({
8791
if (totalSolvedQuestions > 0) {
8892
return (
8993
<>
90-
你目前已經嘗試作答了 {totalAttemptedQuestions} 題,其中攻克了{" "}
91-
{totalSolvedQuestions} 題!
94+
你目前已經嘗試作答了 {totalAttemptedQuestions} 題,其中攻克了 {totalSolvedQuestions} 題!
9295
</>
9396
);
9497
}
9598

9699
if (totalAttemptedQuestions > 0) {
97-
return (
98-
<>你目前已經嘗試作答了 {totalAttemptedQuestions} 題,祝你成功攻克題目!</>
99-
);
100+
return <>你目前已經嘗試作答了 {totalAttemptedQuestions} 題,祝你成功攻克題目!</>;
100101
}
101102

102103
return <>你尚未嘗試作答任何題目,快點試試看你有興趣的題目吧!</>;

app/(app)/challenges/_header/skeleton.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ export default function HeaderSkeleton() {
77
<Skeleton className="h-8 w-64" />
88
<Skeleton className="h-4 w-86" />
99
</div>
10-
11-
<Skeleton className="hidden md:block h-16 w-40" />
10+
11+
<Skeleton
12+
className={`
13+
hidden h-16 w-40
14+
md:block
15+
`}
16+
/>
1217
</div>
1318
);
1419
}

app/(app)/challenges/_question/index.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
import { Badge } from "@/components/ui/badge";
2+
import { type FragmentType, graphql, readFragment } from "@/gql";
23
import { QuestionDifficulty } from "@/gql/graphql";
34
import { SwordIcon } from "lucide-react";
45
import Link from "next/link";
5-
import {
6-
difficultyTranslation,
7-
solvedStatusTranslation,
8-
type SolvedStatus,
9-
} from "../model";
10-
import { graphql, readFragment, type FragmentType } from "@/gql";
6+
import { difficultyTranslation, type SolvedStatus, solvedStatusTranslation } from "../model";
117
import { getQuestionSolvedStatus } from "./solved-status";
128

139
const QUESTION_CARD_FRAGMENT = graphql(`
@@ -45,9 +41,9 @@ export default function QuestionCard({
4541
const solvedStatus = getQuestionSolvedStatus(question);
4642

4743
return (
48-
<div className="flex rounded overflow-hidden">
44+
<div className="flex overflow-hidden rounded">
4945
{/* Question Body */}
50-
<div className="space-y-3 bg-white p-4 flex-1">
46+
<div className="flex-1 space-y-3 bg-white p-4">
5147
<div>
5248
<h2 className="font-bold tracking-wider">{question.title}</h2>
5349
<p className="tracking-wide">{descriptionFirstLine}</p>
@@ -73,7 +69,11 @@ function OperationButton({ href }: { href: string }) {
7369
return (
7470
<Link
7571
href={href}
76-
className="bg-gray-100 hover:bg-primary hover:text-white transition-all duration-300 p-2 flex flex-col justify-center items-center gap-2.5"
72+
className={`
73+
flex flex-col items-center justify-center gap-2.5 bg-gray-100 p-2
74+
transition-all duration-300
75+
hover:bg-primary hover:text-white
76+
`}
7777
>
7878
<SwordIcon className="size-4" />
7979
練習
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { graphql, readFragment, type FragmentType } from "@/gql";
1+
import { type FragmentType, graphql, readFragment } from "@/gql";
22
import type { SolvedStatus } from "../model";
33

44
export const QUESTION_SOLVED_STATUS_FRAGMENT = graphql(`
@@ -9,17 +9,17 @@ export const QUESTION_SOLVED_STATUS_FRAGMENT = graphql(`
99
`);
1010

1111
export function getQuestionSolvedStatus(
12-
fragment: FragmentType<typeof QUESTION_SOLVED_STATUS_FRAGMENT>
12+
fragment: FragmentType<typeof QUESTION_SOLVED_STATUS_FRAGMENT>,
1313
): SolvedStatus {
14-
const question = readFragment(QUESTION_SOLVED_STATUS_FRAGMENT, fragment);
14+
const question = readFragment(QUESTION_SOLVED_STATUS_FRAGMENT, fragment);
1515

16-
if (question.solved) {
17-
return "solved";
18-
}
16+
if (question.solved) {
17+
return "solved";
18+
}
1919

20-
if (question.attempted && !question.solved) {
21-
return "unsolved";
22-
}
20+
if (question.attempted && !question.solved) {
21+
return "unsolved";
22+
}
2323

24-
return "not-tried";
24+
return "not-tried";
2525
}

app/(app)/challenges/content.tsx

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
"use client";
22

3+
import { useDebouncedValue } from "foxact/use-debounced-value";
34
import { useState } from "react";
45
import type { TagState } from "./_filter/tag";
5-
import { useDebouncedValue } from 'foxact/use-debounced-value';
66

7+
import { Button } from "@/components/ui/button";
8+
import { graphql } from "@/gql";
79
import { QuestionDifficulty, type QuestionWhereInput } from "@/gql/graphql";
10+
import { useSuspenseQuery } from "@apollo/client/react";
811
import FilterSection from "./_filter";
912
import QuestionCard from "./_question";
10-
import { useSuspenseQuery } from "@apollo/client/react";
11-
import type { SolvedStatus } from "./model";
12-
import { Button } from "@/components/ui/button";
13-
import { graphql } from "@/gql";
1413
import { getQuestionSolvedStatus } from "./_question/solved-status";
14+
import type { SolvedStatus } from "./model";
1515

1616
export const LIST_QUESTIONS = graphql(`
1717
query ListQuestions($where: QuestionWhereInput, $after: Cursor) {
@@ -61,7 +61,7 @@ export default function ChallengePageContent() {
6161
};
6262

6363
return (
64-
<div className="flex gap-4 w-full">
64+
<div className="flex w-full gap-4">
6565
<FilterSection
6666
search={search}
6767
setSearch={setSearch}
@@ -94,17 +94,15 @@ export function ChallengeQuestionsList({
9494
{data?.questions.edges
9595
?.filter(
9696
(question) =>
97-
question &&
98-
question.node &&
99-
solvedStatusContains.includes(
100-
getQuestionSolvedStatus(question.node)
101-
)
97+
question
98+
&& question.node
99+
&& solvedStatusContains.includes(
100+
getQuestionSolvedStatus(question.node),
101+
),
102102
)
103103
.map((question) => {
104104
if (!question || !question.node) return null;
105-
return (
106-
<QuestionCard key={question.node.id} fragment={question.node} />
107-
);
105+
return <QuestionCard key={question.node.id} fragment={question.node} />;
108106
})}
109107

110108
{data?.questions.pageInfo.hasNextPage && (
@@ -125,8 +123,7 @@ export function ChallengeQuestionsList({
125123
},
126124
};
127125
},
128-
})
129-
}
126+
})}
130127
>
131128
載入更多
132129
</Button>

app/(app)/challenges/model.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ export type SolvedStatus = "solved" | "unsolved" | "not-tried";
1111
export type Difficulty = QuestionDifficulty;
1212

1313
export const solvedStatusTranslation: Record<SolvedStatus, string> = {
14-
solved: "✅ 已經解決",
15-
unsolved: "尚未解決",
16-
"not-tried": "還沒嘗試",
14+
solved: "✅ 已經解決",
15+
unsolved: "尚未解決",
16+
"not-tried": "還沒嘗試",
1717
};
1818

1919
export const difficultyTranslation: Record<Difficulty, string> = {
20-
[QuestionDifficulty.Easy]: "簡單",
21-
[QuestionDifficulty.Medium]: "中等",
22-
[QuestionDifficulty.Hard]: "困難",
23-
[QuestionDifficulty.Unspecified]: "未指定",
20+
[QuestionDifficulty.Easy]: "簡單",
21+
[QuestionDifficulty.Medium]: "中等",
22+
[QuestionDifficulty.Hard]: "困難",
23+
[QuestionDifficulty.Unspecified]: "未指定",
2424
};

0 commit comments

Comments
 (0)