From 02622ace65482a5a9260e71f7e842520f3aee89c Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 30 Jan 2021 03:12:15 +1100 Subject: [PATCH] Added cookie notification --- README.md | 2 +- client/components/app.jsx | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d705e62..2757cd0 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ This should get the template working in development mode. - ~~login (with cookies)~~ - ~~logout (with cookies)~~ - ~~account deletion~~ - - annoying "This site uses cookies" message + - ~~annoying "This site uses cookies" message~~ - CSS template? - Administration Panel - Exclusive to admin accounts diff --git a/client/components/app.jsx b/client/components/app.jsx index ccc9d9b..876b1e4 100644 --- a/client/components/app.jsx +++ b/client/components/app.jsx @@ -1,6 +1,7 @@ //react -import React from 'react'; +import React, { useState } from 'react'; import { BrowserRouter, Switch } from 'react-router-dom'; +import { useCookies } from 'react-cookie'; //library components import LazyRoute from './lazy-route'; @@ -13,6 +14,25 @@ import Header from './panels/header.jsx'; import Footer from './panels/footer.jsx'; const App = props => { + //handle cookies prompt + const [cookies, setCookie] = useCookies(); + + if (!cookies['accept-cookies']) { + const accept = confirm('This website uses cookies to operate correctly. By clicking "ok", you agree to accept said cookies.'); + + if (accept) { + setCookie('accept-cookies', true); + } else { + return ( +
+

This website won't operate correctly without cookies.

+ +
+ ); + } + } + + //default render return (