From e124aa1d676d03a68fc15353b44898e75ef2b398 Mon Sep 17 00:00:00 2001 From: Michael Schramm Date: Tue, 9 Jun 2020 18:07:12 +0200 Subject: [PATCH] hide loading after time --- pages/index.tsx | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/pages/index.tsx b/pages/index.tsx index bddb79008..a57dbecae 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -3,7 +3,7 @@ import { AuthFooter } from 'components/auth/footer' import { NextPage } from 'next' import getConfig from 'next/config' import { useRouter } from 'next/router' -import React, { useEffect } from 'react' +import React, { useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' import { LoadingPage } from '../components/loading.page' @@ -17,9 +17,14 @@ const { publicRuntimeConfig } = getConfig() as { const Index: NextPage = () => { const router = useRouter() const { t } = useTranslation() + const [loading, setLoading] = useState( + publicRuntimeConfig.spa || + (process.browser && + router.pathname !== window.location.pathname) + ) useEffect(() => { - if (router.pathname !== window.location.pathname && window.location.pathname.length > 2) { + if (router.pathname !== window.location.pathname) { let href = router.asPath const as = router.asPath const possible = [/(\/form\/)[^/]+/i, /(\/admin\/forms\/)[^/]+/i, /(\/admin\/users\/)[^/]+/i] @@ -36,12 +41,15 @@ const Index: NextPage = () => { } }) - if ( - publicRuntimeConfig.spa || - (process.browser && - router.pathname !== window.location.pathname && - window.location.pathname.length > 2) - ) { + useEffect(() => { + if (loading) { + setTimeout(() => { + setLoading(false) + }, 10000) + } + }, [loading]) + + if (loading) { return }