From fc16c8bbc6e0a51edd067efbccc339085b0d59cc Mon Sep 17 00:00:00 2001 From: Aidan Hobson Sayers Date: Mon, 9 Nov 2020 19:44:33 +0000 Subject: [PATCH 1/2] Eliminate unnecessary use of router --- src/components/Home/FirstTimeHome.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/components/Home/FirstTimeHome.js b/src/components/Home/FirstTimeHome.js index 65f94d43..b93a3e95 100644 --- a/src/components/Home/FirstTimeHome.js +++ b/src/components/Home/FirstTimeHome.js @@ -1,7 +1,6 @@ import React from 'react'; import { connect } from 'react-redux'; import styled from 'styled-components'; -import { withRouter } from 'react-router-dom'; import { filePlus } from 'react-icons-kit/feather/filePlus'; import { download } from 'react-icons-kit/feather/download'; import { box } from 'react-icons-kit/feather/box'; @@ -21,7 +20,7 @@ import OptionColumn from './OptionColumn'; const WRAPPER_MAX_WIDTH = 850; const WRAPPER_PADDING = UNIT * 2; -const FirstTimeHome = ({ loadDemoMap, setModal, demoSong, history }) => { +const FirstTimeHome = ({ loadDemoMap, setModal, demoSong }) => { const { width: windowWidth } = useWindowDimensions(); const [isLoadingDemo, setIsLoadingDemo] = React.useState(false); @@ -127,6 +126,4 @@ const mapDispatchToProps = { loadDemoMap: actions.loadDemoMap, }; -export default withRouter( - connect(mapStateToProps, mapDispatchToProps)(FirstTimeHome) -); +export default connect(mapStateToProps, mapDispatchToProps)(FirstTimeHome); From db275cf4e6abfbc1f8986ee693a7dc4896e4debb Mon Sep 17 00:00:00 2001 From: Aidan Hobson Sayers Date: Mon, 9 Nov 2020 19:45:03 +0000 Subject: [PATCH 2/2] Allow users to import the demo map on the returning user page --- src/components/Home/ReturningHome.js | 31 ++++++++++++++++++++++++++-- src/middlewares/demo.middleware.js | 28 ++++++++++--------------- 2 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/components/Home/ReturningHome.js b/src/components/Home/ReturningHome.js index 76fd3a3d..8e4835b9 100644 --- a/src/components/Home/ReturningHome.js +++ b/src/components/Home/ReturningHome.js @@ -1,7 +1,10 @@ import React from 'react'; +import { connect } from 'react-redux'; import styled from 'styled-components'; +import * as actions from '../../actions'; import { UNIT } from '../../constants'; +import { getDemoSong } from '../../reducers/songs.reducer'; import Button from '../Button'; import Spacer from '../Spacer'; @@ -10,7 +13,9 @@ import MaxWidthWrapper from '../MaxWidthWrapper'; import SongsTable from './SongsTable'; import Heading from '../Heading'; -const ReturningHome = ({ songs, isProcessingImport, setModal }) => { +const ReturningHome = ({ songs, isProcessingImport, loadDemoMap, setModal, demoSong}) => { + const [isLoadingDemo, setIsLoadingDemo] = React.useState(false); + return ( @@ -36,6 +41,19 @@ const ReturningHome = ({ songs, isProcessingImport, setModal }) => { > Import existing map + + @@ -66,4 +84,13 @@ const SideColumn = styled(Column)` border-radius: ${UNIT}px; min-width: 280px; `; -export default ReturningHome; + +const mapStateToProps = (state) => ({ + demoSong: getDemoSong(state), +}); + +const mapDispatchToProps = { + loadDemoMap: actions.loadDemoMap, +}; + +export default connect(mapStateToProps, mapDispatchToProps)(ReturningHome); diff --git a/src/middlewares/demo.middleware.js b/src/middlewares/demo.middleware.js index b8bd1bd9..a63d6d61 100644 --- a/src/middlewares/demo.middleware.js +++ b/src/middlewares/demo.middleware.js @@ -12,23 +12,17 @@ export default () => (store) => (next) => { next(action); if (action.type === 'LOAD_DEMO_MAP') { - // If this is a brand-new user, they won't have the demo song at all - const state = store.getState(); - const isNewUser = getIsNewUser(state); - - if (isNewUser) { - fetch(demoFileUrl) - .then((res) => res.blob()) - .then((blob) => processImportedMap(blob, [])) - .then((songData) => { - songData.demo = true; - next(importExistingSong(songData)); - }) - .then(() => { - // HACK: Should pull data from demoSong - window.location = '/edit/only-now/Normal/notes'; - }); - } + fetch(demoFileUrl) + .then((res) => res.blob()) + .then((blob) => processImportedMap(blob, [])) + .then((songData) => { + songData.demo = true; + next(importExistingSong(songData)); + }) + .then(() => { + // HACK: Should pull data from demoSong + window.location = '/edit/only-now/Normal/notes'; + }); } }; };