-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4585624
commit 11b2ad1
Showing
13 changed files
with
135 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { Button, IconButton } from '@mui/material'; | ||
import { Fragment, memo, useEffect, useState } from 'react'; | ||
|
||
// import { useAxios } from '../common/AxiosContext'; | ||
import { useJupyterhub } from '../common/JupyterhubContext'; | ||
import urlJoin from 'url-join'; | ||
import SyncIcon from '@mui/icons-material/Sync'; | ||
|
||
interface IOpenServerButton { | ||
url: string; | ||
serverName: string; | ||
} | ||
|
||
function _OpenServerButton(props: IOpenServerButton) { | ||
// const axios = useAxios(); | ||
const jhData = useJupyterhub(); | ||
const [progress, setProgress] = useState(0); | ||
useEffect(() => { | ||
const { user, baseUrl, xsrfToken } = jhData; | ||
let progressUrl = urlJoin( | ||
baseUrl, | ||
'api', | ||
'users', | ||
user, | ||
'servers', | ||
props.serverName, | ||
'progress' | ||
); | ||
if (xsrfToken) { | ||
// add xsrf token to url parameter | ||
const sep = progressUrl.indexOf('?') === -1 ? '?' : '&'; | ||
progressUrl = progressUrl + sep + '_xsrf=' + xsrfToken; | ||
} | ||
|
||
const eventSource = new EventSource(progressUrl); | ||
eventSource.onerror = err => { | ||
setProgress(100); | ||
eventSource.close(); | ||
}; | ||
|
||
eventSource.onmessage = event => { | ||
const data = JSON.parse(event.data); | ||
|
||
setProgress(data.progress ?? 0); | ||
}; | ||
}, [jhData, setProgress]); | ||
|
||
return ( | ||
<Fragment> | ||
{progress === 100 && ( | ||
<Button href={props.url} target="_blank"> | ||
Open Server | ||
</Button> | ||
)} | ||
{progress < 100 && ( | ||
<IconButton title="Starting"> | ||
<SyncIcon | ||
sx={{ | ||
animation: 'spin 2s linear infinite', | ||
'@keyframes spin': { | ||
'0%': { | ||
transform: 'rotate(360deg)' | ||
}, | ||
'100%': { | ||
transform: 'rotate(0deg)' | ||
} | ||
} | ||
}} | ||
htmlColor="orange" | ||
/> | ||
</IconButton> | ||
)} | ||
</Fragment> | ||
); | ||
} | ||
|
||
export const OpenServerButton = memo(_OpenServerButton); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters