@@ -3,14 +3,21 @@ import { useSelector, useDispatch } from 'react-redux';
3
3
import Cookies from 'js-cookie' ;
4
4
import styled from 'styled-components' ;
5
5
import ReactGA from 'react-ga' ;
6
+ import { Transition } from 'react-transition-group' ;
6
7
import getConfig from '../../../utils/getConfig' ;
7
8
import { setUserCookieConsent } from '../actions' ;
8
9
import { remSize , prop } from '../../../theme' ;
9
10
import Button from '../../../common/Button' ;
10
11
11
12
const CookieConsentContainer = styled . div `
12
13
position: fixed;
13
- bottom: 0;
14
+ transition: 1.6s cubic-bezier(0.165, 0.84, 0.44, 1);
15
+ bottom: ${ ( { state } ) => {
16
+ if ( state === 'entered' ) {
17
+ return '0' ;
18
+ }
19
+ return remSize ( - 200 ) ;
20
+ } } ;
14
21
left: 0;
15
22
right: 0;
16
23
z-index: 9999;
@@ -47,6 +54,7 @@ const CookieConsentButtons = styled.div`
47
54
function CookieConsent ( ) {
48
55
const user = useSelector ( ( state ) => state . user ) ;
49
56
const [ cookieConsent , setBrowserCookieConsent ] = useState ( 'none' ) ;
57
+ const [ inProp , setInProp ] = useState ( false ) ;
50
58
const dispatch = useDispatch ( ) ;
51
59
52
60
function initializeCookieConsent ( ) {
@@ -73,6 +81,7 @@ function CookieConsent() {
73
81
}
74
82
setBrowserCookieConsent ( 'essential' ) ;
75
83
Cookies . set ( 'p5-cookie-consent' , 'essential' , { expires : 365 } ) ;
84
+ // Remove Google Analytics Cookies
76
85
Cookies . remove ( '_ga' ) ;
77
86
Cookies . remove ( '_gat' ) ;
78
87
Cookies . remove ( '_gid' ) ;
@@ -113,42 +122,45 @@ function CookieConsent() {
113
122
mergeCookieConsent ( ) ;
114
123
} , [ user . authenticated ] ) ;
115
124
116
- // Turn off Google Analytics
117
- // useEffect(() => {
118
- // if (cookieConsent === 'all' || user.cookieConsent === 'all') {
119
- // ReactGA.initialize(getConfig('GA_MEASUREMENT_ID'));
120
- // ReactGA.pageview(window.location.pathname + window.location.search);
121
- // }
122
- // }, [cookieConsent, user.cookieConsent]);
123
-
124
- const showCookieConsent =
125
- ( user . authenticated && user . cookieConsent === 'none' ) ||
126
- ( ! user . authenticated && cookieConsent === 'none' ) ;
127
-
128
- if ( ! showCookieConsent ) return null ;
125
+ useEffect ( ( ) => {
126
+ if ( cookieConsent !== 'none' ) {
127
+ setInProp ( false ) ;
128
+ } else {
129
+ setInProp ( true ) ;
130
+ }
131
+ } , [ cookieConsent ] ) ;
129
132
130
133
return (
131
- < CookieConsentContainer >
132
- < CookieConsentDialog role = "dialog" tabIndex = "0" >
133
- { /* <button aria-label="Close" tabIndex="0"></button> */ }
134
- < CookieConsentHeader > Cookies</ CookieConsentHeader >
135
- < CookieConsentContent >
136
- < CookieConsentCopy >
137
- The p5.js Editor uses cookies. Some are essential to the website
138
- functionality and allow you to manage an account and preferences.
139
- Others are used for analytics allow us to gather information and
140
- make improvements. You can decide which cookies you would like to
141
- allow.
142
- </ CookieConsentCopy >
143
- < CookieConsentButtons >
144
- < Button kind = { Button . kinds . secondary } onClick = { acceptAllCookies } >
145
- Allow All
146
- </ Button >
147
- < Button onClick = { acceptEssentialCookies } > Allow Essential</ Button >
148
- </ CookieConsentButtons >
149
- </ CookieConsentContent >
150
- </ CookieConsentDialog >
151
- </ CookieConsentContainer >
134
+ < Transition in = { inProp } timeout = { 500 } >
135
+ { ( state ) => (
136
+ < CookieConsentContainer state = { state } >
137
+ < CookieConsentDialog role = "dialog" tabIndex = "0" >
138
+ { /* <button aria-label="Close" tabIndex="0"></button> */ }
139
+ < CookieConsentHeader > Cookies</ CookieConsentHeader >
140
+ < CookieConsentContent >
141
+ < CookieConsentCopy >
142
+ The p5.js Editor uses cookies. Some are essential to the website
143
+ functionality and allow you to manage an account and
144
+ preferences. Others are used for analytics allow us to gather
145
+ information and make improvements. You can decide which cookies
146
+ you would like to allow.
147
+ </ CookieConsentCopy >
148
+ < CookieConsentButtons >
149
+ < Button
150
+ kind = { Button . kinds . secondary }
151
+ onClick = { acceptAllCookies }
152
+ >
153
+ Allow All
154
+ </ Button >
155
+ < Button onClick = { acceptEssentialCookies } >
156
+ Allow Essential
157
+ </ Button >
158
+ </ CookieConsentButtons >
159
+ </ CookieConsentContent >
160
+ </ CookieConsentDialog >
161
+ </ CookieConsentContainer >
162
+ ) }
163
+ </ Transition >
152
164
) ;
153
165
}
154
166
// TODO need to merge browser cookie with user when u login
0 commit comments