-
Notifications
You must be signed in to change notification settings - Fork 135
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: add progress bar when switching pages #587
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import * as singleSpa from 'single-spa' | ||
import { Root } from '@lib/components' | ||
import React, { useState, useEffect, useRef } from 'react' | ||
import { HashRouter as Router } from 'react-router-dom' | ||
import { | ||
DownOutlined, | ||
GlobalOutlined, | ||
|
@@ -10,7 +11,7 @@ import { | |
import { Form, Input, Button, message } from 'antd' | ||
import { motion } from 'framer-motion' | ||
import { useTranslation } from 'react-i18next' | ||
import LanguageDropdown from '@lib/components/LanguageDropdown' | ||
import { LanguageDropdown, TopLoadingBar } from '@lib/components' | ||
import client from '@lib/client' | ||
import * as auth from '@lib/utils/auth' | ||
|
||
|
@@ -172,19 +173,22 @@ function TiDBSignInForm({ registry }) { | |
function App({ registry }) { | ||
return ( | ||
<Root> | ||
<div className={styles.container}> | ||
<div className={styles.dialogContainer}> | ||
<div className={styles.dialog}> | ||
<TiDBSignInForm registry={registry} /> | ||
<Router> | ||
<TopLoadingBar /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about making it another SingleSPA app that always exists on the page, or simply put it outside everything mounted by SingleSPA. In this way, it can listen SingleSPA global events gracefully without worrying about its own lifecycle. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It may be a solution, let me have a try. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implement it by this way in PR #661 , much more graceful! will close this PR. |
||
<div className={styles.container}> | ||
<div className={styles.dialogContainer}> | ||
<div className={styles.dialog}> | ||
<TiDBSignInForm registry={registry} /> | ||
</div> | ||
</div> | ||
<motion.div | ||
initial={{ opacity: 0 }} | ||
animate={{ opacity: 1 }} | ||
transition={{ ease: 'easeOut', duration: 0.5 }} | ||
className={styles.landing} | ||
></motion.div> | ||
</div> | ||
<motion.div | ||
initial={{ opacity: 0 }} | ||
animate={{ opacity: 1 }} | ||
transition={{ ease: 'easeOut', duration: 0.5 }} | ||
className={styles.landing} | ||
></motion.div> | ||
</div> | ||
</Router> | ||
</Root> | ||
) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React, { useRef, useEffect } from 'react' | ||
import LoadingBar from 'react-top-loading-bar' | ||
|
||
const useLoadingBar = () => { | ||
const loadingBar = useRef<LoadingBar>(null) | ||
|
||
useEffect(() => { | ||
function startLoading() { | ||
loadingBar?.current?.continuousStart() | ||
} | ||
window.addEventListener('single-spa:before-routing-event', startLoading) | ||
return () => | ||
window.removeEventListener( | ||
'single-spa:before-routing-event', | ||
startLoading | ||
) | ||
}, []) | ||
|
||
useEffect(() => { | ||
function completeLoading() { | ||
loadingBar?.current?.complete() | ||
} | ||
window.addEventListener('single-spa:routing-event', completeLoading) | ||
return () => | ||
window.removeEventListener('single-spa:routing-event', completeLoading) | ||
}, []) | ||
|
||
return loadingBar | ||
} | ||
|
||
export default function TopLoadinngBar() { | ||
const loadingBar = useLoadingBar() | ||
return <LoadingBar ref={loadingBar} /> | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After testing, the TopLoadingBar can't receive the
single-spa:before-routing-event
event if it isn't wrapped by the Router component.