-
Notifications
You must be signed in to change notification settings - Fork 2
/
gatsby-browser.js
57 lines (50 loc) · 1.56 KB
/
gatsby-browser.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* Implement Gatsby's Browser APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/browser-apis/
*/
// You can delete this file if you're not using it
const React = require('react');
const splitbee = require('@splitbee/web');
const { toast } = require('react-hot-toast');
const theme = require('./src/styles/theme');
const { colors } = theme.default;
const updateButtonStyles = {
margin: '0px',
marginLeft: '10px',
backgroundColor: `${colors.green}`,
color: `${colors.lightestNavy}`,
padding: '6px',
borderRadius: '0.3em',
border: 'none',
fontWeight: 'bold',
};
// Called when the Gatsby browser runtime first starts
exports.onClientEntry = () => {
if (process.env.NODE_ENV === 'production') {
splitbee.default.init({
disableCookie: true, // will disable the cookie usage
scriptUrl: 'https://ayushgupta.tech/bee.js',
apiUrl: 'https://ayushgupta.tech/_hive',
});
}
};
// Reference - https://www.gatsbyjs.com/docs/reference/config-files/gatsby-browser/#onServiceWorkerUpdateReady
// Also see - https://github.com/gatsbyjs/gatsby/issues/9087#issuecomment-723294431
// Inform plugins when a service worker has been updated in the background and the page is ready to reload to apply changes.
exports.onServiceWorkerUpdateReady = () => {
toast(
// eslint-disable-next-line no-unused-vars
t => (
<span>
A new version is available!
<button onClick={() => window.location.reload()} style={updateButtonStyles}>
Update
</button>
</span>
),
{
duration: 5000,
},
);
};