Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

map permission commit #60

Merged
merged 4 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- [PR-60](https://github.com/itk-dev/aapodwalk/pull/60)
- Make it possible to reevaluate ip-tracking consent and therefore permission to Open Street Map
- Move `MapConsentBanner` component to be able to display on other pages that frontpage
- Make `App.jsx`responsible for resetting localstorage map permission on change
- Create buttons to toggle permission banner in `RoutePage.jsx` and in `Point.jsx`
- [PR-59](https://github.com/itk-dev/aapodwalk/pull/59)
- Rename `ErrorComponent.jsx` to `MessageComponent.jsx`
- Rename `ErrorContext.jsx` to `MessageContext.jsx`
Expand Down
10 changes: 10 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import SeeOnMap from "./components/SeeOnMap";
import MessageContext from "./context/MessageContext";
import { Link } from "react-router-dom";
import NavigationHelp from "./components/NavigationHelp";
import MapConsentBanner from "./components/MapConsentBanner";

function App() {
const [selectedRoute, setSelectedRoute] = useState(null);
Expand Down Expand Up @@ -83,6 +84,14 @@ function App() {
}
}, []);

useEffect(() => {
if (openStreetMapConsent === null) {
localStorage.removeItem("data-consent");
} else {
localStorage.setItem("data-consent", openStreetMapConsent);
}
}, [openStreetMapConsent]);

return (
<div className="App flex flex-col h-full pt-24 min-h-screen dark:text-white w-screen pl-3 pr-3 pb-3 text-zinc-800 bg-zinc-100 dark:bg-zinc-800 overflow-hidden">
<LatLongContext.Provider value={contextLatLong}>
Expand Down Expand Up @@ -149,6 +158,7 @@ function App() {
<FrontPage />
</Route>
</Switch>
<MapConsentBanner />
</MessageContext.Provider>
</main>
</RouteContext.Provider>
Expand Down
1 change: 0 additions & 1 deletion src/components/FrontPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ function FrontPage() {
<TagFilterList />
<RouteList />
</SelectedTagContext.Provider>
<MapConsentBanner />
</div>
);
}
Expand Down
1 change: 0 additions & 1 deletion src/components/MapConsentBanner.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ function MapConsentBanner() {
const { setOpenStreetMapConsent, openStreetMapConsent } = useContext(PermissionContext);

function updateConsent(consent) {
localStorage.setItem("data-consent", consent);
setOpenStreetMapConsent(consent);
}

Expand Down
7 changes: 6 additions & 1 deletion src/components/map/MapWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function MapWrapper({ mapData, additionalClass = "", focusable, withIndex }) {

return (
<>
{focusOnMap && (
{focusOnMap && focusable && (
<FocusTrap>
<div className="map-container absolute left-0 top-0 right-0 h-full">
<CloseButton
Expand All @@ -24,6 +24,11 @@ function MapWrapper({ mapData, additionalClass = "", focusable, withIndex }) {
</div>
</FocusTrap>
)}
{focusOnMap && !focusable && (
<div className="map-container absolute left-0 top-0 right-0 h-full">
<MapComponent focusOnMap={focusOnMap} withIndex={withIndex} mapData={mapData} additionalClass="z-40" />
</div>
)}
{!focusOnMap && (
<button type="button" onClick={() => setFocusOnMap(true)}>
{!focusOnMap && focusable && (
Expand Down
28 changes: 21 additions & 7 deletions src/components/points/Point.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import OrderComponent from "./OrderComponent";
import PointOverlay from "./PointOverlay";
import LatLongContext from "../../context/latitude-longitude-context";
import { useScrollToLocation } from "../hooks/UseScrollIntoView";
import PermissionContext from "../../context/permission-context";

function Point({ point, order }) {
const { latitude, longitude, name, image, id, subtitles, proximityToUnlock = 100 } = point;
const { nextUnlockablePointId, listOfUnlocked } = useContext(RouteContext);
const { openStreetMapConsent, setOpenStreetMapConsent } = useContext(PermissionContext);
const { lat, long } = useContext(LatLongContext);
const [unlocked, setUnlocked] = useState(false);
const [playThis, setPlayThis] = useState(false);
Expand Down Expand Up @@ -84,13 +86,25 @@ function Point({ point, order }) {
)}
{isNextPointToUnlock() && (
<>
<Link
to={`/see-on-map/${latitude}/${longitude}`}
className="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 flex flex-col cursor-pointer text-emerald-400 dark:text-emerald-600"
>
<FontAwesomeIcon className="h-9" icon={faMapLocationDot} />
<span className="sr-only">Se punkt {name} på kort</span>
</Link>
{openStreetMapConsent && (
<Link
to={`/see-on-map/${latitude}/${longitude}`}
className="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 flex flex-col cursor-pointer text-emerald-400 dark:text-emerald-600"
>
<FontAwesomeIcon className="h-9" icon={faMapLocationDot} />
<span className="sr-only">Se punkt {name} på kort</span>
</Link>
)}
{!openStreetMapConsent && (
<button
type="button"
onClick={() => setOpenStreetMapConsent(null)}
className="absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 cursor-pointer text-emerald-400 dark:text-emerald-600"
>
<FontAwesomeIcon className="h-9" icon={faMapLocationDot} />
<span className="sr-only">Tag stilling til tilladelser i forhold til kortet igen</span>
</button>
)}
<DistanceComponent
data={point}
classes="absolute top-1/2 right-5 transform -translate-x-1/2 -translate-y-1/2 text-xl"
Expand Down
28 changes: 24 additions & 4 deletions src/components/routes/RoutePage.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { React, useEffect, useState, useContext } from "react";
import { Link, useParams } from "react-router-dom";
import { faPlayCircle } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import useFetch from "../../util/useFetch";
import PermissionContext from "../../context/permission-context";
import RouteContext from "../../context/RouteContext";
import useFetch from "../../util/useFetch";
import MapWrapper from "../map/MapWrapper";
import TagList from "../tags/TagList";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faPlayCircle } from "@fortawesome/free-solid-svg-icons";

function RoutePage() {
const { id } = useParams();
const { openStreetMapConsent, setOpenStreetMapConsent } = useContext(PermissionContext);
const { selectedRoute, setSelectedRoute, setListOfUnlocked } = useContext(RouteContext);
const [dataFetched, setDataFetched] = useState(false);
const [focusOnText, setFocusOnText] = useState(false);
function isRouteAlreadySet() {
return selectedRoute === null && dataFetched;
}
Expand All @@ -35,6 +38,11 @@ function RoutePage() {

if (selectedRoute === null) return null;

function resetPermission() {
setFocusOnText(false);
setOpenStreetMapConsent(null);
}

const { title, tags, points, totalDuration, distance, description } = selectedRoute;

return (
Expand All @@ -46,7 +54,19 @@ function RoutePage() {
<h1 className="text-4xl font-extrabold z-50 relative word-break">{title}</h1>
</div>
<div className="flex flex-col items-end">
<div className="w-3/5 mb-10 text-end">Tryk på kortet for at undersøge ruten</div>
{openStreetMapConsent && <div className="w-3/5 mb-10 text-end">Tryk på kortet for at undersøge ruten</div>}

{!openStreetMapConsent && !focusOnText && (
<button type="button" onClick={() => setFocusOnText(true)} className="opacity-35 mb-10 text-center">
Du har ikke givet samtykke, derfor kan vi ikke vise er kort her. Vil du ændre det, kan du trykke her
sinejespersen marked this conversation as resolved.
Show resolved Hide resolved
</button>
)}
{!openStreetMapConsent && focusOnText && (
<button type="button" onClick={() => resetPermission()} className="mb-10 text-center">
Du har ikke givet samtykke, derfor kan vi ikke vise er kort her. Vil du ændre det, kan du trykke her
sinejespersen marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have the exact same message twice in the code. Consider putting it into a variable.

</button>
)}

<div className="bg-emerald-400 w-full dark:bg-emerald-800 mb-3 rounded-md p-3 flex z-50 relative">
<div>
<div className="font-bold">Distance</div>
Expand Down
Loading