From c882c6ff5f757cb0c257aef654b115f2563bc17a Mon Sep 17 00:00:00 2001 From: Mikhail Mikheev Date: Thu, 19 Sep 2019 14:31:29 +0400 Subject: [PATCH] display loader on initial load when loadingg defaultSafe --- src/routes/index.js | 60 +++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/src/routes/index.js b/src/routes/index.js index 0786dd82..39f9a0a5 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -1,8 +1,9 @@ // @flow -import React from 'react' +import React, { useState } from 'react' import { connect } from 'react-redux' import { Switch, Redirect, Route } from 'react-router-dom' import { defaultSafeSelector } from '~/routes/safeList/store/selectors' +import Loader from '~/components/Loader' import Welcome from './welcome/container' import { SAFELIST_ADDRESS, @@ -29,29 +30,40 @@ type RoutesProps = { defaultSafe?: string, } -const Routes = ({ defaultSafe }: RoutesProps) => ( - - { - if (typeof defaultSafe === 'undefined') { - return 'Loading...' - } - if (defaultSafe) { - return - } - return - }} - /> - - - - - - - -) +const Routes = ({ defaultSafe }: RoutesProps) => { + const [isInitialLoad, setIniitialLoad] = useState(true) + + return ( + + { + if (!isInitialLoad) { + return + } + + if (typeof defaultSafe === 'undefined') { + return + } + + setIniitialLoad(false) + if (defaultSafe) { + return + } + + return + }} + /> + + + + + + + + ) +} export default connect( // $FlowFixMe