-
Notifications
You must be signed in to change notification settings - Fork 15
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
ce7abe6
commit 5127a50
Showing
11 changed files
with
296 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { Button } from '@mui/material'; | ||
import Dialog from '@mui/material/Dialog'; | ||
import DialogActions from '@mui/material/DialogActions'; | ||
import DialogContent from '@mui/material/DialogContent'; | ||
import DialogTitle from '@mui/material/DialogTitle'; | ||
import CircularProgress from '@mui/material/CircularProgress'; | ||
import Box from '@mui/material/Box'; | ||
import { Fragment, memo, useCallback, useState } from 'react'; | ||
|
||
interface IButtonWithConfirm { | ||
buttonLabel: string; | ||
dialogTitle: string; | ||
dialogBody: JSX.Element; | ||
action: (() => void) | (() => Promise<void>); | ||
okLabel?: string; | ||
cancelLabel?: string; | ||
} | ||
const Loading = () => ( | ||
<Box sx={{ display: 'flex', justifyContent: 'center' }}> | ||
<CircularProgress /> | ||
</Box> | ||
); | ||
function _ButtonWithConfirm(props: IButtonWithConfirm) { | ||
const [open, setOpen] = useState(false); | ||
const [loading, setLoading] = useState(false); | ||
const handleOpen = () => { | ||
setOpen(true); | ||
}; | ||
const handleClose = ( | ||
event?: any, | ||
reason?: 'backdropClick' | 'escapeKeyDown' | ||
) => { | ||
if (reason && reason === 'backdropClick') { | ||
return; | ||
} | ||
setOpen(false); | ||
}; | ||
|
||
const removeEnv = useCallback(async () => { | ||
setLoading(true); | ||
await props.action(); | ||
handleClose(); | ||
}, [props.action, setLoading]); | ||
|
||
return ( | ||
<Fragment> | ||
<Button onClick={handleOpen} color="error" size="small"> | ||
{props.buttonLabel} | ||
</Button> | ||
|
||
<Dialog open={open} onClose={handleClose} fullWidth maxWidth={'sm'}> | ||
<DialogTitle>{props.dialogTitle}</DialogTitle> | ||
<DialogContent> | ||
{!loading && props.dialogBody} | ||
{loading && <Loading />} | ||
</DialogContent> | ||
<DialogActions> | ||
<Button variant="contained" onClick={handleClose}> | ||
{props.cancelLabel ?? 'Cancel'} | ||
</Button> | ||
<Button variant="contained" color="error" onClick={removeEnv}> | ||
{props.okLabel ?? 'Accept'} | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
</Fragment> | ||
); | ||
} | ||
|
||
export const ButtonWithConfirm = memo(_ButtonWithConfirm); |
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,37 @@ | ||
import { Stack } from '@mui/material'; | ||
import ScopedCssBaseline from '@mui/material/ScopedCssBaseline'; | ||
import { ThemeProvider } from '@mui/material/styles'; | ||
|
||
import { customTheme } from '../common/theme'; | ||
import { IServerData } from './types'; | ||
import { AxiosContext } from '../common/AxiosContext'; | ||
import { useMemo } from 'react'; | ||
import { AxiosClient } from '../common/axiosclient'; | ||
import { ServerList } from './ServersList'; | ||
|
||
export interface IAppProps { | ||
server_data: IServerData[]; | ||
allow_named_servers: boolean; | ||
named_server_limit_per_user: number; | ||
} | ||
export default function App(props: IAppProps) { | ||
const axios = useMemo(() => { | ||
const jhData = (window as any).jhdata; | ||
const baseUrl = jhData.base_url; | ||
const xsrfToken = jhData.xsrf_token; | ||
return new AxiosClient({ baseUrl, xsrfToken }); | ||
}, []); | ||
console.log('props', props); | ||
|
||
return ( | ||
<ThemeProvider theme={customTheme}> | ||
<AxiosContext.Provider value={axios}> | ||
<ScopedCssBaseline> | ||
<Stack sx={{ padding: 1 }} spacing={1}> | ||
<ServerList servers={props.server_data} /> | ||
</Stack> | ||
</ScopedCssBaseline> | ||
</AxiosContext.Provider> | ||
</ThemeProvider> | ||
); | ||
} |
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,88 @@ | ||
import { DataGrid, GridColDef } from '@mui/x-data-grid'; | ||
import { memo, useMemo } from 'react'; | ||
|
||
import { Box } from '@mui/system'; | ||
import { IServerData } from './types'; | ||
import { formatTime } from '../common/utils'; | ||
|
||
const columns: GridColDef[] = [ | ||
{ | ||
field: 'name', | ||
headerName: 'Server name', | ||
flex: 1 | ||
}, | ||
{ | ||
field: 'url', | ||
headerName: 'URL', | ||
flex: 1, | ||
renderCell: params => { | ||
return ( | ||
<a href={params.value} target="_blank"> | ||
{params.value} | ||
</a> | ||
); | ||
} | ||
}, | ||
{ | ||
field: 'last_activity', | ||
headerName: 'Last activity', | ||
flex: 1, | ||
maxWidth: 150 | ||
}, | ||
{ | ||
field: 'image', | ||
headerName: 'Image', | ||
flex:1, | ||
}, | ||
{ | ||
field: 'status', | ||
headerName: '', | ||
width: 150, | ||
filterable: false, | ||
sortable: false, | ||
hideable: false, | ||
}, | ||
{ | ||
field: 'action', | ||
headerName: '', | ||
width: 100, | ||
filterable: false, | ||
sortable: false, | ||
hideable: false | ||
} | ||
]; | ||
|
||
export interface IServerListProps { | ||
servers: IServerData[]; | ||
} | ||
|
||
function _ServerList(props: IServerListProps) { | ||
const rows = useMemo(() => { | ||
return props.servers.map((it, id) => { | ||
const newItem: any = { ...it, id }; | ||
newItem.image = it.user_options.image ?? ''; | ||
newItem.last_activity = formatTime(newItem.last_activity); | ||
return newItem; | ||
}); | ||
}, [props]); | ||
|
||
return ( | ||
<Box sx={{ padding: 1 }}> | ||
<DataGrid | ||
rows={rows} | ||
columns={columns} | ||
initialState={{ | ||
pagination: { | ||
paginationModel: { | ||
pageSize: 100 | ||
} | ||
} | ||
}} | ||
pageSizeOptions={[100]} | ||
disableRowSelectionOnClick | ||
/> | ||
</Box> | ||
); | ||
} | ||
|
||
export const ServerList = memo(_ServerList); |
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,29 @@ | ||
import '@fontsource/roboto/300.css'; | ||
import '@fontsource/roboto/400.css'; | ||
import '@fontsource/roboto/500.css'; | ||
import '@fontsource/roboto/700.css'; | ||
|
||
import { StrictMode } from 'react'; | ||
import { createRoot } from 'react-dom/client'; | ||
|
||
import App, { IAppProps } from './App'; | ||
|
||
const rootElement = document.getElementById('servers-root'); | ||
const root = createRoot(rootElement!); | ||
console.log('AAAAAAAAAA'); | ||
|
||
const dataElement = document.getElementById('tljh-page-data'); | ||
let configData: IAppProps = { | ||
server_data: [], | ||
allow_named_servers: false, | ||
named_server_limit_per_user: 0 | ||
}; | ||
if (dataElement) { | ||
configData = JSON.parse(dataElement.textContent || '') as IAppProps; | ||
} | ||
|
||
root.render( | ||
<StrictMode> | ||
<App {...configData} /> | ||
</StrictMode> | ||
); |
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,7 @@ | ||
export const API_PREFIX = 'spawn'; | ||
export interface IServerData { | ||
name: string; | ||
url: string; | ||
last_activity: string; | ||
user_options: { image?: string }; | ||
} |
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
Oops, something went wrong.