Skip to content

Commit 7153276

Browse files
authored
Merge pull request #24 from database-playground/pan93412/dbp-107-需要顯示點數增加數
feat(statistics): render score in RankingEdge
2 parents cc0deae + 7400c99 commit 7153276

File tree

6 files changed

+33
-12
lines changed

6 files changed

+33
-12
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@
44
import { graphql } from "@/gql";
55
import type { RankingPeriod } from "@/gql/graphql";
66
import { useSuspenseQuery } from "@apollo/client/react";
7+
import { ScoreDiff } from "./score";
78

89
const COMPLETED_QUESTIONS_RANKING = graphql(`
910
query CompletedQuestionRanking($period: RankingPeriod!) {
@@ -19,6 +20,7 @@ const COMPLETED_QUESTIONS_RANKING = graphql(`
1920
solvedQuestions
2021
}
2122
}
23+
score
2224
}
2325
}
2426
}
@@ -47,7 +49,9 @@ export default function SolvedQuestionsRanking({
4749
return (
4850
<TableRow key={edge.node.id}>
4951
<TableCell>{edge.node.name}</TableCell>
50-
<TableCell>{edge.node.submissionStatistics.solvedQuestions}</TableCell>
52+
<TableCell>
53+
{edge.node.submissionStatistics.solvedQuestions} (<ScoreDiff score={edge.score} />)
54+
</TableCell>
5155
</TableRow>
5256
);
5357
})}

app/(app)/statistics/_components/ranking/points.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@
44
import { graphql } from "@/gql";
55
import type { RankingPeriod } from "@/gql/graphql";
66
import { useSuspenseQuery } from "@apollo/client/react";
7+
import { ScoreDiff } from "./score";
78

89
const POINTS_RANKING = graphql(`
910
query PointsRanking($period: RankingPeriod!) {
@@ -14,6 +15,7 @@ const POINTS_RANKING = graphql(`
1415
name
1516
totalPoints
1617
}
18+
score
1719
}
1820
}
1921
}
@@ -38,7 +40,9 @@ export default function PointsRanking({ period }: { period: RankingPeriod }) {
3840
return (
3941
<TableRow key={edge.node.id}>
4042
<TableCell>{edge.node.name}</TableCell>
41-
<TableCell>{edge.node.totalPoints}</TableCell>
43+
<TableCell>
44+
{edge.node.totalPoints} (<ScoreDiff score={edge.score} />)
45+
</TableCell>
4246
</TableRow>
4347
);
4448
})}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export function ScoreDiff({ score }: { score: number }) {
2+
if (score > 0) {
3+
return <span className="text-green-800">+{score}</span>;
4+
}
5+
6+
if (score < 0) {
7+
return <span className="text-red-800">-{Math.abs(score)}</span>;
8+
}
9+
10+
return <span className="text-gray-800">無變化</span>;
11+
}

