Skip to content

Commit 08c8a21

Browse files
authored
Merge pull request #8 from database-playground/pan93412/dbp-63-enable-apq-on-frontend
feat(apollo): enable APQ
2 parents fced4d9 + 9b99647 commit 08c8a21

File tree

6 files changed

+21
-6
lines changed

6 files changed

+21
-6
lines changed

app/(app)/challenges/_components/header/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export default function Header() {
2424
const totalSolvedQuestions = data.me.submissionStatistics.solvedQuestions;
2525
const totalAttemptedQuestions = data.me.submissionStatistics.attemptedQuestions;
2626

27+
const completedPercentage = totalQuestions > 0 ? (totalSolvedQuestions / totalQuestions) * 100 : 0;
28+
2729
return (
2830
<header className="flex items-center justify-between pb-6">
2931
<div className="space-y-1 tracking-wide">
@@ -51,7 +53,7 @@ export default function Header() {
5153
variant="primary"
5254
cols={10}
5355
rows={4}
54-
progress={(totalSolvedQuestions / totalQuestions) * 100}
56+
progress={completedPercentage}
5557
/>
5658
</div>
5759
</header>

app/(app)/statistics/_components/board/completed-questions.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ export default function CompletedQuestionsPercentage() {
2828

2929
const totalQuestions = data.me.submissionStatistics.totalQuestions;
3030
const solvedQuestions = data.me.submissionStatistics.solvedQuestions;
31-
const completedPercentage = (solvedQuestions / totalQuestions) * 100;
31+
const completedPercentage = totalQuestions > 0 ? (solvedQuestions / totalQuestions) * 100 : 0;
3232

3333
return (
3434
<>
35-
{solvedQuestions}/{totalQuestions} ({completedPercentage.toFixed(2)}%)
35+
{solvedQuestions}/{totalQuestions} ({completedPercentage.toFixed(0)}%)
3636
</>
3737
);
3838
}

app/(app)/statistics/_components/statistics/resolved-questions.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ export default function ResolvedQuestions() {
2020
const { data } = useSuspenseQuery(RESOLVED_QUESTIONS);
2121
const totalQuestions = data.me.submissionStatistics.totalQuestions;
2222
const solvedQuestions = data.me.submissionStatistics.solvedQuestions;
23-
const resolvedQuestions = solvedQuestions / totalQuestions;
23+
const resolvedQuestions = totalQuestions > 0 ? (solvedQuestions / totalQuestions) * 100 : 0;
2424

2525
return (
2626
<div className="flex flex-col gap-1">
2727
你攻克了 {resolvedQuestions.toFixed(0)}% 的題目!
28-
<Progress className="max-w-[50%]" value={resolvedQuestions * 100} />
28+
<Progress className="max-w-[50%]" value={resolvedQuestions} />
2929
</div>
3030
);
3131
}

lib/apollo.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { HttpLink } from "@apollo/client";
22
import { ApolloClient, InMemoryCache } from "@apollo/client-integration-nextjs";
3+
import { PersistedQueryLink } from "@apollo/client/link/persisted-queries";
4+
import { sha256 } from "crypto-hash";
35
import buildUri from "./build-uri";
46

57
/**
@@ -8,6 +10,7 @@ import buildUri from "./build-uri";
810
* You should add the token to the headers of the request.
911
*/
1012
export function makeClient({ token }: { token?: string | null }) {
13+
const persistedQueryLink = new PersistedQueryLink({ sha256 });
1114
const httpLink = new HttpLink({
1215
uri: buildUri("/query"),
1316
headers: {
@@ -17,6 +20,6 @@ export function makeClient({ token }: { token?: string | null }) {
1720

1821
return new ApolloClient({
1922
cache: new InMemoryCache(),
20-
link: httpLink,
23+
link: persistedQueryLink.concat(httpLink),
2124
});
2225
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"babel-plugin-react-compiler": "19.1.0-rc.3",
4343
"class-variance-authority": "^0.7.1",
4444
"clsx": "^2.1.1",
45+
"crypto-hash": "^4.0.0",
4546
"foxact": "^0.2.49",
4647
"graphql": "^16.11.0",
4748
"lucide-react": "^0.544.0",

pnpm-lock.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)