Skip to content

Commit d7a387d

Browse files
committed
Switch to hook for tutorial cookies
1 parent 511233d commit d7a387d

5 files changed

Lines changed: 15 additions & 26 deletions

File tree

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
"redux": "^4.1.2",
3535
"redux-thunk": "^2.4.0",
3636
"typescript": "*",
37-
"universal-cookie": "latest",
3837
"uuid": "^8.3.2"
3938
},
4039
"scripts": {

src/Home.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import SourceMultiTable from './SourceMultiTable';
99
import SplitPane from 'react-split-pane';
1010
import {changeExpr} from './modules/data';
1111
import {BrowserView, MobileOnlyView} from 'react-device-detect';
12-
import Cookies from 'universal-cookie';
1312
import ReactGA from 'react-ga';
1413

1514
import './Home.css';
@@ -19,9 +18,7 @@ import Tutorial from './Tutorial';
1918
import type {ComponentType} from 'react';
2019
import type {RouterHistory} from 'react-router-dom';
2120

22-
type State = {
23-
cookies: typeof Cookies,
24-
};
21+
type State = {};
2522

2623
type Props = {
2724
history: RouterHistory,
@@ -32,8 +29,6 @@ class Home extends Component<Props, State> {
3229
constructor(props: Props) {
3330
super(props);
3431

35-
this.state = {cookies: new Cookies()};
36-
3732
// If GA is no longer used, remove preconnect from index.html
3833
switch (process.env.NODE_ENV) {
3934
case 'production':
@@ -65,7 +60,7 @@ class Home extends Component<Props, State> {
6560
<div className="bottomLeftContainer">
6661
<DataContainer />
6762
<div className="footer">
68-
<Tutorial cookies={this.state.cookies} />
63+
<Tutorial />
6964
<p className="email">
7065
For questions, please email{' '}
7166
<a href="mailto:mmior@cs.rit.edu">mmior@cs.rit.edu</a>

src/Tutorial.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
import Joyride, {CallBackProps, STATUS} from 'react-joyride';
22
import React, {useState} from 'react';
3-
4-
type Props = {
5-
cookies: any,
6-
};
3+
import {useCookies} from 'react-cookie';
74

85
const redoText = 'Redo tutorial';
96
const stepStyle = {tooltipContainer: {textAlign: 'left'}};
107

118
/** Container for all components of the tutorial */
12-
function Tutorial(props: Props) {
9+
function Tutorial() {
1310
let initialText, shouldRun;
14-
if (props.cookies.get('tutorial') === undefined) {
11+
const [cookies, setCookie] = useCookies(['tutorial']);
12+
if (cookies.tutorial === undefined) {
1513
initialText = 'Tutorial';
1614
shouldRun = true;
17-
props.cookies.set('tutorial', 'true', {path: '/'});
15+
setCookie('tutorial', 'true', {path: '/'});
1816
} else {
1917
initialText = redoText;
2018
shouldRun = false;

src/index.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import * as Sentry from '@sentry/browser';
99
import './index.css';
1010
import store, {history} from './store';
1111
import App from './App';
12-
import CookiesProvider from 'react-cookie/cjs/CookiesProvider';
1312

1413
let sentryConfig = {};
1514
sentryConfig.dsn = 'https://496d372d00a24c57af7967ac2ff5dacd@sentry.io/2445886';
@@ -21,14 +20,12 @@ if (process.env.REACT_APP_GIT_SHA) {
2120
Sentry.init(sentryConfig);
2221

2322
ReactDOM.render(
24-
<CookiesProvider>
25-
<Provider store={store}>
26-
<ConnectedRouter history={history}>
27-
<div>
28-
<App />
29-
</div>
30-
</ConnectedRouter>
31-
</Provider>
32-
</CookiesProvider>,
23+
<Provider store={store}>
24+
<ConnectedRouter history={history}>
25+
<div>
26+
<App />
27+
</div>
28+
</ConnectedRouter>
29+
</Provider>,
3330
((document.getElementById('root'): any): HTMLElement)
3431
);

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16966,7 +16966,7 @@ unique-string@^1.0.0:
1696616966
dependencies:
1696716967
crypto-random-string "^1.0.0"
1696816968

16969-
universal-cookie@^4.0.0, universal-cookie@latest:
16969+
universal-cookie@^4.0.0:
1697016970
version "4.0.4"
1697116971
resolved "https://registry.yarnpkg.com/universal-cookie/-/universal-cookie-4.0.4.tgz#06e8b3625bf9af049569ef97109b4bb226ad798d"
1697216972
integrity sha512-lbRVHoOMtItjWbM7TwDLdl8wug7izB0tq3/YVKhT/ahB4VDvWMyvnADfnJI8y6fSvsjh51Ix7lTGC6Tn4rMPhw==

0 commit comments

Comments
 (0)