diff --git a/src/components/LeaderBoard/LeaderBoard.js b/src/components/LeaderBoard/LeaderBoard.js
index 1e08aad..e5d2790 100644
--- a/src/components/LeaderBoard/LeaderBoard.js
+++ b/src/components/LeaderBoard/LeaderBoard.js
@@ -5,82 +5,54 @@ import SmallLoader from "../Shared/SmallLoader";
import LeaderBoardCard from "./LeaderBoardCard";
import "./LeaderBoard.scss";
import { useDocumentOnce } from "react-firebase-hooks/firestore";
-import { useQueryParam, NumberParam, StringParam } from "use-query-params";
-import { Link } from "react-router-dom";
-import { useLocation } from "react-router-dom";
-
-const defaultPageSize = 50;
const LeaderBoard = ({ history }) => {
const [leaderBoardInfo, setLeaderBoardInfo] = useState([]);
const [guildInfo, setGuildInfo] = useState({});
const { id } = useParams();
- const [fullLoading, setFullLoading] = useState(true);
- const [hasMore, setHasMore] = useState();
- const [page, setPage] = useQueryParam("page", NumberParam);
- const [pageSize, setPageSize] = useQueryParam("page-size", NumberParam);
-
const [rawLeaderBoardData, loading, error] = useDocumentOnce(firebase.db.collection("Leveling").doc(id));
- const location = useLocation();
-
- useEffect(() => {
- setTimeout(() => {
- window.scrollTo(0, 0);
- }, 100)
- }, [location]);
-
useEffect(() => {
(async () => {
- setFullLoading(true)
if (loading) return;
const data = rawLeaderBoardData.data();
if (!data) {
history.push("/");
}
const leaderBoardData = Object.keys(data || {})
+
.filter(key => data[key].xp)
.sort((a, b) => data[b].xp - data[a].xp)
- .slice(((page || 1) - 1) * (pageSize || defaultPageSize), (page || 1) * (pageSize || defaultPageSize));
+ .slice(0, 101);
const leaderBoardDashBoard = await Promise.all(
leaderBoardData.map(async id => {
const response = await fetch(`${process.env.REACT_APP_API_URL}/resolveuser?user=${id}&platform=discord`);
return { ...(await response.json()), ...data[id] };
})
);
- setFullLoading(loading);
setLeaderBoardInfo(leaderBoardDashBoard);
- setHasMore( Object.keys(data || {}).length > (page || 1) * (pageSize || defaultPageSize));
try {
const guildResponse = await fetch(`${process.env.REACT_APP_API_URL}/resolveguild?guild=${id}`);
const guildJson = await guildResponse.json();
setGuildInfo(prev => guildJson || prev);
} catch (err) {}
})();
- }, [id, rawLeaderBoardData, loading, history, page, pageSize]);
-
+ }, [id, rawLeaderBoardData, loading, history]);
return (
-
- {error &&
There was an error loading the leaderboard
}
+
{guildInfo.name}
- {!fullLoading && (
+ {!loading && (
{leaderBoardInfo.map((user, idx) => (
-
+
))}
-
- {!!(page - 1) && (
- Previous Page
- )}
- {hasMore && Next Page}
-
)}
diff --git a/src/components/LeaderBoard/LeaderBoard.scss b/src/components/LeaderBoard/LeaderBoard.scss
index ab06817..e8f870f 100644
--- a/src/components/LeaderBoard/LeaderBoard.scss
+++ b/src/components/LeaderBoard/LeaderBoard.scss
@@ -25,21 +25,6 @@
padding: 1rem 1.25rem;
margin-bottom: 4rem;
box-shadow: 0px 0px 16px -6px darken(#686464, 10);
- .leaderboard-footer{
- width: 100%;
- display: flex;
- align-items: center;
- justify-content: center;
- a{
- margin: 0 .5rem;
- padding: .5rem 1rem;
- background: var(--disstreamchat-purple);
- border-radius: .35rem;
- &:hover{
- text-decoration: underline;
- }
- }
- }
}
.leaderboard-item {
@@ -100,13 +85,13 @@
align-items: center;
justify-content: center;
border-radius: 50%;
- .leaderboard-item#place-1 & {
+ .leaderboard-item:first-child & {
background: #da9e3b;
}
- .leaderboard-item#place-2 & {
+ .leaderboard-item:nth-child(2) & {
background: #989898;
}
- .leaderboard-item#place-3 & {
+ .leaderboard-item:nth-child(3) & {
background: #ae7441;
}
}
diff --git a/src/components/LeaderBoard/LeaderBoardCard.js b/src/components/LeaderBoard/LeaderBoardCard.js
index 913aa20..8e0ce45 100644
--- a/src/components/LeaderBoard/LeaderBoardCard.js
+++ b/src/components/LeaderBoard/LeaderBoardCard.js
@@ -21,7 +21,7 @@ const LeaderBoardCard = ({ place, level, xp, username, displayAvatarURL }) => {
}, [level, xp]);
return (
-
+
{place}

@@ -33,13 +33,13 @@ const LeaderBoardCard = ({ place, level, xp, username, displayAvatarURL }) => {
{xp > 1000 ? `${(xp / 1000).toFixed(2)}k` : xp}
-