From 4dc0472b75e7a8b8c239463f446534fdbcb14ea3 Mon Sep 17 00:00:00 2001 From: Simon Ho Date: Sat, 15 Feb 2020 17:59:03 -0800 Subject: [PATCH] Use new user flag instead of version --- src/App.js | 7 +------ src/GuidedTour.js | 3 ++- src/utils.js | 20 +++++++++++++++++++- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/App.js b/src/App.js index 9a2e319..5b671e3 100644 --- a/src/App.js +++ b/src/App.js @@ -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'; @@ -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 diff --git a/src/GuidedTour.js b/src/GuidedTour.js index c6f664c..9cf08b6 100644 --- a/src/GuidedTour.js +++ b/src/GuidedTour.js @@ -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 @@ -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: [ { diff --git a/src/utils.js b/src/utils.js index dfbb8fa..6e82923 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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) { @@ -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 * @@ -185,6 +202,7 @@ export default { setTitle, createSummaryString, isTouchDevice, + isNewUser, encode, decode };