Skip to content

Commit 4ebb3cc

Browse files
authored
feat(generalised tiles): use generalised ft tiles, zoom in on map position to load form
feat(generalised tiles): use generalised ft tiles, zoom in on map position to load form
2 parents 40647d3 + c4b1f99 commit 4ebb3cc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1039
-528
lines changed

.env

Lines changed: 0 additions & 10 deletions
This file was deleted.

.env.dist

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
NEXT_PUBLIC_VECTOR_TILES_ENDPOINT=https://tiles-staging.tree-app.ch
2-
NEXT_PUBLIC_SO_PDF_ENDPOINT=https://so-data.tree-app.ch/forest-types
2+
NEXT_PUBLIC_DATA_ENDPOINT=https://data.tree-app.ch
3+
NEXT_PUBLIC_SO_PDF_ENDPOINT=https://data.tree-app.ch/profiles/so/forest-types
4+
NEXT_PUBLIC_TREE_PDF_ENDPOINT=https://data.tree-app.ch/tree-types
35
NEXT_PUBLIC_MATOMO_URL_BASE=https://analytics.geops.de/
46
NEXT_PUBLIC_MATOMO_SITE_ID=14
57
KV_REST_API_URL=https://dear-woodcock-56336.upstash.io

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ yarn-error.log*
3636
*.tsbuildinfo
3737
next-env.d.ts
3838

39-
4039
# Serwist
4140
public/sw*
4241
public/swe-worker*

components/CantonalForestType.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Field } from "@headlessui/react";
22
import { useTranslation } from "react-i18next";
33

44
import useStore from "@/store";
5+
import getForestTypePdfUrl from "@/utils/getForestTypesPdfUrl";
56
import useCantonalForestType from "@/utils/hooks/useCantonalForestType";
67
import useHasPdf from "@/utils/hooks/useHasPdf";
78

@@ -14,7 +15,10 @@ function CantonalForestType() {
1415
(state) => state.setForestTypeDescription,
1516
);
1617
const cantonalForestType = useCantonalForestType();
17-
const hasPdf = useHasPdf(cantonalForestType);
18+
const hasPdf = useHasPdf(
19+
cantonalForestType && getForestTypePdfUrl(cantonalForestType),
20+
["so"],
21+
);
1822

1923
if (!cantonalForestType) return null;
2024

components/CookieBanner.tsx

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useMemo } from "react";
2+
import { createPortal } from "react-dom";
23
import { Trans, useTranslation } from "react-i18next";
34

45
import useLocalStorage from "@/utils/hooks/useLocalStorage";
@@ -18,30 +19,33 @@ const CookieBanner = () => {
1819
[i18n.language],
1920
);
2021

21-
return lsValue !== "true" ? (
22-
<Message className="absolute bottom-0 z-50 flex w-screen items-center justify-between rounded-none border-none bg-zinc-900 text-white">
23-
<div>
24-
<Trans i18nKey="cookieConsent">
25-
<a
26-
className="text-white underline hover:text-primary-200"
27-
href={link}
28-
rel="noopener noreferrer"
29-
target="_blank"
22+
return lsValue !== "true"
23+
? createPortal(
24+
<Message className="absolute bottom-0 z-[9999] flex w-screen items-center justify-between rounded-none border-none bg-zinc-900 text-white">
25+
<div>
26+
<Trans i18nKey="cookieConsent">
27+
<a
28+
className="text-white underline hover:text-primary-200"
29+
href={link}
30+
rel="noopener noreferrer"
31+
target="_blank"
32+
>
33+
Datenschutzerklärung
34+
</a>
35+
</Trans>
36+
</div>
37+
<Button
38+
className="ml-2 border-2 border-white !bg-zinc-900 text-white hover:border-white hover:!bg-zinc-600 hover:bg-zinc-700 hover:text-white"
39+
data-cypress="cookie-consent-ok-btn"
40+
onClick={() => setLsValue("true")}
41+
variant="outlined"
3042
>
31-
Datenschutzerklärung
32-
</a>
33-
</Trans>
34-
</div>
35-
<Button
36-
className="ml-2 border-2 border-white !bg-zinc-900 text-white hover:border-white hover:!bg-zinc-600 hover:bg-zinc-700 hover:text-white"
37-
data-cypress="cookie-consent-ok-btn"
38-
onClick={() => setLsValue("true")}
39-
variant="outlined"
40-
>
41-
OK
42-
</Button>
43-
</Message>
44-
) : null;
43+
OK
44+
</Button>
45+
</Message>,
46+
document.body,
47+
)
48+
: null;
4549
};
4650

4751
export default CookieBanner;

components/ForestTypeModal/ForestTypeDescription/index.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
import dynamic from "next/dynamic";
21
import { useMemo } from "react";
32
import { useTranslation } from "react-i18next";
43

54
import useStore from "@/store";
5+
import getForestTypePdfUrl from "@/utils/getForestTypesPdfUrl";
66
import useHasPdf from "@/utils/hooks/useHasPdf";
77

88
import BlForestTypeDescription from "./bl";
99
import ChForestTypesDescription from "./ch";
1010
import LuForestTypeDescription from "./lu";
11-
12-
const SoForestTypesDescription = dynamic(() => import("./so"), { ssr: false }); // Needs to be dynamic due to react-pdf
11+
import SoForestTypeDescription from "./so";
1312

