Additional progress towards completion!
This commit is contained in:
parent
d622cb0589
commit
2eebc4f79e
16 changed files with 215 additions and 52 deletions
|
|
@ -5,6 +5,7 @@ import { Provider } from 'react-redux';
|
|||
import { BrowserRouter as Router, Route } from 'react-router-dom';
|
||||
import LoadAuth from './auth/load';
|
||||
import NavBar from './components/modules/NavBar';
|
||||
import ConfigBrowse from './components/view/ConfigBrowse';
|
||||
import ConfigCreate from './components/view/ConfigCreate';
|
||||
import Login from './components/view/Login';
|
||||
import Register from './components/view/Register';
|
||||
|
|
@ -20,6 +21,7 @@ export default () => {
|
|||
<div style={{ paddingTop: `${3.5}em` }} />
|
||||
<Route exact path="/" component={ConfigCreate} />
|
||||
<Route exact path="/login" component={Login} />
|
||||
<Route exact path="/browse" component={ConfigBrowse} />
|
||||
<Route exact path="/register" component={Register} />
|
||||
</Router>
|
||||
</Provider>,
|
||||
|
|
|
|||
4
frontend/src/axios/Config/GetConfig.js
Normal file
4
frontend/src/axios/Config/GetConfig.js
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
import axios from 'axios';
|
||||
|
||||
export default (id) => axios.get(`/api/configs/${id}`)
|
||||
.then((resp) => resp.data);
|
||||
7
frontend/src/axios/Config/GetConfigs.js
Normal file
7
frontend/src/axios/Config/GetConfigs.js
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import axios from 'axios';
|
||||
import store from '../../redux/store';
|
||||
|
||||
export default () => axios.get('/api/configs/')
|
||||
.then((resp) => {
|
||||
store.dispatch({ type: 'SET_CONFIGS', configs: resp.data || [] });
|
||||
});
|
||||
8
frontend/src/axios/Config/PutConfig.js
Normal file
8
frontend/src/axios/Config/PutConfig.js
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import axios from 'axios';
|
||||
import GetConfigs from './GetConfigs';
|
||||
|
||||
export default (data) => axios.put('/api/configs', data)
|
||||
.then((resp) => {
|
||||
GetConfigs();
|
||||
return resp.data;
|
||||
});
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
import axios from 'axios';
|
||||
|
||||
export default (data) => {
|
||||
console.log(data);
|
||||
axios.post('/api/configs', data);
|
||||
};
|
||||
|
|
@ -28,7 +28,7 @@ const NavBarComponent = ({
|
|||
<NavLinkItem name="Create" dest="/" icon={faPlusSquare} />
|
||||
|
||||
{store.getState().isAuthenticated && (
|
||||
<NavLinkItem name="Your Configs" dest="/configs" icon={faCode} />
|
||||
<NavLinkItem name="Your Configs" dest="/browse" icon={faCode} />
|
||||
)}
|
||||
|
||||
{store.getState().isAuthenticated && (
|
||||
|
|
|
|||
64
frontend/src/components/view/ConfigBrowse.jsx
Normal file
64
frontend/src/components/view/ConfigBrowse.jsx
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
import React from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
import { Table, Container } from 'react-bootstrap';
|
||||
import { CSSTransition } from 'react-transition-group';
|
||||
import GetConfigs from '../../axios/Config/GetConfigs';
|
||||
|
||||
const ConfigViewComponent = ({
|
||||
configs,
|
||||
}) => {
|
||||
if (!Array.isArray(configs)) {
|
||||
GetConfigs();
|
||||
return (
|
||||
<CSSTransition classNames="react-router" appear in timeout={300}>
|
||||
<div className="v-center"><h1>Loading...</h1></div>
|
||||
</CSSTransition>
|
||||
);
|
||||
}
|
||||
|
||||
if (!configs.length) {
|
||||
return (
|
||||
<CSSTransition classNames="react-router" appear in timeout={300}>
|
||||
<div className="v-center">
|
||||
<h1>
|
||||
No Configs Found
|
||||
{' '}
|
||||
<span role="img" aria-label="frown-emoji">🙁</span>
|
||||
</h1>
|
||||
</div>
|
||||
</CSSTransition>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<CSSTransition classNames="react-router" appear in timeout={300}>
|
||||
<div>
|
||||
<h2 className="text-center mt-3">Your Configs</h2>
|
||||
<Container className="perfect-width">
|
||||
<Table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>URL</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{configs.map((slug, idx) => (
|
||||
<tr>
|
||||
<td>{idx + 1}</td>
|
||||
<td><a href={`/?id=${slug}`}>{slug}</a></td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</Table>
|
||||
</Container>
|
||||
</div>
|
||||
</CSSTransition>
|
||||
);
|
||||
};
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
configs: state.configs,
|
||||
});
|
||||
|
||||
export default connect(mapStateToProps)(ConfigViewComponent);
|
||||
|
|
@ -1,13 +1,19 @@
|
|||
import React, { useState } from 'react';
|
||||
import { Accordion, Container, Button } from 'react-bootstrap';
|
||||
import { Accordion, Button, Container } from 'react-bootstrap';
|
||||
import { connect } from 'react-redux';
|
||||
import { CSSTransition } from 'react-transition-group';
|
||||
import PutConfig from '../../axios/Config/PutConfig';
|
||||
import GetConfig from '../../axios/Config/GetConfig';
|
||||
import ConfigRender from './ConfigRender';
|
||||
import ConfigRenderOre from './ConfigRenderOre';
|
||||
import ConfigRenderStone from './ConfigRenderStone';
|
||||
import PostGenerateJson from '../../axios/Generate';
|
||||
|
||||
const Configurator = ({
|
||||
mc114,
|
||||
}) => {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const [postRender, setPostRender] = useState(null);
|
||||
|
||||
const [oreConfigs, setOreConfigs] = useState([true]);
|
||||
const [stoneConfigs, setStoneConfigs] = useState([true]);
|
||||
const [oreState, setOreState] = useState([{
|
||||
|
|
@ -32,6 +38,21 @@ const Configurator = ({
|
|||
dimBlacklist: [],
|
||||
}]);
|
||||
|
||||
if (params.has('id')) {
|
||||
if (postRender) {
|
||||
return (<ConfigRender jsonData={postRender} />);
|
||||
}
|
||||
|
||||
GetConfig(params.get('id')).then((data) => (
|
||||
setPostRender(data)
|
||||
));
|
||||
return (
|
||||
<CSSTransition classNames="react-router" appear in timeout={300}>
|
||||
<div className="v-center"><h1>Loading...</h1></div>
|
||||
</CSSTransition>
|
||||
);
|
||||
}
|
||||
|
||||
const addOreEntry = () => {
|
||||
setOreConfigs([...oreConfigs, true]);
|
||||
};
|
||||
|
|
@ -45,8 +66,6 @@ const Configurator = ({
|
|||
const onOreConfigChange = (idx, oreConfigState) => {
|
||||
const newState = [...oreState];
|
||||
newState[idx] = oreConfigState;
|
||||
console.log('Ore State Change', idx, oreConfigState);
|
||||
console.log(newState);
|
||||
setOreState(newState);
|
||||
};
|
||||
|
||||
|
|
@ -63,22 +82,21 @@ const Configurator = ({
|
|||
const onStoneConfigChange = (idx, stoneConfigState) => {
|
||||
const newState = [...stoneState];
|
||||
newState[idx] = stoneConfigState;
|
||||
console.log('Stone State Change', idx, stoneConfigState);
|
||||
console.log(newState);
|
||||
setStoneState(newState);
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="text-center d-block">
|
||||
<img className="header" src={`${process.env.PUBLIC_URL}/logo.png`} alt="Geolosys Logo" />
|
||||
<h4>Geolosys Deposit Configurator</h4>
|
||||
</div>
|
||||
<CSSTransition classNames="react-router" appear in timeout={300}>
|
||||
<div>
|
||||
<div className="text-center d-block">
|
||||
<img className="header" src={`${process.env.PUBLIC_URL}/logo.png`} alt="Geolosys Logo" />
|
||||
<h4>Geolosys Deposit Configurator</h4>
|
||||
</div>
|
||||
|
||||
<Container>
|
||||
<h4>Ores</h4>
|
||||
<Accordion defaultActiveKey="0">
|
||||
{oreConfigs.map((enabled, idx) => enabled && (
|
||||
<Container>
|
||||
<h4>Ores</h4>
|
||||
<Accordion defaultActiveKey="0">
|
||||
{oreConfigs.map((enabled, idx) => enabled && (
|
||||
<ConfigRenderOre
|
||||
mc114={mc114}
|
||||
onEntryCreation={addOreEntry}
|
||||
|
|
@ -86,14 +104,14 @@ const Configurator = ({
|
|||
onConfigChange={onOreConfigChange}
|
||||
idx={idx}
|
||||
/>
|
||||
))}
|
||||
</Accordion>
|
||||
</Container>
|
||||
))}
|
||||
</Accordion>
|
||||
</Container>
|
||||
|
||||
<Container>
|
||||
<h4>Stones</h4>
|
||||
<Accordion defaultActiveKey="0">
|
||||
{stoneConfigs.map((enabled, idx) => enabled && (
|
||||
<Container>
|
||||
<h4>Stones</h4>
|
||||
<Accordion defaultActiveKey="0">
|
||||
{stoneConfigs.map((enabled, idx) => enabled && (
|
||||
<ConfigRenderStone
|
||||
mc114={mc114}
|
||||
onEntryCreation={addStoneEntry}
|
||||
|
|
@ -101,20 +119,25 @@ const Configurator = ({
|
|||
onConfigChange={onStoneConfigChange}
|
||||
idx={idx}
|
||||
/>
|
||||
))}
|
||||
</Accordion>
|
||||
</Container>
|
||||
))}
|
||||
</Accordion>
|
||||
</Container>
|
||||
|
||||
<Button
|
||||
onClick={() => PostGenerateJson({
|
||||
ores: oreState,
|
||||
stones: stoneState,
|
||||
})}
|
||||
className="d-block mx-auto my-4"
|
||||
>
|
||||
Generate!
|
||||
</Button>
|
||||
</div>
|
||||
<Button
|
||||
onClick={() => PutConfig({
|
||||
json: {
|
||||
ores: oreState,
|
||||
stones: stoneState,
|
||||
},
|
||||
}).then((data) => {
|
||||
window.location.href = `/?id=${data}`;
|
||||
})}
|
||||
className="d-block mx-auto my-4"
|
||||
>
|
||||
Generate!
|
||||
</Button>
|
||||
</div>
|
||||
</CSSTransition>
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
|||
15
frontend/src/components/view/ConfigRender.jsx
Normal file
15
frontend/src/components/view/ConfigRender.jsx
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import React from 'react';
|
||||
import { Container } from 'react-bootstrap';
|
||||
|
||||
export default ({
|
||||
jsonData,
|
||||
}) => (
|
||||
<div>
|
||||
<h2 className="text-center mt-3">Config View</h2>
|
||||
<Container className="shadow mt-5">
|
||||
<pre>
|
||||
{JSON.stringify(jsonData.json, null, 2) }
|
||||
</pre>
|
||||
</Container>
|
||||
</div>
|
||||
);
|
||||
|
|
@ -19,7 +19,6 @@ export default ({
|
|||
});
|
||||
|
||||
const setStateWithPropogation = (newState) => {
|
||||
console.log(newState);
|
||||
setState(newState);
|
||||
onConfigChange(idx, newState);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,3 +1,20 @@
|
|||
@font-face {
|
||||
font-family: 'JetBrainsMono';
|
||||
src: url('https://cdn.jsdelivr.net/gh/JetBrains/JetBrainsMono/web/woff2/JetBrainsMono-Regular.woff2') format('woff2'), url('https://cdn.jsdelivr.net/gh/JetBrains/JetBrainsMono/web/woff/JetBrainsMono-Regular.woff') format('woff'), url('https://cdn.jsdelivr.net/gh/JetBrains/JetBrainsMono/ttf/JetBrainsMono-Regular.ttf') format('truetype');
|
||||
font-weight: 400;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
pre {
|
||||
font-family: 'JetBrainsMono';
|
||||
font-variant-ligatures: common-ligatures;
|
||||
}
|
||||
|
||||
.container.perfect-width {
|
||||
max-width: 768px;
|
||||
width: 98%;
|
||||
}
|
||||
|
||||
.perfect-width {
|
||||
max-width: 384px;
|
||||
width: 85%;
|
||||
|
|
@ -37,4 +54,4 @@ img.header {
|
|||
.switch-nav-item, .switch-nav-item * {
|
||||
cursor: pointer !important;
|
||||
color: #fff;
|
||||
}
|
||||
}
|
||||
|
|
@ -28,6 +28,11 @@ export default function reducer(
|
|||
...state,
|
||||
mc114: !state.mc114,
|
||||
};
|
||||
case 'SET_CONFIGS':
|
||||
return {
|
||||
...state,
|
||||
configs: action.configs,
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue