From 4c74d1433803940f45ea7c96726e5bd8fd543fe9 Mon Sep 17 00:00:00 2001 From: Yi-Jyun Pan Date: Thu, 25 Sep 2025 00:20:52 +0800 Subject: [PATCH 1/3] feat(apollo): enable APQ --- lib/apollo.ts | 5 ++++- package.json | 1 + pnpm-lock.yaml | 9 +++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/apollo.ts b/lib/apollo.ts index 8da1df6..9fa6a4d 100644 --- a/lib/apollo.ts +++ b/lib/apollo.ts @@ -1,5 +1,7 @@ import { HttpLink } from "@apollo/client"; import { ApolloClient, InMemoryCache } from "@apollo/client-integration-nextjs"; +import { PersistedQueryLink } from "@apollo/client/link/persisted-queries"; +import { sha256 } from "crypto-hash"; import buildUri from "./build-uri"; /** @@ -8,6 +10,7 @@ import buildUri from "./build-uri"; * You should add the token to the headers of the request. */ export function makeClient({ token }: { token?: string | null }) { + const persistedQueryLink = new PersistedQueryLink({ sha256 }); const httpLink = new HttpLink({ uri: buildUri("/query"), headers: { @@ -17,6 +20,6 @@ export function makeClient({ token }: { token?: string | null }) { return new ApolloClient({ cache: new InMemoryCache(), - link: httpLink, + link: persistedQueryLink.concat(httpLink), }); } diff --git a/package.json b/package.json index 7433a9b..c82724c 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "babel-plugin-react-compiler": "19.1.0-rc.3", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", + "crypto-hash": "^4.0.0", "foxact": "^0.2.49", "graphql": "^16.11.0", "lucide-react": "^0.544.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a51f6ab..b58de10 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -97,6 +97,9 @@ importers: clsx: specifier: ^2.1.1 version: 2.1.1 + crypto-hash: + specifier: ^4.0.0 + version: 4.0.0 foxact: specifier: ^0.2.49 version: 0.2.49(react@19.2.0-canary-83c88ad4-20250923) @@ -2394,6 +2397,10 @@ packages: resolution: {integrity: sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==} engines: {node: '>= 8'} + crypto-hash@4.0.0: + resolution: {integrity: sha512-KkkFriWj2teXIJOmftIRavBL4q8A7EZV24Nn9sWhIR4hdeS8u+q2A2p0tWZ1m4xVoP1zs3VJjVwwAUnztBb8uw==} + engines: {node: '>=20'} + cssesc@3.0.0: resolution: {integrity: sha512-/Tb/JcjK111nNScGob5MNtsntNM1aCNUDipB/TkwZFhyDrrE47SOx/18wF2bbjgc3ZzCSKW1T5nt5EbFoAz/Vg==} engines: {node: '>=4'} @@ -6877,6 +6884,8 @@ snapshots: shebang-command: 2.0.0 which: 2.0.2 + crypto-hash@4.0.0: {} + cssesc@3.0.0: {} csstype@3.1.3: {} From cadde04405830a4522d0113b51b95b9750d5a752 Mon Sep 17 00:00:00 2001 From: Yi-Jyun Pan Date: Thu, 25 Sep 2025 00:28:45 +0800 Subject: [PATCH 2/3] fix(statistics): simplify resolvedQuestions display --- app/(app)/statistics/_components/board/completed-questions.tsx | 2 +- .../statistics/_components/statistics/resolved-questions.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/(app)/statistics/_components/board/completed-questions.tsx b/app/(app)/statistics/_components/board/completed-questions.tsx index f3d8855..c399f2b 100644 --- a/app/(app)/statistics/_components/board/completed-questions.tsx +++ b/app/(app)/statistics/_components/board/completed-questions.tsx @@ -32,7 +32,7 @@ export default function CompletedQuestionsPercentage() { return ( <> - {solvedQuestions}/{totalQuestions} ({completedPercentage.toFixed(2)}%) + {solvedQuestions}/{totalQuestions} ({completedPercentage.toFixed(0)}%) ); } diff --git a/app/(app)/statistics/_components/statistics/resolved-questions.tsx b/app/(app)/statistics/_components/statistics/resolved-questions.tsx index 8899bf4..9bff4fc 100644 --- a/app/(app)/statistics/_components/statistics/resolved-questions.tsx +++ b/app/(app)/statistics/_components/statistics/resolved-questions.tsx @@ -20,7 +20,7 @@ export default function ResolvedQuestions() { const { data } = useSuspenseQuery(RESOLVED_QUESTIONS); const totalQuestions = data.me.submissionStatistics.totalQuestions; const solvedQuestions = data.me.submissionStatistics.solvedQuestions; - const resolvedQuestions = solvedQuestions / totalQuestions; + const resolvedQuestions = solvedQuestions / totalQuestions * 100; return (
From 9b99647d30553493d94d24c4fedf89d9694c62fc Mon Sep 17 00:00:00 2001 From: Yi-Jyun Pan Date: Thu, 25 Sep 2025 00:32:30 +0800 Subject: [PATCH 3/3] fix: bad percentage calculation when totalSolvedQuestions is zero --- app/(app)/challenges/_components/header/index.tsx | 4 +++- .../statistics/_components/board/completed-questions.tsx | 2 +- .../statistics/_components/statistics/resolved-questions.tsx | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/(app)/challenges/_components/header/index.tsx b/app/(app)/challenges/_components/header/index.tsx index a11188a..42a94a1 100644 --- a/app/(app)/challenges/_components/header/index.tsx +++ b/app/(app)/challenges/_components/header/index.tsx @@ -24,6 +24,8 @@ export default function Header() { const totalSolvedQuestions = data.me.submissionStatistics.solvedQuestions; const totalAttemptedQuestions = data.me.submissionStatistics.attemptedQuestions; + const completedPercentage = totalQuestions > 0 ? (totalSolvedQuestions / totalQuestions) * 100 : 0; + return (
@@ -51,7 +53,7 @@ export default function Header() { variant="primary" cols={10} rows={4} - progress={(totalSolvedQuestions / totalQuestions) * 100} + progress={completedPercentage} />
diff --git a/app/(app)/statistics/_components/board/completed-questions.tsx b/app/(app)/statistics/_components/board/completed-questions.tsx index c399f2b..ddc85a0 100644 --- a/app/(app)/statistics/_components/board/completed-questions.tsx +++ b/app/(app)/statistics/_components/board/completed-questions.tsx @@ -28,7 +28,7 @@ export default function CompletedQuestionsPercentage() { const totalQuestions = data.me.submissionStatistics.totalQuestions; const solvedQuestions = data.me.submissionStatistics.solvedQuestions; - const completedPercentage = (solvedQuestions / totalQuestions) * 100; + const completedPercentage = totalQuestions > 0 ? (solvedQuestions / totalQuestions) * 100 : 0; return ( <> diff --git a/app/(app)/statistics/_components/statistics/resolved-questions.tsx b/app/(app)/statistics/_components/statistics/resolved-questions.tsx index 9bff4fc..e998b31 100644 --- a/app/(app)/statistics/_components/statistics/resolved-questions.tsx +++ b/app/(app)/statistics/_components/statistics/resolved-questions.tsx @@ -20,12 +20,12 @@ export default function ResolvedQuestions() { const { data } = useSuspenseQuery(RESOLVED_QUESTIONS); const totalQuestions = data.me.submissionStatistics.totalQuestions; const solvedQuestions = data.me.submissionStatistics.solvedQuestions; - const resolvedQuestions = solvedQuestions / totalQuestions * 100; + const resolvedQuestions = totalQuestions > 0 ? (solvedQuestions / totalQuestions) * 100 : 0; return (
你攻克了 {resolvedQuestions.toFixed(0)}% 的題目! - +
); }