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 f3d8855..ddc85a0 100644
--- a/app/(app)/statistics/_components/board/completed-questions.tsx
+++ b/app/(app)/statistics/_components/board/completed-questions.tsx
@@ -28,11 +28,11 @@ 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 (
<>
- {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..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;
+ const resolvedQuestions = totalQuestions > 0 ? (solvedQuestions / totalQuestions) * 100 : 0;
return (
你攻克了 {resolvedQuestions.toFixed(0)}% 的題目!
-
+
);
}
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: {}