svg-layout-designer-react/src/App.tsx
Hydroxycarbamide adf86ebea1 Create sidebar
2022-07-30 22:02:56 +02:00

69 lines
1.7 KiB
TypeScript

import React from 'react';
import './App.scss';
import Sidebar from './Components/Sidebar/Sidebar';
import { IAvailableContainerModel } from './Interfaces/IAvailableContainerModel';
import { IConfigurationResponseModel } from './Interfaces/IConfigurationResponseModel';
interface IAppProps {
}
interface IAppState {
componentOptions: IAvailableContainerModel[]
isSidebarOpen: boolean
}
class App extends React.Component<IAppProps> {
public state: IAppState;
constructor(props: IAppProps) {
super(props);
this.state = {
isSidebarOpen: true,
componentOptions: []
};
}
componentDidMount() {
fetchConfiguration().then((configuration: IConfigurationResponseModel) => {
this.setState({
isSidebarOpen: this.state.isSidebarOpen,
componentOptions: configuration.AvailableContainers
});
});
}
public ToggleMenu() {
this.setState({
isSidebarOpen: !this.state.isSidebarOpen,
componentOptions: this.state.componentOptions
});
}
render() {
return (
<div className="App font-sans h-full">
<Sidebar componentOptions={this.state.componentOptions} isOpen={this.state.isSidebarOpen} onClick={() => this.ToggleMenu()} />
<button className='fixed z-0 top-4 left-4 text-lg' onClick={() => this.ToggleMenu()}>&#9776; Menu</button>
</div>
);
}
}
async function fetchConfiguration(): Promise<IConfigurationResponseModel> {
const url = `${import.meta.env.VITE_API_URL}`;
const myHeaders = new Headers({
'Content-Type': 'application/json'
});
const myInit = {
method: 'POST',
headers: myHeaders
};
return await fetch(url, myInit)
.then((response) =>
response.json()
) as IConfigurationResponseModel;
}
export default App;