Skip to content

Commit

Permalink
Use new user flag instead of version
Browse files Browse the repository at this point in the history
  • Loading branch information
sho-87 committed Feb 16, 2020
1 parent 2e25f49 commit 4dc0472
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
7 changes: 1 addition & 6 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
decode
} from './utils';
import { maxPoints } from './values';
import { version, dataVersion } from '../package.json';
import { dataVersion } from '../package.json';

import './styles/App.css';
import './styles/fonts.css';
Expand Down Expand Up @@ -169,11 +169,6 @@ class App extends Component {
}
}

componentDidMount() {
// Store current app version
localStorage.setItem('version', version);
}

/**
* Get empty state values for new application instance. Also checks
* local storage for saved settings
Expand Down
3 changes: 2 additions & 1 deletion src/GuidedTour.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { Component } from 'react';
import Joyride, { ACTIONS, EVENTS, STATUS } from 'react-joyride';
import { isNewUser } from './utils';

/**
* Component containing the guided tour for app onboarding
Expand All @@ -12,7 +13,7 @@ class GuidedTour extends Component {
super(props);

this.state = {
run: localStorage.getItem('version') ? false : true,
run: isNewUser() ? true : false,
stepIndex: 0,
steps: [
{
Expand Down
20 changes: 19 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export function createSummaryString(commander, r, y, b, sep = '/') {
/**
* Detect if device is touch enabled
*
* @returns {boolean} Whether device is touch or not
* @returns {Boolean} Whether device is touch or not
*/
export function isTouchDevice() {
if (window.matchMedia('(pointer: coarse)').matches) {
Expand All @@ -142,6 +142,23 @@ export function isTouchDevice() {
}
}

/**
* Check whether user is new or returning
*
* @returns {Boolean} Whether user is new or returning
*/
export function isNewUser() {
if (
!localStorage.getItem('isNewUser') ||
JSON.parse(localStorage.getItem('isNewUser') === true)
) {
localStorage.setItem('isNewUser', false);
return true;
} else {
return false;
}
}

/**
* Encode/compress the passed text
*
Expand Down Expand Up @@ -185,6 +202,7 @@ export default {
setTitle,
createSummaryString,
isTouchDevice,
isNewUser,
encode,
decode
};

0 comments on commit 4dc0472

Please sign in to comment.