Skip to content

Commit fd1882e

Browse files
authored
Merge pull request #4 from CodeDead/feature/cookie-notice
feature/cookie-notice
2 parents 139033d + 97ed7c5 commit fd1882e

File tree

7 files changed

+89
-5
lines changed

7 files changed

+89
-5
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"dependencies": {
1717
"@material-ui/core": "^4.11.3",
1818
"@material-ui/icons": "^4.11.2",
19+
"@material-ui/lab": "^4.0.0-alpha.57",
1920
"gatsby": "^2.31.1",
2021
"gatsby-image": "^2.10.0",
2122
"gatsby-plugin-google-gtag": "^2.7.0",

src/components/Layout/index.jsx

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import React, { useContext } from 'react';
2-
import { graphql, useStaticQuery } from 'gatsby';
2+
import { graphql, useStaticQuery, navigate } from 'gatsby';
33
import { CssBaseline } from '@material-ui/core';
4+
import Alert from '@material-ui/lab/Alert';
45
import { createMuiTheme, ThemeProvider } from '@material-ui/core/styles';
6+
import Button from '@material-ui/core/Button';
7+
import Typography from '@material-ui/core/Typography';
58
import DefaultAppBar from '../DefaultAppBar';
69
import Footer from '../Footer';
710
import { MainContext } from '../../contexts/MainContextProvider';
811
import ThemeSelector from '../../utils/ThemeSelector';
912
import './index.css';
13+
import { setHasAcceptedCookieNotice } from '../../reducers/MainReducer/Actions';
1014

1115
const Layout = ({ children }) => {
12-
const [state] = useContext(MainContext);
13-
const { themeIndex, themeColorIndex } = state;
16+
const [state, dispatch] = useContext(MainContext);
17+
const { themeIndex, themeColorIndex, hasAcceptedCookieNotice } = state;
1418
const data = useStaticQuery(graphql`query {
1519
site {
1620
siteMetadata {
@@ -37,11 +41,53 @@ const Layout = ({ children }) => {
3741
},
3842
});
3943

44+
/**
45+
* Accept cookies
46+
*/
47+
const acceptCookies = () => {
48+
dispatch(setHasAcceptedCookieNotice(true));
49+
};
50+
51+
/**
52+
* Go to the GDPR site
53+
*/
54+
const gotoGdpr = () => {
55+
navigate('http://ec.europa.eu/ipg/basics/legal/cookies/index_en.htm');
56+
};
57+
4058
return (
4159
<ThemeProvider theme={theme}>
4260
<CssBaseline />
4361
<DefaultAppBar title={data.site.siteMetadata.title} />
4462
{children}
63+
{hasAcceptedCookieNotice ? null : (
64+
<Alert
65+
severity="warning"
66+
style={{ position: 'sticky', bottom: 0, marginTop: 10 }}
67+
>
68+
<Typography>
69+
We might use cookies to ensure that we give you the best experience on our website.
70+
If you continue to use this site we will assume that you are happy with it.
71+
</Typography>
72+
73+
<Button
74+
variant="contained"
75+
color="secondary"
76+
onClick={gotoGdpr}
77+
style={{ marginRight: 5 }}
78+
>
79+
Decline
80+
</Button>
81+
82+
<Button
83+
variant="contained"
84+
color="primary"
85+
onClick={acceptCookies}
86+
>
87+
Agree
88+
</Button>
89+
</Alert>
90+
)}
4591
<Footer
4692
facebookUrl={data.site.siteMetadata.facebook}
4793
githubUrl={data.site.siteMetadata.github}

src/contexts/MainContextProvider/index.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const themeIndex = typeof window !== 'undefined' && localStorage.themeIndex ? pa
55
const themeColorIndex = typeof window !== 'undefined' && localStorage.themeColorIndex
66
? parseFloat(localStorage.themeColorIndex)
77
: 0;
8+
const hasAcceptedCookieNotice = typeof window !== 'undefined' && localStorage.hasAcceptedCookieNotice ? localStorage.hasAcceptedCookieNotice === 'true' : false;
89

910
const initState = {
1011
pageIndex: 0,
@@ -14,6 +15,7 @@ const initState = {
1415
defaultColor: '#3f50b5',
1516
},
1617
blogLimit: 0,
18+
hasAcceptedCookieNotice,
1719
};
1820

1921
export const MainContext = createContext(initState);

src/reducers/MainReducer/Actions/actionTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export const SET_PAGE_INDEX = 'SET_PAGE_INDEX';
22
export const SET_THEME_INDEX = 'SET_THEME_INDEX';
33
export const SET_THEME_COLOR_INDEX = 'SET_THEME_COLOR_INDEX';
44
export const SET_BLOG_LIMIT = 'SET_BLOG_LIMIT';
5+
export const SET_HAS_ACCEPTED_COOKIE_NOTICE = 'HAS_ACCEPTED_COOKIE_NOTICE';

src/reducers/MainReducer/Actions/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {
2-
SET_BLOG_LIMIT,
2+
SET_BLOG_LIMIT, SET_HAS_ACCEPTED_COOKIE_NOTICE,
33
SET_PAGE_INDEX,
44
SET_THEME_COLOR_INDEX,
5-
SET_THEME_INDEX,
5+
SET_THEME_INDEX
66
} from './actionTypes';
77

88
export const setPageIndex = (index) => ({
@@ -24,3 +24,8 @@ export const setBlogLimit = (limit) => ({
2424
type: SET_BLOG_LIMIT,
2525
payload: limit,
2626
});
27+
28+
export const setHasAcceptedCookieNotice = (hasAccepted) => ({
29+
type: SET_HAS_ACCEPTED_COOKIE_NOTICE,
30+
payload: hasAccepted,
31+
});

src/reducers/MainReducer/index.jsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
SET_BLOG_LIMIT,
3+
SET_HAS_ACCEPTED_COOKIE_NOTICE,
34
SET_PAGE_INDEX,
45
SET_THEME_COLOR_INDEX,
56
SET_THEME_INDEX,
@@ -29,6 +30,12 @@ const MainReducer = (state, action) => {
2930
...state,
3031
blogLimit: action.payload,
3132
};
33+
case SET_HAS_ACCEPTED_COOKIE_NOTICE:
34+
localStorage.hasAcceptedCookieNotice = action.payload;
35+
return {
36+
...state,
37+
hasAcceptedCookieNotice: action.payload,
38+
};
3239
default:
3340
return state;
3441
}

yarn.lock

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,6 +2074,27 @@ __metadata:
20742074
languageName: node
20752075
linkType: hard
20762076

2077+
"@material-ui/lab@npm:^4.0.0-alpha.57":
2078+
version: 4.0.0-alpha.57
2079+
resolution: "@material-ui/lab@npm:4.0.0-alpha.57"
2080+
dependencies:
2081+
"@babel/runtime": ^7.4.4
2082+
"@material-ui/utils": ^4.11.2
2083+
clsx: ^1.0.4
2084+
prop-types: ^15.7.2
2085+
react-is: ^16.8.0 || ^17.0.0
2086+
peerDependencies:
2087+
"@material-ui/core": ^4.9.10
2088+
"@types/react": ^16.8.6 || ^17.0.0
2089+
react: ^16.8.0 || ^17.0.0
2090+
react-dom: ^16.8.0 || ^17.0.0
2091+
peerDependenciesMeta:
2092+
"@types/react":
2093+
optional: true
2094+
checksum: 5d1a078800822d2d3ffcc6162a8867ab83a72b23103f2b1aeaf56135e16a3ade6672673c4c70a481aad467bd67ca31447a5bbb55d66260cc785baedde597d182
2095+
languageName: node
2096+
linkType: hard
2097+
20772098
"@material-ui/styles@npm:^4.11.3":
20782099
version: 4.11.3
20792100
resolution: "@material-ui/styles@npm:4.11.3"
@@ -4931,6 +4952,7 @@ __metadata:
49314952
dependencies:
49324953
"@material-ui/core": ^4.11.3
49334954
"@material-ui/icons": ^4.11.2
4955+
"@material-ui/lab": ^4.0.0-alpha.57
49344956
eslint-config-airbnb: ^18.2.1
49354957
eslint-plugin-import: ^2.22.1
49364958
eslint-plugin-jsx-a11y: ^6.4.1

0 commit comments

Comments
 (0)