Skip to content

Commit c7776d4

Browse files
committed
style: reformat codebase
1 parent 3439a59 commit c7776d4

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

app/(app)/challenges/[id]/_components/ide/compare-answer.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,18 @@ export default function CompareAnswer({ id }: CompareAnswerProps) {
8686
// 轉換為 CSV 格式
8787
const correctAnswerCSV = tableToCSV(
8888
referenceAnswerResult.columns,
89-
referenceAnswerResult.rows
89+
referenceAnswerResult.rows,
9090
);
9191

9292
const myAnswerCSV = tableToCSV(
9393
lastSubmission.queryResult.columns,
94-
lastSubmission.queryResult.rows
94+
lastSubmission.queryResult.rows,
9595
);
9696

9797
// 如果答案正確,顯示成功訊息
9898
if (
99-
lastSubmission.status === SubmissionStatus.Success ||
100-
compareCSV(correctAnswerCSV, myAnswerCSV)
99+
lastSubmission.status === SubmissionStatus.Success
100+
|| compareCSV(correctAnswerCSV, myAnswerCSV)
101101
) {
102102
return (
103103
<Alert className="border-green-200 bg-green-50 text-green-800">
@@ -125,7 +125,7 @@ export default function CompareAnswer({ id }: CompareAnswerProps) {
125125
<h3 className="text-sm font-medium text-muted-foreground">
126126
答案比較 (左側:正確答案,右側:您的答案)
127127
</h3>
128-
<div className="border rounded-md overflow-hidden">
128+
<div className="overflow-hidden rounded-md border">
129129
<CodeMirrorMerge>
130130
<Original
131131
value={correctAnswerCSV}

lib/apollo.rsc.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import { headers } from "next/headers";
33
import { makeClient } from "./apollo";
44

55
export const { getClient, query, PreloadQuery } = registerApolloClient(async () => {
6-
const header = await headers();
7-
const token = header.get("Authorization")?.split(" ")[1];
6+
const header = await headers();
7+
const token = header.get("Authorization")?.split(" ")[1];
88

9-
return makeClient({ token });
9+
return makeClient({ token });
1010
});

lib/csv-utils.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,30 @@ export function tableToCSV(columns: string[], rows: string[][]): string {
55
// 轉義 CSV 欄位中的特殊字符
66
const escapeCSVField = (field: string): string => {
77
// 如果欄位包含逗號、雙引號或換行符,需要用雙引號包圍
8-
if (field.includes(',') || field.includes('"') || field.includes('\n')) {
8+
if (field.includes(",") || field.includes("\"") || field.includes("\n")) {
99
// 將雙引號轉義為兩個雙引號
10-
return `"${field.replace(/"/g, '""')}"`;
10+
return `"${field.replace(/"/g, "\"\"")}"`;
1111
}
1212
return field;
1313
};
1414

1515
// 處理標題行
16-
const headerRow = columns.map(escapeCSVField).join(',');
17-
16+
const headerRow = columns.map(escapeCSVField).join(",");
17+
1818
// 處理數據行
19-
const dataRows = rows.map(row =>
20-
row.map(escapeCSVField).join(',')
21-
);
19+
const dataRows = rows.map(row => row.map(escapeCSVField).join(","));
2220

2321
// 組合所有行
24-
return [headerRow, ...dataRows].join('\n');
22+
return [headerRow, ...dataRows].join("\n");
2523
}
2624

2725
/**
2826
* 比較兩個 CSV 字符串是否相等(忽略行順序)
2927
*/
3028
export function compareCSV(csv1: string, csv2: string): boolean {
3129
// 分割成行並排序(除了標題行)
32-
const lines1 = csv1.trim().split('\n');
33-
const lines2 = csv2.trim().split('\n');
30+
const lines1 = csv1.trim().split("\n");
31+
const lines2 = csv2.trim().split("\n");
3432

3533
// 如果行數不同,直接返回 false
3634
if (lines1.length !== lines2.length) {

0 commit comments

Comments
 (0)