gql/gql.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ type Documents = {
3030
"\n query MaterialsSchemaContent($id: ID!) {\n database(id: $id) {\n id\n schema\n }\n }\n": typeof types.MaterialsSchemaContentDocument,
3131
"\n query MaterialsSchema {\n databases {\n id\n ...MaterialsSchemaCard\n }\n }\n": typeof types.MaterialsSchemaDocument,
3232
"\n query CompletedQuestions {\n me {\n id\n submissionStatistics {\n totalQuestions\n solvedQuestions\n }\n }\n }\n": typeof types.CompletedQuestionsDocument,
33-
"\n query CompletedQuestionRanking($period: RankingPeriod!) {\n ranking(\n first: 10\n filter: { order: DESC, by: COMPLETED_QUESTIONS, period: $period }\n ) {\n edges {\n node {\n id\n name\n submissionStatistics {\n solvedQuestions\n }\n }\n }\n }\n }\n": typeof types.CompletedQuestionRankingDocument,
34-
"\n query PointsRanking($period: RankingPeriod!) {\n ranking(first: 10, filter: { order: DESC, by: POINTS, period: $period }) {\n edges {\n node {\n id\n name\n totalPoints\n }\n }\n }\n }\n": typeof types.PointsRankingDocument,
33+
"\n query CompletedQuestionRanking($period: RankingPeriod!) {\n ranking(\n first: 10\n filter: { order: DESC, by: COMPLETED_QUESTIONS, period: $period }\n ) {\n edges {\n node {\n id\n name\n submissionStatistics {\n solvedQuestions\n }\n }\n score\n }\n }\n }\n": typeof types.CompletedQuestionRankingDocument,
34+
"\n query PointsRanking($period: RankingPeriod!) {\n ranking(first: 10, filter: { order: DESC, by: POINTS, period: $period }) {\n edges {\n node {\n id\n name\n totalPoints\n }\n score\n }\n }\n }\n": typeof types.PointsRankingDocument,
3535
"\n query Points {\n me {\n id\n totalPoints\n\n points(first: 5, orderBy: { field: GRANTED_AT, direction: DESC }) {\n edges {\n node {\n id\n ...PointFragment\n }\n }\n }\n }\n }\n": typeof types.PointsDocument,
3636
"\n fragment PointFragment on Point {\n description\n points\n }\n": typeof types.PointFragmentFragmentDoc,
3737
"\n query ResolvedQuestions {\n me {\n id\n submissionStatistics {\n totalQuestions\n solvedQuestions\n }\n }\n }\n": typeof types.ResolvedQuestionsDocument,
@@ -60,8 +60,8 @@ const documents: Documents = {
6060
"\n query MaterialsSchemaContent($id: ID!) {\n database(id: $id) {\n id\n schema\n }\n }\n": types.MaterialsSchemaContentDocument,
6161
"\n query MaterialsSchema {\n databases {\n id\n ...MaterialsSchemaCard\n }\n }\n": types.MaterialsSchemaDocument,
6262
"\n query CompletedQuestions {\n me {\n id\n submissionStatistics {\n totalQuestions\n solvedQuestions\n }\n }\n }\n": types.CompletedQuestionsDocument,
63-
"\n query CompletedQuestionRanking($period: RankingPeriod!) {\n ranking(\n first: 10\n filter: { order: DESC, by: COMPLETED_QUESTIONS, period: $period }\n ) {\n edges {\n node {\n id\n name\n submissionStatistics {\n solvedQuestions\n }\n }\n }\n }\n }\n": types.CompletedQuestionRankingDocument,
64-
"\n query PointsRanking($period: RankingPeriod!) {\n ranking(first: 10, filter: { order: DESC, by: POINTS, period: $period }) {\n edges {\n node {\n id\n name\n totalPoints\n }\n }\n }\n }\n": types.PointsRankingDocument,
63+
"\n query CompletedQuestionRanking($period: RankingPeriod!) {\n ranking(\n first: 10\n filter: { order: DESC, by: COMPLETED_QUESTIONS, period: $period }\n ) {\n edges {\n node {\n id\n name\n submissionStatistics {\n solvedQuestions\n }\n }\n score\n }\n }\n }\n": types.CompletedQuestionRankingDocument,
64+
"\n query PointsRanking($period: RankingPeriod!) {\n ranking(first: 10, filter: { order: DESC, by: POINTS, period: $period }) {\n edges {\n node {\n id\n name\n totalPoints\n }\n score\n }\n }\n }\n": types.PointsRankingDocument,
6565
"\n query Points {\n me {\n id\n totalPoints\n\n points(first: 5, orderBy: { field: GRANTED_AT, direction: DESC }) {\n edges {\n node {\n id\n ...PointFragment\n }\n }\n }\n }\n }\n": types.PointsDocument,
6666
"\n fragment PointFragment on Point {\n description\n points\n }\n": types.PointFragmentFragmentDoc,
6767
"\n query ResolvedQuestions {\n me {\n id\n submissionStatistics {\n totalQuestions\n solvedQuestions\n }\n }\n }\n": types.ResolvedQuestionsDocument,
@@ -155,11 +155,11 @@ export function graphql(source: "\n query CompletedQuestions {\n me {\n
155155
/**
156156
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
157157
*/
158-
export function graphql(source: "\n query CompletedQuestionRanking($period: RankingPeriod!) {\n ranking(\n first: 10\n filter: { order: DESC, by: COMPLETED_QUESTIONS, period: $period }\n ) {\n edges {\n node {\n id\n name\n submissionStatistics {\n solvedQuestions\n }\n }\n }\n }\n }\n"): (typeof documents)["\n query CompletedQuestionRanking($period: RankingPeriod!) {\n ranking(\n first: 10\n filter: { order: DESC, by: COMPLETED_QUESTIONS, period: $period }\n ) {\n edges {\n node {\n id\n name\n submissionStatistics {\n solvedQuestions\n }\n }\n }\n }\n }\n"];
158+
export function graphql(source: "\n query CompletedQuestionRanking($period: RankingPeriod!) {\n ranking(\n first: 10\n filter: { order: DESC, by: COMPLETED_QUESTIONS, period: $period }\n ) {\n edges {\n node {\n id\n name\n submissionStatistics {\n solvedQuestions\n }\n }\n score\n }\n }\n }\n"): (typeof documents)["\n query CompletedQuestionRanking($period: RankingPeriod!) {\n ranking(\n first: 10\n filter: { order: DESC, by: COMPLETED_QUESTIONS, period: $period }\n ) {\n edges {\n node {\n id\n name\n submissionStatistics {\n solvedQuestions\n }\n }\n score\n }\n }\n }\n"];
159159
/**
160160
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
161161
*/
162-
export function graphql(source: "\n query PointsRanking($period: RankingPeriod!) {\n ranking(first: 10, filter: { order: DESC, by: POINTS, period: $period }) {\n edges {\n node {\n id\n name\n totalPoints\n }\n }\n }\n }\n"): (typeof documents)["\n query PointsRanking($period: RankingPeriod!) {\n ranking(first: 10, filter: { order: DESC, by: POINTS, period: $period }) {\n edges {\n node {\n id\n name\n totalPoints\n }\n }\n }\n }\n"];
162+
export function graphql(source: "\n query PointsRanking($period: RankingPeriod!) {\n ranking(first: 10, filter: { order: DESC, by: POINTS, period: $period }) {\n edges {\n node {\n id\n name\n totalPoints\n }\n score\n }\n }\n }\n"): (typeof documents)["\n query PointsRanking($period: RankingPeriod!) {\n ranking(first: 10, filter: { order: DESC, by: POINTS, period: $period }) {\n edges {\n node {\n id\n name\n totalPoints\n }\n score\n }\n }\n }\n"];
163163
/**
164164
* The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients.
165165
*/

0 commit comments

Comments
 (0)