Skip to content

Commit

Permalink
DUMMY data
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-dudu committed Jan 22, 2025
1 parent 3fa2f6e commit 0831a3e
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 18 deletions.
143 changes: 130 additions & 13 deletions src/Components/CourtsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,130 @@ const CourtsList: React.FC = () => {
fetchCourts();
}, []);

const dummy = [
{
courts: [
{
available: true,
name: "Court 5",
occupiedUntil: "2025-01-20T11:23:09.874336",
surface: "Tartan",
lights: true,
courtID: "5",
},
],
googleMapsLink: "https://maps.app.goo.gl/C8g62sqJgnEQduAK8",
locationID: "2",
address: "Drumul Taberei 53, București 061362",
coordinates: [44.421714958074254, 26.030068288094757],
courtName: "Parcul Drumul Taberei",
},
{
courts: [
{
available: true,
name: "Court 1",
occupiedUntil: "2025-01-18T20:24:35.902708",
surface: "Tartan",
lights: true,
courtID: "1",
},
{
available: true,
courtID: "2",
lights: false,
name: "Court 2",
occupiedUntil: "2025-01-22T10:00:03.813622",
surface: "Tartan",
},
{
available: false,
courtID: "3",
lights: false,
name: "Court 3",
occupiedUntil: "2025-01-22T11:31:17.411916",
surface: "Tartan",
},
{
available: true,
name: "Court 4",
occupiedUntil: "2025-01-20T14:08:13.252996",
surface: "Tartan",
lights: false,
courtID: "4",
},
],
googleMapsLink: "https://maps.app.goo.gl/182ua82Pqp9G67N48",
locationID: "1",
address: "Drumul Lunca Cetății 211",
coordinates: [44.40045060210415, 26.17353510803108],
courtName: "Parc Sportiv Lunca Cetății",
},
{
courts: [
{
available: false,
courtID: "9",
lights: false,
name: "Court 9",
occupiedUntil: "2025-01-22T11:00:28.895782",
surface: "Tartan",
},
{
available: true,
name: "Court 10",
occupiedUntil: "2025-01-18T12:26:58.955099",
surface: "Tartan",
lights: false,
courtID: "10",
},
],
googleMapsLink: "https://maps.app.goo.gl/PbWrLTe2zuz2NRAh9",
locationID: "4",
address: "Calea Giulești",
coordinates: [44.460807050214385, 26.04390284599664],
courtName: "Parcul Marin Preda",
},
{
courts: [
{
available: true,
name: "Court 6",
occupiedUntil: "2025-01-21T15:36:31.705315",
surface: "Tartan",
lights: true,
courtID: "6",
},
{
available: true,
name: "Court 7",
occupiedUntil: "2025-01-18T19:26:58.955099",
surface: "Tartan",
lights: true,
courtID: "7",
},
{
available: false,
courtID: "8",
lights: true,
name: "Court 8",
occupiedUntil: "2025-01-22T11:31:33.413979",
surface: "Tartan",
},
],
googleMapsLink: "https://maps.app.goo.gl/ummyXqJnMi9by3vs6",
locationID: "3",
address: "Bulevardul Unirii",
coordinates: [44.4254754065915, 26.116106045190428],
courtName: "Unirii",
},
];

const fetchCourts = async () => {
try {
const response = await fetch(process.env.REACT_APP_COURT_GET_LINK || "");
const data = await response.json();
setLocations(data.body);
setLocations(dummy);
} catch (error) {
console.error("Error fetching courts:", error);
} finally {
Expand All @@ -35,15 +154,17 @@ const CourtsList: React.FC = () => {
setExpandedLocation((prev) => (prev === locationID ? null : locationID));
};

const now = 1737534968461;

const getCourtStatusClass = (court: any) => {
const occupiedUntil2 = new Date(court.occupiedUntil);

const occupiedSince = new Date(occupiedUntil2);
occupiedSince.setHours(occupiedSince.getHours() - 1);
const currentTime = new Date();
console.log("currentTime.getTime()", currentTime.getTime());

const timeDiffInHours =
(currentTime.getTime() - occupiedSince.getTime()) / 3600000;
const timeDiffInHours = (now - occupiedSince.getTime()) / 3600000;

if (court.available && timeDiffInHours >= 2) {
return "available";
Expand All @@ -63,29 +184,25 @@ const CourtsList: React.FC = () => {
);
}

console.log("locations", locations);

return (
<div className="parentWrapper">
<Grid container spacing={2}>
{locations.map((location: any) => {
const availableCourts = location.courts.filter(
(court: any) =>
court.available &&
(new Date().getTime() - new Date(court.occupiedUntil).getTime()) /
3600000 >
1
(now - new Date(court.occupiedUntil).getTime()) / 3600000 > 1
).length;

const allFieldsAvailable = location.courts.length === availableCourts;

const likelyAvailableCourts = location.courts.filter(
(court: any) =>
court.available &&
(new Date().getTime() - new Date(court.occupiedUntil).getTime()) /
3600000 >
0.1 &&
(new Date().getTime() - new Date(court.occupiedUntil).getTime()) /
3600000 <
1
(now - new Date(court.occupiedUntil).getTime()) / 3600000 > 0.1 &&
(now - new Date(court.occupiedUntil).getTime()) / 3600000 < 1
).length;

const takenCourts = location.courts.filter(
Expand Down Expand Up @@ -153,7 +270,7 @@ const CourtsList: React.FC = () => {
occupiedSince.setHours(occupiedSince.getHours() - 1);

const timeSinceOccupied = Math.round(
(new Date().getTime() - occupiedSince.getTime()) / 60000 // in minutes
(now - occupiedSince.getTime()) / 60000 // in minutes
);

return (
Expand Down
5 changes: 5 additions & 0 deletions src/pages/HowItWorks.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
display: flex;
flex-direction: column;
padding: 12px;
// align-items: flex-start;

p {
// text-align: justify;
}
}
22 changes: 17 additions & 5 deletions src/pages/HowItWorks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,23 @@ const HowItWorks = (props: Props) => {
return (
<div className="howItWorksParent">
<h1>{t("howItWorks.title")}</h1>
<p>{t("howItWorks.p1")}</p>
<p>{t("howItWorks.p2")}</p>
<p>{t("howItWorks.p3")}</p>
<p>{t("howItWorks.p4")}</p>
<p>{t("howItWorks.p5")}</p>
<ul>
<li>
<p>{t("howItWorks.p1")}</p>
</li>
<li>
<p>{t("howItWorks.p2")}</p>
</li>
<li>
<p>{t("howItWorks.p3")}</p>
</li>
<li>
<p>{t("howItWorks.p4")}</p>
</li>
<li>
<p>{t("howItWorks.p5")}</p>
</li>
</ul>
</div>
);
};
Expand Down

0 comments on commit 0831a3e

Please sign in to comment.