1413
function useShowForestTypeDescription(code: string, activeProfile: string) {
15-
const hasPdf = useHasPdf(code);
14+
const hasPdf = useHasPdf(code && getForestTypePdfUrl(code), ["so"]);
1615

1716
const showForestTypeDescription = useMemo(
1817
() => (activeProfile === "so" ? hasPdf : !!code),
@@ -37,7 +36,7 @@ function ForestTypeDescription() {
3736
{activeProfile === "ch" && <ChForestTypesDescription code={code} />}
3837
{activeProfile === "lu" && <LuForestTypeDescription code={code} />}
3938
{activeProfile === "bl" && <BlForestTypeDescription code={code} />}
40-
{activeProfile === "so" && <SoForestTypesDescription code={code} />}
39+
{activeProfile === "so" && <SoForestTypeDescription code={code} />}
4140
{activeProfile === "vd" && (
4241
<p className="p-2">{t("forestTypeModal.noDataMessage")}</p>
4342
)}

components/ForestTypeModal/ForestTypeDescription/so/index.tsx

Lines changed: 10 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,32 @@
11
"use client";
2-
import { useEffect, useReducer, useRef, useState } from "react";
2+
import dynamic from "next/dynamic";
33
import { useTranslation } from "react-i18next";
4-
import { Document, Page, pdfjs } from "react-pdf";
5-
6-
pdfjs.GlobalWorkerOptions.workerSrc = "/pdf.worker.min.mjs"; // we host this statically in public folder
74

85
import { buttonStyles, primaryStyles } from "@/components/ui/Button";
9-
10-
let rerenderTimout: ReturnType<typeof setTimeout>;
6+
import { useModalContext } from "@/components/ui/Modal";
117

128
const soPdfEndpoint = process.env.NEXT_PUBLIC_SO_PDF_ENDPOINT;
139

10+
const PdfViewer = dynamic(() => import("@/components/PdfViewer"), {
11+
ssr: false,
12+
}); // Needs to be dynamic due to react-pdf pdf.worker.min.mjs
13+
1414
function ForestTypeDescription({ code }: { code: string }) {
1515
const name = code?.replace("*", "stern");
16-
const containerRef = useRef<HTMLDivElement | null>(null);
17-
const [numPages, setNumPages] = useState<null | number>(null);
1816
const { t } = useTranslation();
19-
const [, forceUpdate] = useReducer((x: number) => x + 1, 0);
20-
21-
const onDocumentLoadSuccess = ({
22-
numPages: nextNumPages,
23-
}: {
24-
numPages: number;
25-
}) => {
26-
setNumPages(nextNumPages);
27-
};
28-
29-
useEffect(() => {
30-
// Force rerender PDF on resize, important for mobile devices
31-
const debouncedRerender = () => {
32-
clearTimeout(rerenderTimout);
33-
rerenderTimout = setTimeout(forceUpdate, 50);
34-
};
35-
const resizeObserver = new ResizeObserver(debouncedRerender);
36-
resizeObserver.observe(document.body);
37-
return () => {
38-
clearTimeout(rerenderTimout);
39-
resizeObserver.disconnect();
40-
};
41-
}, []);
17+
const { isOpen } = useModalContext();
4218

4319
return (
44-
<div className="flex flex-col gap-2" ref={containerRef}>
20+
<div className="flex flex-col gap-2">
4521
<a
4622
className={`${buttonStyles} ${primaryStyles} self-end`}
4723
href={`${soPdfEndpoint}/${name}.pdf`}
4824
target="so-data"
4925
>
5026
{t("export.exportForestTypeDescription")}
5127
</a>
52-
{containerRef?.current ? (
53-
<Document
54-
file={`${soPdfEndpoint}/${name}.pdf`}
55-
onLoadSuccess={onDocumentLoadSuccess}
56-
>
57-
{Array.from(new Array(numPages), (_, index) => (
58-
<Page
59-
key={`page_${index + 1}`}
60-
pageNumber={index + 1}
61-
renderAnnotationLayer={false}
62-
renderTextLayer={false}
63-
width={(containerRef.current?.clientWidth ?? 500) - 10}
64-
/>
65-
))}
66-
</Document>
67-
) : null}
28+
{/* We react to isOpen to rerender the component */}
29+
{isOpen ? <PdfViewer href={`${soPdfEndpoint}/${name}.pdf`} /> : null}
6830
</div>
6931
);
7032
}

components/MapGeolocation.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ function MapGeolocation() {
3030
});
3131

3232
return getIsMobileDevice() ? (
33-
<div className="absolute bottom-28 right-5 z-50 flex items-center rounded p-1 backdrop-blur-sm">
33+
<div className="absolute bottom-28 right-5 z-40 flex items-center rounded p-1 backdrop-blur-sm">
3434
<Button
35-
className="flex h-[34px] !w-[34px] items-center justify-center bg-white !px-0 !py-0 !text-primary-500 hover:bg-white hover:!text-primary-200"
35+
className="flex h-[34px] !w-[34px] items-center justify-center bg-white/85 !px-0 !py-0 !text-primary-500 hover:bg-white/85 hover:!text-primary-200"
3636
onClick={() => geoloc.setTracking(true)}
3737
>
3838
<GeolocationIcon className="h-4 w-4" />

components/MapLayersMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ function MapLayersMenu() {
161161
{({ open }) => {
162162
return (
163163
<>
164-
<PopoverButton className="absolute right-5 top-5 z-50 flex items-center rounded-lg p-1 backdrop-blur-sm sm:w-60">
164+
<PopoverButton className="absolute right-5 top-5 z-30 flex items-center rounded-lg p-1 backdrop-blur-sm sm:w-60">
165165
<div
166166
className={`${buttonStyles} ${outlinedStyles} flex w-full justify-between gap-2 border-none !px-3`}
167167
>

0 commit comments

Comments
 (0)