Skip to content

Commit

Permalink
Feat: added round support
Browse files Browse the repository at this point in the history
  • Loading branch information
Akalanka47000 committed Oct 14, 2023
1 parent aeda28e commit aa55da1
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"dependencies": {
"@reduxjs/toolkit": "1.9.5",
"@sliit-foss/bashaway-ui": "0.5.1",
"@sliit-foss/bashaway-ui": "0.10.2",
"framer-motion": "10.14.0",
"jwt-decode": "^3.1.2",
"lodash": "4.17.21",
Expand Down
80 changes: 76 additions & 4 deletions pnpm-lock.yaml

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

25 changes: 18 additions & 7 deletions src/pages/home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ import { ScoreCard } from "@/components/home";
import { filters as filterData, sorts as sortData } from "@/filters";
import { useTitle } from "@/hooks";
import { useFetchLeaderboardQuery } from "@/store/api";
import { AnimatedSwitcher, Filters, NoRecords, Pagination, Sorts } from "@sliit-foss/bashaway-ui/components";
import {
AnimatedSwitcher,
Filters,
NoRecords,
Pagination,
Sorts,
TwinSwitch
} from "@sliit-foss/bashaway-ui/components";
import { useRound } from "@sliit-foss/bashaway-ui/hooks";
import { Footnote, Title } from "@sliit-foss/bashaway-ui/typography";
import { computeFilterQuery, computeSortQuery } from "@sliit-foss/bashaway-ui/utils";

Expand All @@ -13,22 +21,25 @@ const Home = () => {
const [filters, setFilters] = useState(computeFilterQuery(filterData));
const [sorts, setSorts] = useState(computeSortQuery(sortData));

const { data: scores, isFetching } = useFetchLeaderboardQuery({ page, filters, sorts });
const { rounds, round, roundKey, onRoundChange } = useRound();

useTitle("Leaderboard | Bashaway");
const { data: scores, isFetching } = useFetchLeaderboardQuery({ page, filters, sorts, round });

useEffect(() => {
if (page !== 1) setPage(1);
}, [filters, sorts]);
}, [filters, sorts, round]);

useTitle("Leaderboard | Bashaway");

return (
<>
<div className="w-full flex flex-col justify-center items-center gap-6 mb-8 max-w-4xl">
<div className="flex flex-col items-center gap-2 md:gap-1 mb-6 pointer-events-none">
<Title className="tracking-normal">The Leaderboard</Title>
<Footnote className="text-black/40 max-w-[500px] text-xl lg:text-center leading-6">
<div className="flex flex-col items-center gap-2 md:gap-1 mb-2">
<Title className="tracking-normal pointer-events-none">The Leaderboard</Title>
<Footnote className="text-black/40 max-w-[500px] text-xl lg:text-center leading-6 pointer-events-none">
A place where your true colors show off despite all the differences
</Footnote>
<TwinSwitch values={rounds} className="mt-5" onChange={onRoundChange} selectedValue={roundKey} />
</div>
<div className="w-full flex flex-col md:flex-row justify-center items-center gap-6 mb-8">
<Filters filters={filterData} setFilterQuery={setFilters} styles={{ filter: "md:w-3/4" }} />
Expand Down
2 changes: 1 addition & 1 deletion src/store/api/leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const leaderboardApi = createApi({
baseQuery,
endpoints: (builder) => ({
fetchLeaderboard: builder.query({
query: () => `/api/leaderboard`,
query: ({ round }) => `/api/leaderboard?round=${round}`,
transformResponse: (response, _, arg) => {
const { page, filters, sorts } = arg;
response.data = response.data.map((item, index) => ({ ...item, place: index + 1 }));
Expand Down

0 comments on commit aa55da1

Please sign in to comment.