Additional progress towards completion!

This commit is contained in:
oitsjustjose 2020-10-20 22:27:36 -05:00
commit 2eebc4f79e
16 changed files with 215 additions and 52 deletions

View file

@ -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 && (

View 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);

View file

@ -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>
);
};

View 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>
);

View file

@ -19,7 +19,6 @@ export default ({
});
const setStateWithPropogation = (newState) => {
console.log(newState);
setState(newState);
onConfigChange(idx, newState);
};