-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* build(deps): bump @types/node from 16.11.4 to 16.11.6 Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 16.11.4 to 16.11.6. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) --- updated-dependencies: - dependency-name: "@types/node" dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * Fix RemoveZoneCommand * build(deps): bump @mui/material from 5.0.5 to 5.0.6 Bumps [@mui/material](https://github.com/mui-org/material-ui/tree/HEAD/packages/mui-material) from 5.0.5 to 5.0.6. - [Release notes](https://github.com/mui-org/material-ui/releases) - [Changelog](https://github.com/mui-org/material-ui/blob/master/CHANGELOG.md) - [Commits](https://github.com/mui-org/material-ui/commits/v5.0.6/packages/mui-material) --- updated-dependencies: - dependency-name: "@mui/material" dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * build(deps-dev): bump @types/react from 17.0.32 to 17.0.33 Bumps [@types/react](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/react) from 17.0.32 to 17.0.33. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/react) --- updated-dependencies: - dependency-name: "@types/react" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * Add simple login panel * Add start simulation ui in SimulationPanel * add mocked api request (#204) * update post req (#204) * update comment * update url * update urls and cors (#204) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: ostatni5 <26521377+ostatni5@users.noreply.github.com>
- Loading branch information
1 parent
9fe3b18
commit 057f4c4
Showing
14 changed files
with
238 additions
and
29 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,60 @@ | ||
import { Box, Button, TextField } from "@mui/material"; | ||
import React from "react"; | ||
|
||
interface LoginPanelProps { | ||
handleLogin: (data:{email:string,password:string}) => void; | ||
} | ||
|
||
export default function LoginPanel(props: LoginPanelProps) { | ||
const [email, setEmail] = React.useState(''); | ||
const handleEmailChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
setEmail(event.target.value); | ||
}; | ||
const [password, setPassword] = React.useState(''); | ||
const handlePasswordChange = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
setPassword(event.target.value); | ||
}; | ||
return ( | ||
<Box sx={{ | ||
margin: "0 auto", | ||
display: "flex", | ||
alignItems: "center", | ||
padding: "5rem" | ||
}}> | ||
<Box component="form" | ||
sx={{ | ||
margin: "0 auto", | ||
backgroundColor: "rgba(255,255,255,.6)", | ||
display: "flex", | ||
flexDirection: "column", | ||
gap: "1.5rem", | ||
padding: "5rem" | ||
}} | ||
> | ||
<TextField | ||
id="loginField" | ||
label="Email adress" | ||
variant="outlined" | ||
value={email} | ||
onChange={handleEmailChange} | ||
/> | ||
<TextField | ||
id="passwordField" | ||
label="Password" | ||
variant="outlined" | ||
type="password" | ||
value={password} | ||
onChange={handlePasswordChange} | ||
/> | ||
<Button | ||
variant="outlined" | ||
onClick={()=>{ | ||
setPassword('') | ||
setEmail('') | ||
props.handleLogin({email,password}) | ||
}} | ||
>Login</Button> | ||
</Box> | ||
</Box> | ||
) | ||
} |
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,63 @@ | ||
import { Box, Button, LinearProgress } from '@mui/material'; | ||
import ky from 'ky'; | ||
|
||
import React, { useState } from "react"; | ||
import { useStore } from '../../services/StoreService'; | ||
import { BACKEND_URL, CORS } from '../../util/Config'; | ||
|
||
interface SimulationPanelProps { | ||
onError?: (error: unknown) => void; | ||
onSuccess?: (result: unknown) => void; | ||
} | ||
|
||
export default function SimulationPanel(props: SimulationPanelProps) { | ||
const { editorRef } = useStore(); | ||
const [isInProgress, setInProgress] = useState<boolean>(false); | ||
|
||
const sendRequest = () => { | ||
setInProgress(true); | ||
ky.post(`${BACKEND_URL}/sh/demo`, { | ||
mode: CORS ? 'cors' : 'no-cors', | ||
json: editorRef.current?.toJSON() | ||
}) | ||
.json() | ||
.then((response) => { | ||
alert(response); | ||
props.onSuccess?.call(null, response); | ||
}) | ||
.catch((error) => { | ||
alert(error); | ||
props.onError?.call(null, error); | ||
}).finally(() => { | ||
setInProgress(false); | ||
}); | ||
}; | ||
|
||
return ( | ||
<Box sx={{ | ||
margin: "0 auto", | ||
width: "min(960px, 100%)", | ||
padding: "5rem", | ||
display: "flex", | ||
flexDirection: "column", | ||
gap: "1.5rem", | ||
}}> | ||
<LinearProgress | ||
variant={ | ||
isInProgress ? 'indeterminate' : 'determinate' | ||
} | ||
value={0} | ||
/> | ||
<Button | ||
sx={{ | ||
width: "min(300px, 100%)", | ||
margin: "0 auto", | ||
}} | ||
onClick={sendRequest} | ||
|
||
> | ||
{isInProgress ? 'Stop' : 'Start'} | ||
</Button> | ||
</Box> | ||
); | ||
} |
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,34 @@ | ||
import { ReactNode, useRef } from "react"; | ||
import { Editor } from "../ThreeEditor/js/Editor"; | ||
import { createGenericContext } from "../util/GenericContext"; | ||
|
||
|
||
|
||
export interface StoreProps { | ||
children: ReactNode | ||
} | ||
|
||
export interface IStore { | ||
editorRef: React.MutableRefObject<Editor | undefined> | ||
} | ||
|
||
const [useStore, StoreContextProvider] = createGenericContext<IStore>(); | ||
|
||
const Store = (props: StoreProps) => { | ||
const editorRef = useRef<Editor>(); | ||
|
||
const value: IStore = { | ||
editorRef | ||
} | ||
|
||
return ( | ||
<StoreContextProvider value={value}> | ||
{props.children} | ||
</StoreContextProvider> | ||
) | ||
}; | ||
|
||
export { | ||
useStore, | ||
Store | ||
} |
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,3 @@ | ||
export const BACKEND_URL = process.env.REACT_APP_BACKEND_URL ?? 'http://localhost:5000'; | ||
export const CORS = false; | ||
export const DEMO_MODE = process.env.REACT_APP_TARGET === 'demo'; |
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,17 @@ | ||
import React from "react"; | ||
|
||
export const createGenericContext = <T extends unknown>() => { | ||
// Create a context with a generic parameter or undefined | ||
const genericContext = React.createContext<T | undefined>(undefined); | ||
|
||
// Check if the value provided to the context is defined or throw an error | ||
const useGenericContext = () => { | ||
const contextIsDefined = React.useContext(genericContext); | ||
if (!contextIsDefined) { | ||
throw new Error("useGenericContext must be used within a Provider"); | ||
} | ||
return contextIsDefined; | ||
}; | ||
|
||
return [useGenericContext, genericContext.Provider] as const; | ||
}; |
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,4 @@ | ||
export default interface UserData{ | ||
uuid: string, | ||
login: string, | ||
} |