diff --git a/pages/api/fakeRanking.ts b/pages/api/fakeRanking.ts
index eb93f4d..d7eb206 100644
--- a/pages/api/fakeRanking.ts
+++ b/pages/api/fakeRanking.ts
@@ -31,7 +31,10 @@ export default async function handler(
data = data.reverse();
}
}
-
+ // fake loading time
+ await new Promise((resolve) =>
+ setTimeout(resolve, 250 + Math.random() * 1000)
+ );
res.status(200).json({ data });
}
diff --git a/pages/dashboard/ranking.tsx b/pages/dashboard/ranking.tsx
index 2e310e9..6428f23 100644
--- a/pages/dashboard/ranking.tsx
+++ b/pages/dashboard/ranking.tsx
@@ -1,6 +1,7 @@
import { m, Variants } from "framer-motion";
import Head from "next/head";
import { ReactElement, useEffect, useState } from "react";
+import Loading from "../../components/common/Loading";
import DashLayout from "../../layouts/DashLayout";
import { fakeDataEntry } from "../api/fakeRanking";
@@ -8,13 +9,16 @@ function Ranking() {
const [sortBy, setSortBy] = useState("netWorth");
const [sortAsc, setSortAsc] = useState(false);
const [fakeData, setFakeData] = useState([]);
+ const [dataLoaded, setDataLoaded] = useState(false);
useEffect(() => {
+ setDataLoaded(false);
// fetch data from api on change to sort method
fetch(`/api/fakeRanking?s=${sortBy}&a=${sortAsc}`)
.then((res) => res.json())
.then((data) => {
setFakeData(data.data);
+ setDataLoaded(true);
});
}, [sortBy, sortAsc]);
@@ -23,13 +27,9 @@ function Ranking() {
if (sortBy != props.sortType) {
return (
);
}
return (
Ranking - InvestBot
-
+
{/* hidden if smaller than lg */}
{/* TODO: responsive for extremely skinny displays (i.e. galaxy fold), or really for mobile entirely so info is not lost */}
{/* Column names and arrows */}
@@ -148,68 +140,69 @@ function Ranking() {
Daily
-
+
{
- // generate table rows
- fakeData.map((entry: fakeDataEntry, index) => {
- // if daily change is negative, make it red
- let changeClass = " text-lime-500";
- if (entry.dailyChangePercent < 0) {
- changeClass = " text-red-500";
- }
- return (
-
-
-
- {index + 1}
-
-
- {entry.name}
-
- {entry.netWorth.toLocaleString("en-US")}
-
- {entry.points.toLocaleString("en-US")}
-
-
- {entry.shares.toLocaleString("en-US")}
-
-
- {(
- Math.round(entry.dailyChangePercent * 1000) / 10
- ).toFixed(1) + "%"}
-
-
-
- );
- })
+ // if data is not loaded, loading div
+ !dataLoaded ? (
+
+
+
This is fake delay :)
+
+ ) : (
+
+ {
+ // generate table rows
+ fakeData.map((entry: fakeDataEntry, index) => {
+ // if daily change is negative, make it red
+ let changeClass = " text-lime-500";
+ if (entry.dailyChangePercent < 0) {
+ changeClass = " text-red-500";
+ }
+ return (
+
+