mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-14 16:14:48 +01:00
begin progress bar element
This commit is contained in:
@@ -13,6 +13,7 @@ import { getConfig, saveConfig } from '../utils/configuration'
|
||||
import Topbar from './components/TopBar'
|
||||
import BigButton from './components/common/BigButton'
|
||||
import Checkbox from './components/common/Checkbox'
|
||||
import ProgressBar from './components/common/ProgressBar'
|
||||
|
||||
const downloadHandler = new DownloadHandler()
|
||||
|
||||
@@ -60,6 +61,16 @@ function App() {
|
||||
<Checkbox label="Connect via Grasscutter" onChange={toggleGrasscutter} />
|
||||
</div>
|
||||
<BigButton text="PLAY DA GAME :D" onClick={playGame} id="officialPlay" />
|
||||
|
||||
<div id="downloadProgress" style={{
|
||||
position: 'absolute',
|
||||
top: '50%',
|
||||
left: '50%',
|
||||
}}>
|
||||
|
||||
<ProgressBar path="S:/Cultivation/grassclipper.zip" downloadManager={downloadHandler} />
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
|
||||
@@ -12,8 +12,7 @@ interface IState {
|
||||
}
|
||||
|
||||
export default class BigButton extends React.Component<IProps, IState> {
|
||||
|
||||
constructor(props: { text: string, onClick: () => any, id: string }) {
|
||||
constructor(props: IProps) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
|
||||
0
src/ui/components/common/ProgressBar.css
Normal file
0
src/ui/components/common/ProgressBar.css
Normal file
52
src/ui/components/common/ProgressBar.tsx
Normal file
52
src/ui/components/common/ProgressBar.tsx
Normal file
@@ -0,0 +1,52 @@
|
||||
import React from 'react'
|
||||
|
||||
interface IProps {
|
||||
path: string,
|
||||
downloadManager: any,
|
||||
}
|
||||
|
||||
interface IState {
|
||||
progress: number,
|
||||
status: string,
|
||||
total: number,
|
||||
}
|
||||
|
||||
export default class ProgressBar extends React.Component<IProps, IState> {
|
||||
constructor(props: IProps) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
progress: 0,
|
||||
status: '',
|
||||
total: this.props.downloadManager.getDownloadProgress(this.props.path).total,
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
// Periodically check the progress of passed file path
|
||||
const intv = setInterval(() => {
|
||||
const prog = this.props.downloadManager.getDownloadProgress(this.props.path)
|
||||
this.setState({
|
||||
progress: prog.progress,
|
||||
status: prog.status,
|
||||
})
|
||||
|
||||
if (prog.status === 'finished') {
|
||||
clearInterval(intv)
|
||||
}
|
||||
}, 100)
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className="ProgressBar">
|
||||
<div className="InnerProgress" style={{
|
||||
width: `${this.state.progress / this.state.total}%`,
|
||||
}}></div>
|
||||
<div className="ProgressText">
|
||||
{this.state.status}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user