File tree Expand file tree Collapse file tree 6 files changed +21
-6
lines changed
Expand file tree Collapse file tree 6 files changed +21
-6
lines changed Original file line number Diff line number Diff 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 >
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 11import { HttpLink } from "@apollo/client" ;
22import { ApolloClient , InMemoryCache } from "@apollo/client-integration-nextjs" ;
3+ import { PersistedQueryLink } from "@apollo/client/link/persisted-queries" ;
4+ import { sha256 } from "crypto-hash" ;
35import 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 */
1012export 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}
Original file line number Diff line number Diff line change 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" ,
You can’t perform that action at this time.
0 commit comments