Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/(app)/challenges/_components/header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<header className="flex items-center justify-between pb-6">
<div className="space-y-1 tracking-wide">
Expand Down Expand Up @@ -51,7 +53,7 @@ export default function Header() {
variant="primary"
cols={10}
rows={4}
progress={(totalSolvedQuestions / totalQuestions) * 100}
progress={completedPercentage}
/>
</div>
</header>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)}%)
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className="flex flex-col gap-1">
你攻克了 {resolvedQuestions.toFixed(0)}% 的題目!
<Progress className="max-w-[50%]" value={resolvedQuestions * 100} />
<Progress className="max-w-[50%]" value={resolvedQuestions} />
</div>
);
}
5 changes: 4 additions & 1 deletion lib/apollo.ts
Original file line number Diff line number Diff line change
@@ -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";

/**
Expand All @@ -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: {
Expand All @@ -17,6 +20,6 @@ export function makeClient({ token }: { token?: string | null }) {

return new ApolloClient({
cache: new InMemoryCache(),
link: httpLink,
link: persistedQueryLink.concat(httpLink),
});
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.