Skip to content

Commit f6544d0

Browse files
authored
Merge pull request #21 from itk-dev/feature/update-destination-on-unlock
added updatedestination on unlock + accuracy as leeway for proximity
2 parents 1bbc67f + 5952c7d commit f6544d0

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

src/components/points-of-interest/PointOfInterest.jsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function PointOfInterest({
2727
destinationChanged,
2828
nextUnlockableId,
2929
setSource,
30+
accuracy,
3031
}) {
3132
const { lat, long } = useContext(LatLongContext);
3233
const [proximity, setProximity] = useState(null);
@@ -50,7 +51,8 @@ function PointOfInterest({
5051
);
5152
setProximity(distance);
5253
if (!unlocked && id === nextUnlockableId) {
53-
setUnlocked(distance < 51); // todo magic number/get from config
54+
setUnlocked(distance < accuracy); // todo magic number/get from config
55+
destinationChanged();
5456
}
5557
}
5658
}, [latitude, longitude, lat, long, geolocationAvailable]);
@@ -86,12 +88,25 @@ function PointOfInterest({
8688

8789
return (
8890
<div
89-
className={`relative flex items-start gap-4 p-2 rounded-lg ${unlocked ? `bg-zinc-200 dark:bg-zinc-600` : `bg-zinc-100 dark:bg-zinc-700` }`}
91+
className={`relative flex items-start gap-4 p-2 rounded-lg ${
92+
unlocked
93+
? `bg-zinc-200 dark:bg-zinc-600`
94+
: `bg-zinc-100 dark:bg-zinc-700`
95+
}`}
9096
>
91-
<div className={`absolute -left-3 px-2 font-bold rounded-full text-sm ${unlocked ? `bg-emerald-700 text-zinc-100` : `bg-emerald-900 text-zinc-400` }`} >
97+
<div
98+
className={`absolute -left-3 px-2 font-bold rounded-full text-sm ${
99+
unlocked
100+
? `bg-emerald-700 text-zinc-100`
101+
: `bg-emerald-900 text-zinc-400`
102+
}`}
103+
>
92104
{index}
93105
</div>
94-
<Image src={image} className={`w-24 h-24 rounded-full ${!unlocked && `opacity-40` }` } />
106+
<Image
107+
src={image}
108+
className={`w-24 h-24 rounded-full ${!unlocked && `opacity-40`}`}
109+
/>
95110
<div className="flex flex-col">
96111
<h2 className="text-zinc-900 text-sm font-bold dark:text-zinc-200 my-3">
97112
{name}
@@ -103,7 +118,7 @@ function PointOfInterest({
103118
<span className="sr-only">Afstand</span>
104119
{/* todo this is slow and would benefit from loading screen / skeleton componenet */}
105120
<span className="text-md" id="distance">
106-
{proximity} m
121+
{proximity - accuracy} m
107122
</span>
108123
</label>
109124
)}

src/components/routes/RouteCarousel.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { React, useState } from "react";
1+
import { React } from "react";
22
import { Carousel } from "react-responsive-carousel";
33
import { Link } from "react-router-dom";
44
import Route from "./Route";

src/components/routes/RoutePage.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function RoutePage() {
3030
const [nextUnlockableId, setNextUnlockableId] = useState(null);
3131
const [routeComplete, setRouteComplete] = useState(false);
3232
const [source, setSource] = useState(null);
33+
const [accuracy, setAccuracy] = useState(0);
3334
const { userLatitude, userLongitude } = useContext(LatLongContext);
3435
const { geolocationAvailable } = useContext(PermissionContext);
3536
const audioRef = useRef();
@@ -85,6 +86,7 @@ function RoutePage() {
8586

8687
function locationHandler(pos) {
8788
setTimeout(() => {
89+
setAccuracy();
8890
setAngle(
8991
getAngleFromLocationToDestination(
9092
pos.coords.latitude,
@@ -172,6 +174,7 @@ function RoutePage() {
172174
destinationChanged={destinationChanged}
173175
nextUnlockableId={nextUnlockableId}
174176
setSource={setSource}
177+
accuracy={accuracy}
175178
/>
176179
))}
177180
</div>
@@ -204,7 +207,9 @@ function RoutePage() {
204207
{orientation && angle && (
205208
<div>
206209
<div className="flex justify-between">
207-
<span className="text-sm text-bold mr-5">Retning</span>
210+
<span className="text-sm text-bold mr-5 my-auto">
211+
Retning
212+
</span>
208213
<span className="w-1/2">
209214
<LocationArrow
210215
className="inline w-10"

src/util/helper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ export function getRelevantDestinationPoint(pointsOfInterest) {
6767
}
6868

6969
export function getIdFromApiEndpoint(endpoint) {
70-
const regex = /[^\/]+$/;
70+
const regex = /[^/]+$/;
7171
// Todo create utils file
7272
const idFound = endpoint ? endpoint.toString().match(regex) : null;
7373
return idFound[0];
7474
}
7575

7676
export function getIdsFromApiEndpoints(endpoints) {
77-
const regex = /[^\/]+$/;
77+
const regex = /[^/]+$/;
7878
const result = [];
7979

8080
endpoints.forEach((e) => {

0 commit comments

Comments
 (0)