Skip to content

Commit 722e559

Browse files
committed
feat: move scoreboard scort to the filter action
add display for empty scoreboard
1 parent f8415bf commit 722e559

File tree

9 files changed

+37
-29
lines changed

9 files changed

+37
-29
lines changed

public/locales/bg/common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@
167167
"communities.overview.courses.description": "In the courses of this community, you will be able to learn about new technologies, solve challenges, get feedback and earn bounties.",
168168
"communities.overview.scoreboard.title": "Scoreboard",
169169
"communities.overview.scoreboard.description": "On the scoreboard, you can see which users have accumulated the most reputation by giving valuable feedback to their peers.",
170+
"communities.scoreboard.empty-state.title": "Няма оценки за тази категория.",
170171
"communities.card.estimated": "Estimated Time",
171172
"communities.card.earn": "Earn rewards",
172173
"communities.card.submissions": "{{count}} Изявления",

public/locales/en/common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@
170170
"communities.overview.courses.description": "In the courses of this community, you will be able to learn about new technologies, solve challenges, get feedback and earn bounties.",
171171
"communities.overview.scoreboard.title": "Scoreboard",
172172
"communities.overview.scoreboard.description": "On the scoreboard, you can see which users have accumulated the most reputation by giving valuable feedback to their peers.",
173+
"communities.scoreboard.empty-state.title": "No scores for this category",
173174
"communities.card.estimated": "Estimated Time",
174175
"communities.card.earn": "Earn rewards",
175176
"communities.card.submissions": "{{count}} Submissions",

public/locales/es/common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@
170170
"communities.overview.courses.description": "En los cursos de esta comunidad, podrá aprender sobre nuevas tecnologías, resolver retos, recibir feedbacks y ganar premios.",
171171
"communities.overview.scoreboard.title": "Tabla de Resultados",
172172
"communities.overview.scoreboard.description": "En la tabla de resultados, puede ver qué usuarios han acumulado la mejor reputación dando su valioso feedback a sus compañeras.",
173+
"communities.scoreboard.empty-state.title": "No hay puntuaciones para esta categoría.",
173174
"communities.card.estimated": "Tiempo estimado",
174175
"communities.card.earn": "Gane recompensas",
175176
"communities.card.submissions": "{{count}} Envíos",

public/locales/hr/common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@
154154
"communities.overview.courses.description": "In the courses of this community, you will be able to learn about new technologies, solve challenges, get feedback and earn bounties.",
155155
"communities.overview.scoreboard.title": "Scoreboard",
156156
"communities.overview.scoreboard.description": "On the scoreboard, you can see which users have accumulated the most reputation by giving valuable feedback to their peers.",
157+
"communities.scoreboard.empty-state.title": "Nema bodova za ovu kategoriju.",
157158
"communities.card.estimated": "Estimated Time",
158159
"communities.card.earn": "Earn rewards",
159160
"communities.overview.challenge.rewards": "Nagrade",

src/components/cards/Scoreboard.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ interface ScoreboardCardProps {
1414
feedbacks: number;
1515
score: number;
1616
submissions: number;
17+
submissionPoints: number;
18+
totalPoints?: number;
1719
};
1820
index: number;
1921
}
@@ -42,8 +44,8 @@ export default function ScoreboardCard({ value, index }: ScoreboardCardProps): J
4244
<span>{value.submissions === 1 ? "Submission" : "Submissions"}</span>
4345
</p>
4446
<p className="whitespace-nowrap sm:px-4 px-3 text-xs space-x-1">
45-
<span>{value.score}</span>
46-
<span>{value.score === 1 ? "Total Point" : "Total Points"}</span>
47+
<span>{value.submissionPoints}</span>
48+
<span>{value.submissionPoints === 1 ? "Submission Point" : "Submission Points"}</span>
4749
</p>
4850
<p className="whitespace-nowrap text-xs sm:px-4 px-3 space-x-1">
4951
<span>{value.feedbacks}</span>

src/components/sections/communities/overview/scoreboard/Filter.tsx

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { ChangeEvent, ReactElement, useCallback, useEffect, useState } from "react";
22
import FilterOption from "./_partials/FilterOption";
3-
import { selectList, setLoading, setFilterBy as setScoreboardFilterBy, setScoreboardList, sortScoreboards } from "@/store/feature/communities/scoreboard.slice";
3+
import { setLoading } from "@/store/feature/communities/scoreboard.slice";
44
import { useDispatch } from "@/hooks/useTypedDispatch";
55
import { useRouter } from "next/router";
6-
import { useSelector } from "@/hooks/useTypedSelector";
76
import { filterScoreboards } from "@/store/services/communities/scoreboard.service";
87

