Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui: show progress bar when switching pages #661

Merged
merged 3 commits into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions ui/dashboardApp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from '@lib/utils/appOptions'
import * as telemetry from '@lib/utils/telemetry'

import LayoutRoot from '@dashboard/layout/root'
import LayoutMain from '@dashboard/layout/main'
import LayoutSignIn from '@dashboard/layout/signin'

Expand Down Expand Up @@ -43,9 +44,16 @@ async function main(options: AppOptions) {

const registry = new AppRegistry(options)

singleSpa.registerApplication(
'root',
AppRegistry.newReactSpaApp(() => LayoutRoot, 'root'),
() => true,
{ registry }
)

singleSpa.registerApplication(
'layout',
AppRegistry.newReactSpaApp(() => LayoutMain, 'root'),
AppRegistry.newReactSpaApp(() => LayoutMain, '__spa__main__'),
() => {
return !routing.isSignInPage()
},
Expand All @@ -54,7 +62,7 @@ async function main(options: AppOptions) {

singleSpa.registerApplication(
'signin',
AppRegistry.newReactSpaApp(() => LayoutSignIn, 'root'),
AppRegistry.newReactSpaApp(() => LayoutSignIn, '__spa__main__'),
() => {
return routing.isSignInPage()
},
Expand Down
17 changes: 17 additions & 0 deletions ui/dashboardApp/layout/root/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react'
import { HashRouter as Router } from 'react-router-dom'

import { Root, TopLoadingBar } from '@lib/components'

function App() {
return (
<Root>
<Router>
<TopLoadingBar />
<div id="__spa__main__"></div>
</Router>
</Root>
)
}

export default App
20 changes: 20 additions & 0 deletions ui/lib/components/TopLoadingBar/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React, { useRef } from 'react'
import { useEventListener } from '@umijs/hooks'
import LoadingBar from 'react-top-loading-bar'

const useLoadingBar = () => {
const loadingBar = useRef<LoadingBar>()
useEventListener('single-spa:before-routing-event', () =>
loadingBar.current.continuousStart()
)
useEventListener('single-spa:routing-event', () =>
loadingBar.current.complete()
)

return loadingBar
}

export default function TopLoadinngBar() {
const loadingBar = useLoadingBar()
return <LoadingBar ref={loadingBar} />
}
1 change: 1 addition & 0 deletions ui/lib/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,4 @@ export { default as DatePicker } from './DatePicker'

export { default as LanguageDropdown } from './LanguageDropdown'
export { default as ParamsPageWrapper } from './ParamsPageWrapper'
export { default as TopLoadingBar } from './TopLoadingBar'
1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"react-router-dom": "^6.0.0-alpha.3",
"react-spring": "^8.0.27",
"react-syntax-highlighter": "^12.2.1",
"react-top-loading-bar": "^1.2.0",
"react-use": "^14.2.0",
"single-spa": "^5.3.4",
"single-spa-react": "^2.14.0",
Expand Down
5 changes: 5 additions & 0 deletions ui/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11442,6 +11442,11 @@ react-syntax-highlighter@^12.2.1:
prismjs "^1.8.4"
refractor "^2.4.1"

react-top-loading-bar@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/react-top-loading-bar/-/react-top-loading-bar-1.2.0.tgz#fcbca3c2e462bee7b1c0d1850e8b584cd7bd5a26"
integrity sha512-5oNdy+DfD5JK06bcc/gsnnXHmml+d8eaBe3C8KQ3eLiH/BD8+FcwsgbAwqgOaRjuSeVQXdYN2JC2G1uVFtCLfA==

react-universal-interface@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/react-universal-interface/-/react-universal-interface-0.6.0.tgz#b65cbf7d71a2f3f7dd9705d8e4f06748539bd465"
Expand Down