-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgatsby-browser.js
More file actions
37 lines (34 loc) · 1.26 KB
/
gatsby-browser.js
File metadata and controls
37 lines (34 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { wrapRootElement } from "./src/components/wrapRootElement"
import fetch from 'node-fetch';
import 'typeface-roboto';
import './src/styles/global.css';
const onRouteUpdate = ({ location }) => {
if (
(document.readyState === 'interactive' ||
document.readyState === 'complete') &&
location.pathname === '/'
) {
console.log('ReactDOM.render has executed');
const src = `/.netlify/functions/google-places`;
fetch(src, {
headers: { accept: 'Accept: application/json' },
})
.then((response) => response.text())
.then((data) => {
console.log(data)
const json = JSON.parse(data);
const open_now = json.msg.result.opening_hours.open_now;
if (open_now === true) {
document.querySelector('#open_now').innerHTML =
'<span style="color:#0cb02b">OPEN</span>';
} else {
document.querySelector('#open_now').innerHTML =
'<span style="color:red">CLOSED</span>';
}
})
.catch((res) => {
console.log(res);
});
}
};
export { onRouteUpdate, wrapRootElement }