From f97c1ef4f4731db5b16afef8ac49e252f992b56b Mon Sep 17 00:00:00 2001 From: Raphael Arce Date: Thu, 13 Jul 2023 12:01:24 +0200 Subject: [PATCH] feat: split up show point modal and get point data, added loading screen that is shown before receiving the data Signed-off-by: Raphael Arce --- src/components/Icons/Spinner.tsx | 22 ++++++ src/components/Icons/index.tsx | 1 + src/components/PointInfoModal/index.tsx | 97 +++++++++++++++---------- src/components/filter/FilterLayer.tsx | 10 ++- src/components/map/Map.tsx | 6 +- 5 files changed, 90 insertions(+), 46 deletions(-) create mode 100644 src/components/Icons/Spinner.tsx diff --git a/src/components/Icons/Spinner.tsx b/src/components/Icons/Spinner.tsx new file mode 100644 index 0000000..7cd3253 --- /dev/null +++ b/src/components/Icons/Spinner.tsx @@ -0,0 +1,22 @@ +export const Spinner = () => { + return ( + <> + + + ); +}; diff --git a/src/components/Icons/index.tsx b/src/components/Icons/index.tsx index a2652ff..65b1ec1 100644 --- a/src/components/Icons/index.tsx +++ b/src/components/Icons/index.tsx @@ -50,3 +50,4 @@ export { ArrowDown } from "./ArrowDown"; export { ArrowUp } from "./ArrowUp"; export { Box } from "./Box"; export { Trash } from "./Trash"; +export { Spinner } from "./Spinner"; diff --git a/src/components/PointInfoModal/index.tsx b/src/components/PointInfoModal/index.tsx index 16e94ae..6019f9c 100644 --- a/src/components/PointInfoModal/index.tsx +++ b/src/components/PointInfoModal/index.tsx @@ -4,12 +4,13 @@ import { BusinessAtPointData, BusinessData, } from "../../../pages/api/getsinglepointdata"; -import { Cross } from "../Icons"; +import { Cross, Spinner } from "../Icons"; export interface PointInfoModalType { poinInfoModalOpen: boolean; setPoinInfoModalOpen: (date: boolean) => void; businessAtPointData: BusinessAtPointData; + setBusinessAtPoint: (businessAtPoint: undefined) => void; color: string; } @@ -67,35 +68,43 @@ export const PointInfoModal: FC = ({ poinInfoModalOpen, setPoinInfoModalOpen, businessAtPointData, + setBusinessAtPoint, color, }) => { function closeModal() { setPoinInfoModalOpen(false); + setBusinessAtPoint(undefined); } return ( <> - {businessAtPointData && ( - -
- - - {/* This element is to trick the browser into centering the modal contents. */} + +
+ <> + + {/* This element is to trick the browser into centering the modal + contents. */} -
@@ -106,17 +115,22 @@ export const PointInfoModal: FC = ({ />
- Eingetragene Unternehmen ( - {businessAtPointData.businesses.length}) -
-
- Für den Standort: {businessAtPointData.latitude},{" "} - {businessAtPointData.longitude} -
-
- Planungsraum:{" "} - {businessAtPointData.businesses[0].planungsraum} + Eingetragene Unternehmen{" "} + {businessAtPointData && + `(${businessAtPointData.businesses.length})`}
+ {businessAtPointData && ( + <> +
+ Für den Standort: {businessAtPointData.latitude},{" "} + {businessAtPointData.longitude} +
+
+ Planungsraum:{" "} + {businessAtPointData.businesses[0].planungsraum} +
+ + )}
-
-
- )} + +
+
); }; diff --git a/src/components/filter/FilterLayer.tsx b/src/components/filter/FilterLayer.tsx index 7280ae2..d578c7f 100644 --- a/src/components/filter/FilterLayer.tsx +++ b/src/components/filter/FilterLayer.tsx @@ -162,11 +162,11 @@ export const FilterLayer: FC = ({ filterValBezirk, ]); - async function showPointInfo(info) { + async function getPointInfo(info) { const data = await getSinglePointData(info.object.id, info.object.p); - console.log(data); + // the following line is on purpose to reduce fast jumping elements. + await new Promise((resolve) => setTimeout(() => resolve(), 1000)); setPointData(data as BusinessAtPointData); - setPoinInfoModalOpen(true); } function calculatePointRadius(zoom) { @@ -219,7 +219,8 @@ export const FilterLayer: FC = ({ getFillColor: layersData[layerId].color, // [86, 189, 102], opacity: layerOpacity, onClick: (info) => { - showPointInfo(info); + setPoinInfoModalOpen(true); + getPointInfo(info); }, transitions: { // transition with a duration of 3000ms @@ -308,6 +309,7 @@ export const FilterLayer: FC = ({ poinInfoModalOpen={poinInfoModalOpen} setPoinInfoModalOpen={setPoinInfoModalOpen} businessAtPointData={pointData!} + setBusinessAtPoint={setPointData} >
= ({