Skip to content

Commit c7b0194

Browse files
Generate card link on entering geofence. Close #52
1 parent b137c10 commit c7b0194

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

client-src/js/main.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ clickLinkListener(cCardLink);
4040

4141
const geo = navigator.geolocation;
4242

43-
// If supported run:
43+
// If geolocation supported run:
4444
const displayLocation = (position) => {
4545
// Store position
4646
const latitude = position.coords.latitude;
@@ -61,21 +61,25 @@ const displayLocation = (position) => {
6161
// Check if coordinates are within shop geofence
6262
if (P[0] >= X[0] && P[0] <= X[3]) {
6363
if (P[1] >= Y[0] && P[1] <= Y[3]) {
64+
// Show link
65+
cCardLink.style.display = 'flex';
6466
return true;
6567
}
6668
}
69+
// Hide link
70+
cCardLink.style.display = 'none';
6771
return false;
6872
};
6973

7074
// Check for geo support
7175
const getLocation = () => {
76+
const div = document.getElementById('location');
7277
if (geo) {
7378
geo.watchPosition((position) => {
74-
if (displayLocation(position) === true) {
75-
const div = document.getElementById('location');
79+
if (displayLocation(position)) {
7680
div.innerHTML = 'Welcome to Khan El Shopa';
7781
} else {
78-
console.log('Not in the shop');
82+
div.innerHTML = '';
7983
}
8084
});
8185
} else {

client-src/sass/main.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ body {
6262
}
6363

6464
#loadLink {
65-
display: flex;
65+
display: none;
6666
justify-content: center;
6767
max-width: 35%;
6868
height: auto;

public/assets/css/main.css

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/assets/js/main.js

Lines changed: 8 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)