98
/**
@@ -76,12 +75,11 @@ export default function Filters(): ReactElement {
7675
const [sortBy, setSortBy] = useState("score");
7776

7877
const dispatch = useDispatch();
79-
const list = useSelector((state) => selectList(state));
80-
const filteredScoreboards = useSelector((state) => selectList(state));
8178
const router = useRouter();
8279
const { slug } = router.query;
8380

8481
const onFilterScoreboards = useCallback(async () => {
82+
dispatch(setLoading(true));
8583
await dispatch(
8684
filterScoreboards({
8785
slug: slug as string,
@@ -90,28 +88,13 @@ export default function Filters(): ReactElement {
9088
locale: router.locale as string,
9189
})
9290
);
93-
const data = filteredScoreboards;
94-
if (data) {
95-
const filteredData = [...data];
96-
dispatch(setScoreboardFilterBy(filterBy));
97-
if (sortBy) {
98-
filteredData?.sort((firstItem, secondItem) => secondItem[sortBy] - firstItem[sortBy]);
99-
}
100-
dispatch(setScoreboardList(filteredData));
101-
}
102-
setLoading(true);
91+
dispatch(setLoading(false));
10392
}, [dispatch, filterBy, router.locale, slug, sortBy]);
10493

10594
useEffect(() => {
10695
onFilterScoreboards();
10796
}, [onFilterScoreboards]);
10897

109-
useEffect(() => {
110-
dispatch(setScoreboardList(sortScoreboards({ sortBy, list })));
111-
// Eslint disable because the list is running the effect infinitely
112-
// eslint-disable-next-line react-hooks/exhaustive-deps
113-
}, [dispatch, sortBy]);
114-
11598
const handleFilterByChange = (event: ChangeEvent<HTMLInputElement>) => {
11699
const newValue = event.target.value;
117100
if (newValue === filterBy) return;

src/components/sections/communities/overview/scoreboard/index.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import ScoreboardCard from "@/components/cards/Scoreboard";
33
import ArrowButton from "@/components/ui/button/Arrow";
44
import { useTranslation } from "next-i18next";
55
import { ReactElement, useState } from "react";
6+
// import Loader from "@/components/ui/button/Loader";
7+
import Loader from "@/components/ui/Loader";
8+
import EmptyState from "@/components/ui/EmptyState";
69

710
/**
811
* Scoreboard Overview index component
@@ -14,7 +17,7 @@ import { ReactElement, useState } from "react";
1417

1518
export default function ScoreboardOverview(): ReactElement {
1619
const { t } = useTranslation();
17-
const { list, filterBy } = useSelector((state) => state.scoreboard);
20+
const { list, filterBy, loading } = useSelector((state) => state.scoreboard);
1821

1922
const [items, setItems] = useState(3);
2023

@@ -24,7 +27,11 @@ export default function ScoreboardOverview(): ReactElement {
2427

2528
return (
2629
<>
27-
{(list && list.length !== 0) || filterBy !== "all" ? (
30+
{loading ? (
31+
<div className="h-full w-full grid">
32+
<Loader className="place-self-center" />
33+
</div>
34+
) : (list && list.length !== 0) || filterBy !== "all" ? (
2835
<div className="flex flex-col w-full overflow-hidden border border-gray-200 border-solid divide-y divide-gray-200 divide-solid rounded-3xl">
2936
{list.slice(0, items).map((item, i) => (
3037
<ScoreboardCard key={`list-element-${i}`} index={i + 1} value={item} />
@@ -38,7 +45,9 @@ export default function ScoreboardOverview(): ReactElement {
3845
)}
3946
</div>
4047
) : (
41-
<></>
48+
<div className=" w-full overflow-hidden border-t border-gray-200 ">
49+
<EmptyState title={t("communities.scoreboard.empty-state.title")} />
50+
</div>
4251
)}
4352
</>
4453
);

src/store/feature/communities/scoreboard.slice.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,15 @@ const scoreboardSlice = createSlice({
4040
initialState,
4141
reducers: {
4242
setScoreboardList: (state, action) => {
43-
state.list = action.payload;
43+
const modifiedList = action.payload?.map((scoreboard: Scoreboard) => ({ ...scoreboard, totalPoints: scoreboard?.submissionPoints + scoreboard?.feedbackPoints }));
44+
// console.log("modifiedList", modifiedList);
45+
state.list = modifiedList;
4446
},
4547
setScoreboardFilteredList: (state, action) => {
46-
state.list = action.payload;
48+
console.log("--- set the scoreboard", action.payload);
49+
const modifiedList = action.payload?.map((scoreboard: Scoreboard) => ({ ...scoreboard, totalPoints: scoreboard?.submissionPoints + scoreboard?.feedbackPoints }));
50+
console.log("modifiedList", modifiedList);
51+
state.list = modifiedList;
4752
},
4853
setLoading: (state, action) => {
4954
state.loading = action.payload;

src/store/services/communities/scoreboard.service.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,16 @@ const scoreboardService = createApi({
4949
"Accept-Language": locale || "en",
5050
},
5151
}),
52-
onQueryStarted: async (_, { dispatch, queryFulfilled }) => {
52+
onQueryStarted: async ({ sortBy }, { dispatch, queryFulfilled }) => {
5353
try {
5454
dispatch(setLoading(true));
5555
const { data } = await queryFulfilled;
56-
dispatch(setScoreboardFilteredList(data));
56+
console.log("data after filter--", data);
57+
const sortedList = [...data];
58+
if (sortBy) {
59+
sortedList?.sort((firstItem, secondItem) => secondItem[sortBy] - firstItem[sortBy]);
60+
}
61+
dispatch(setScoreboardFilteredList(sortedList));
5762
} catch (err) {
5863
console.error(err);
5964
} finally {

0 commit comments

Comments
 (0)