This commit is contained in:
oitsjustjose 2020-10-20 21:14:45 -05:00
commit d622cb0589
19 changed files with 1819 additions and 107 deletions

View file

@ -4,10 +4,10 @@ import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { BrowserRouter as Router, Route } from 'react-router-dom';
import LoadAuth from './auth/load';
import RequiresAuth from './components/modules/Auth';
import NavBar from './components/modules/NavBar';
import Dashboard from './components/view/Dashboard';
import Posts from './components/view/Posts';
import ConfigCreate from './components/view/ConfigCreate';
import Login from './components/view/Login';
import Register from './components/view/Register';
import store from './redux/store';
export default () => {
@ -18,8 +18,9 @@ export default () => {
<Router>
<NavBar />
<div style={{ paddingTop: `${3.5}em` }} />
<Route exact path="/" component={Posts} />
<RequiresAuth exact path="/manage" component={Dashboard} />
<Route exact path="/" component={ConfigCreate} />
<Route exact path="/login" component={Login} />
<Route exact path="/register" component={Register} />
</Router>
</Provider>,
document.getElementById('root'),

View file

@ -5,5 +5,5 @@ export default () => {
localStorage.removeItem('auth-token');
setAuthToken(null);
store.dispatch({ type: 'CLEAR_USER' });
window.location.reload();
window.location.href = '/';
};

View file

@ -0,0 +1,6 @@
import axios from 'axios';
export default (data) => {
console.log(data);
axios.post('/api/configs', data);
};

View file

@ -0,0 +1,20 @@
/* eslint-disable no-underscore-dangle */
import axios from 'axios';
import jwtDecode from 'jwt-decode';
import store from '../redux/store';
import setAuthToken from './AuthToken';
export default (data) => {
const path = '/api/users/register';
return axios.post(path, data)
.then((resp) => {
const token = resp.data;
localStorage.setItem('auth-token', token);
const user = jwtDecode(token);
store.dispatch({ type: 'SET_USER', user: user._doc });
setAuthToken(token);
});
};

View file

@ -0,0 +1,21 @@
import React from 'react';
import { Route } from 'react-router-dom';
import { CSSTransition } from 'react-transition-group';
import LoginPage from '../view/Login';
import store from '../../redux/store';
export default ({ children, ...rest }) => {
const state = store.getState();
if (state.isAuthenticated === undefined) {
return (
<CSSTransition classNames="react-router" appear in timeout={300}>
<div className="v-center"><h1>Loading...</h1></div>
</CSSTransition>
);
}
return (state.isAuthenticated && !!state.user)
? (<Route {...rest} />)
: (<Route {...rest} component={LoginPage} />);
};

View file

@ -0,0 +1,100 @@
import React, { useState } from 'react';
import {
Button, Form, InputGroup, OverlayTrigger, Tooltip,
} from 'react-bootstrap';
import { faMinus, faPlus } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
export default ({
onChangeSuper,
}) => {
const [entries, setEntries] = useState([true]);
const [biomes, setBiomes] = useState([null]);
const [isWhitelist, setWlMode] = useState(false);
const addEntry = () => {
const newBiomes = [...biomes, null];
setBiomes(newBiomes);
setEntries([...entries, true]);
onChangeSuper({
isWhitelist,
biomes: newBiomes,
});
};
const removeEntry = (targetIdx) => {
const newEntries = [...entries];
newEntries[targetIdx] = false;
setEntries(newEntries);
onChangeSuper({
isWhitelist,
biomes: biomes.filter((_, i) => entries[i] === true),
});
};
const onChange = (idx, value) => {
const newBiomes = [...biomes];
newBiomes[idx] = value;
setBiomes(newBiomes);
onChangeSuper({
isWhitelist,
biomes: newBiomes,
});
};
const onWlChange = (value) => {
setWlMode(value);
onChangeSuper({
isWhitelist: value,
biomes,
});
};
return entries.map((enabled, idx) => enabled && (
<Form.Group>
<InputGroup>
<OverlayTrigger
placement="top"
overlay={(
<Tooltip id={`biome-input-${idx}`}>
{'Format: <modid:biome> OR '}
<a rel="noreferrer noopener" href="https://oitsjustjo.se/u/GelX-uC1s" target="_blank">
Biome Type
</a>
</Tooltip>
)}
>
<Form.Control
required
type="text"
onChange={(evt) => onChange(idx, evt.target.value)}
/>
</OverlayTrigger>
{idx === 0 && (
<InputGroup.Append>
<InputGroup.Text>
Whitelist?
</InputGroup.Text>
<InputGroup.Checkbox
onChange={(evt) => onWlChange(evt.target.checked)}
aria-label="Checkbox for following text input"
/>
</InputGroup.Append>
)}
<InputGroup.Append>
<Button variant="success" onClick={addEntry}>
<FontAwesomeIcon icon={faPlus} />
</Button>
{idx !== 0 && (
<Button variant="danger" onClick={() => removeEntry(idx)}>
<FontAwesomeIcon icon={faMinus} />
</Button>
)}
</InputGroup.Append>
</InputGroup>
</Form.Group>
));
};

View file

@ -0,0 +1,67 @@
import React, { useState } from 'react';
import {
Button, Form, InputGroup, OverlayTrigger, Tooltip,
} from 'react-bootstrap';
import { faMinus, faPlus } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
export default ({
type, tooltipText, onChangeSuper,
}) => {
const [entries, setEntries] = useState([true]);
const [state, setState] = useState([null]);
const addEntry = () => {
const newState = [...state, null];
setState(newState);
onChangeSuper(newState);
setEntries([...entries, true]);
};
const removeEntry = (targetIdx) => {
const newEntries = [...entries];
newEntries[targetIdx] = false;
onChangeSuper(state.filter((_, i) => entries[i] === true));
setEntries(newEntries);
};
const onChange = (idx, value) => {
const newState = [...state];
newState[idx] = value;
setState(newState);
onChangeSuper(newState);
};
return entries.map((enabled, idx) => enabled && (
<Form.Group>
<InputGroup>
<OverlayTrigger
placement="top"
overlay={(
<Tooltip id={`${tooltipText}-${idx}`}>
{tooltipText}
</Tooltip>
)}
>
<Form.Control
required
type={type}
onChange={(evt) => onChange(idx, evt.target.value)}
/>
</OverlayTrigger>
<InputGroup.Append>
<Button variant="success" onClick={addEntry}>
<FontAwesomeIcon icon={faPlus} />
</Button>
{idx !== 0 && (
<Button variant="danger" onClick={() => removeEntry(idx)}>
<FontAwesomeIcon icon={faMinus} />
</Button>
)}
</InputGroup.Append>
</InputGroup>
</Form.Group>
));
};

View file

@ -0,0 +1,112 @@
import { faMinus, faPlus } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import React, { useState } from 'react';
import {
Button, Form, InputGroup, OverlayTrigger, Tooltip,
} from 'react-bootstrap';
export default ({
prefix, singular, onChangeSuper,
}) => {
const [entries, setEntries] = useState([true]);
const [state, setState] = useState([{
ore: '',
chance: 100,
}]);
const changePostEvt = (update) => {
onChangeSuper(update.filter((_, i) => entries[i] === true));
};
const addEntry = () => {
if (!singular) {
const newState = [...state, { ore: '', chance: 100 }];
setState(newState);
changePostEvt(newState);
setEntries([...entries, true]);
}
};
const removeEntry = (targetIdx) => {
if (!singular) {
const newEntries = [...entries];
newEntries[targetIdx] = false;
changePostEvt(state);
setEntries(newEntries);
}
};
const onChange = (idx, key, value) => {
const newState = [...state];
newState[idx] = {
...newState[idx],
[key]: value,
};
setState(newState);
changePostEvt(newState);
};
return (singular ? [entries[0]] : entries).map((enabled, idx) => enabled && (
<Form.Group>
<InputGroup>
<InputGroup.Prepend>
<InputGroup.Text>Block and Chance</InputGroup.Text>
</InputGroup.Prepend>
<OverlayTrigger
placement="top"
overlay={(
<Tooltip id={`tooltip-block-${prefix}-${idx}`}>
Format: modid:block or modid:block:meta
</Tooltip>
)}
>
<Form.Control
required
type="text"
value={state[idx].ore}
onChange={(evt) => onChange(idx, 'ore', evt.target.value)}
/>
</OverlayTrigger>
<OverlayTrigger
placement="top"
overlay={(
<Tooltip id={`tooltip-chance-${prefix}-${idx}`}>
All Chances
{' '}
<strong>MUST</strong>
{' '}
Add To 100
</Tooltip>
)}
>
<Form.Control
required
type="number"
min="1"
max="100"
value={(singular && 100) || state[idx].chance}
disabled={singular}
onChange={(evt) => onChange(idx, 'chance', parseInt(evt.target.value, 10))}
/>
</OverlayTrigger>
{!singular && (
<InputGroup.Append>
<Button variant="success" onClick={addEntry}>
<FontAwesomeIcon icon={faPlus} />
</Button>
{idx !== 0 && (
<Button variant="danger" onClick={() => removeEntry(idx)}>
<FontAwesomeIcon icon={faMinus} />
</Button>
)}
</InputGroup.Append>
)}
</InputGroup>
</Form.Group>
));
};

View file

@ -1,33 +1,70 @@
import { faSignOutAlt } from '@fortawesome/free-solid-svg-icons';
import React from 'react';
import { Nav, Navbar, NavItem } from 'react-bootstrap';
import {
faCode, faPlusSquare, faSignInAlt, faSignOutAlt,
} from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import NavLinkItem from './NavLinkItem';
import store from '../../redux/store';
import {
Form, Nav, Navbar, NavItem,
} from 'react-bootstrap';
import { connect } from 'react-redux';
import LogOut from '../../auth/logout';
import store from '../../redux/store';
import NavLinkItem from './NavLinkItem';
export default () => (
const NavBarComponent = ({
mc114Mode,
}) => (
<Navbar expand="lg" collapseOnSelect bg="dark" variant="dark" fixed="top">
<Navbar.Brand>Geolosys Configurator</Navbar.Brand>
<Navbar.Brand>
<span>
<img width="24" src={`${process.env.PUBLIC_URL}/logo.png`} alt="Geolosys Logo" />
{' '}
Configurator
</span>
</Navbar.Brand>
<Navbar.Toggle aria-controls="responsive-navbar-nav" />
<Navbar.Collapse>
<Nav className="mr-auto">
<NavLinkItem name="Blog" dest="/" icon={faBook} />
<NavLinkItem name="Create" dest="/" icon={faPlusSquare} />
{store.getState().isAuthenticated && (
<div>
<NavLinkItem name="Your Configs" dest="/manage" icon={faEdit} />
<NavItem style={{ cursor: 'pointer' }} onClick={LogOut}>
<div className="nav-link nav-sign-out">
<span>
<FontAwesomeIcon icon={faSignOutAlt} />
{' '}
Sign Out
</span>
</div>
</NavItem>
</div>
<NavLinkItem name="Your Configs" dest="/configs" icon={faCode} />
)}
{store.getState().isAuthenticated && (
<NavItem style={{ cursor: 'pointer' }} onClick={LogOut}>
<div className="nav-link nav-sign-out">
<span>
<FontAwesomeIcon icon={faSignOutAlt} />
{' '}
Sign Out
</span>
</div>
</NavItem>
)}
{!store.getState().isAuthenticated && (
<NavLinkItem name="Log In" dest="/login" icon={faSignInAlt} />
)}
<NavItem className="switch-nav-item align-bottom mt-2">
<Form.Check
type="switch"
label="For MC 1.14+"
id="mc114-switch"
checked={mc114Mode === true}
onChange={() => {
store.dispatch({ type: 'TOGGLE_MC_VER' });
}}
/>
</NavItem>
</Nav>
</Navbar.Collapse>
</Navbar>
);
const mapStateToProps = (state) => ({
mc114Mode: state.mc114,
});
export default connect(mapStateToProps)(NavBarComponent);

View file

@ -0,0 +1,125 @@
import React, { useState } from 'react';
import { Accordion, Container, Button } from 'react-bootstrap';
import { connect } from 'react-redux';
import ConfigRenderOre from './ConfigRenderOre';
import ConfigRenderStone from './ConfigRenderStone';
import PostGenerateJson from '../../axios/Generate';
const Configurator = ({
mc114,
}) => {
const [oreConfigs, setOreConfigs] = useState([true]);
const [stoneConfigs, setStoneConfigs] = useState([true]);
const [oreState, setOreState] = useState([{
name: '',
type: 'dense',
oreBlocks: null,
sampleBlocks: null,
maxY: 1,
minY: 0,
chance: 0,
size: 1,
density: 1,
dimBlacklist: [],
blockStateMatchers: [],
}]);
const [stoneState, setStoneState] = useState([{
block: '',
maxY: -1,
minY: -1,
chance: -1,
size: -1,
dimBlacklist: [],
}]);
const addOreEntry = () => {
setOreConfigs([...oreConfigs, true]);
};
const removeOreEntry = (targetIdx) => {
const cp = [...oreConfigs];
cp[targetIdx] = false;
setOreConfigs(cp);
};
const onOreConfigChange = (idx, oreConfigState) => {
const newState = [...oreState];
newState[idx] = oreConfigState;
console.log('Ore State Change', idx, oreConfigState);
console.log(newState);
setOreState(newState);
};
const addStoneEntry = () => {
setStoneConfigs([...stoneConfigs, true]);
};
const removeStoneEntry = (targetIdx) => {
const cp = [...stoneConfigs];
cp[targetIdx] = false;
setStoneConfigs(cp);
};
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>
<Container>
<h4>Ores</h4>
<Accordion defaultActiveKey="0">
{oreConfigs.map((enabled, idx) => enabled && (
<ConfigRenderOre
mc114={mc114}
onEntryCreation={addOreEntry}
onEntryDeletion={removeOreEntry}
onConfigChange={onOreConfigChange}
idx={idx}
/>
))}
</Accordion>
</Container>
<Container>
<h4>Stones</h4>
<Accordion defaultActiveKey="0">
{stoneConfigs.map((enabled, idx) => enabled && (
<ConfigRenderStone
mc114={mc114}
onEntryCreation={addStoneEntry}
onEntryDeletion={removeStoneEntry}
onConfigChange={onStoneConfigChange}
idx={idx}
/>
))}
</Accordion>
</Container>
<Button
onClick={() => PostGenerateJson({
ores: oreState,
stones: stoneState,
})}
className="d-block mx-auto my-4"
>
Generate!
</Button>
</div>
);
};
const mapStateToProps = (state) => ({
mc114: state.mc114,
});
export default connect(mapStateToProps)(Configurator);

View file

@ -0,0 +1,304 @@
import React, { useState } from 'react';
import { faMinus, faPlus } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import {
Accordion, Button, ButtonGroup, Card, Form, OverlayTrigger, Tooltip,
} from 'react-bootstrap';
import WeightedTextEntry from '../modules/Config/WeightedTextEntry';
import ExtendableInput from '../modules/Config/ExtendableInput';
import ExtendableBiomeInput from '../modules/Config/ExtendableBiomeInput';
export default ({
mc114, idx, onEntryCreation, onEntryDeletion, onConfigChange,
}) => {
const [state, setState] = useState({
name: '',
depType: 'deposit',
type: 'dense',
oreBlocks: null, // string or string[] depending on type
sampleBlocks: null, // string or string[] depending on type
maxY: 1,
minY: 0,
chance: 0,
size: 1,
density: 1,
dimBlacklist: [],
blockStateMatchers: [], // string[]
});
const setStateWithPropogation = (newState) => {
const formatted = { ...newState };
if (formatted.oreBlocks) {
formatted.oreBlocks = formatted.oreBlocks.map((x) => [x.ore, x.chance]).flat();
}
if (formatted.sampleBlocks) {
formatted.sampleBlocks = formatted.sampleBlocks.map((x) => [x.ore, x.chance]).flat();
}
delete formatted.depType;
setState(newState);
onConfigChange(idx, formatted);
};
return (
<Card>
<Card.Header>
<ButtonGroup>
<Accordion.Toggle as={Button} variant="outline-secondary" eventKey={`${idx}`}>
Config Entry
</Accordion.Toggle>
<Button variant="success" onClick={onEntryCreation}>
<FontAwesomeIcon icon={faPlus} />
</Button>
{idx !== 0 && (
<Button variant="danger" onClick={() => onEntryDeletion(idx)}>
<FontAwesomeIcon icon={faMinus} />
</Button>
)}
</ButtonGroup>
</Card.Header>
<Accordion.Collapse eventKey={`${idx}`}>
<Card.Body>
<Form style={{ padding: '12px' }} onSubmit={null}>
<Form.Group>
<Form.Label>
Deposit Name [Optional]
</Form.Label>
<Form.Control
type="text"
onChange={(evt) => {
setStateWithPropogation(
{ ...state, name: evt.target.value },
);
}}
/>
</Form.Group>
<Form.Group>
<Form.Label>
Deposit Type
</Form.Label>
<Form.Control
as="select"
value={state.depType}
onChange={(evt) => setStateWithPropogation(
{ ...state, depType: evt.target.value },
)}
>
<option value="deposit">Normal</option>
<option value="depositMulti">Multi-Ore</option>
<option value="depositBiome">Biome Specific</option>
<option value="depositBiomeMulti">Multi-Ore &amp; Biome Specific</option>
</Form.Control>
</Form.Group>
{mc114 && (
<Form.Group>
<Form.Label>
Deposit Structure Type (
<b>1.14+ Only</b>
)
</Form.Label>
<Form.Control
as="select"
value={state.type}
onChange={(evt) => setStateWithPropogation(
{ ...state, type: evt.target.value },
)}
>
<option value="dense">Dense</option>
<option value="sparse">Sparse</option>
<option value="dike">Dike</option>
<option value="layer">Layer</option>
</Form.Control>
</Form.Group>
)}
<Form.Group>
<Form.Label>
Ore Blocks
</Form.Label>
<WeightedTextEntry
singular={!state.depType.toLowerCase().includes('multi')}
prefix="ore"
onChangeSuper={(oreBlocks) => {
setStateWithPropogation({ ...state, oreBlocks });
}}
/>
</Form.Group>
<Form.Group>
<Form.Label>
Sample Blocks
</Form.Label>
<WeightedTextEntry
singular={!state.depType.toLowerCase().includes('multi')}
prefix="sample"
onChangeSuper={(sampleBlocks) => {
setStateWithPropogation({ ...state, sampleBlocks });
}}
/>
</Form.Group>
<Form.Group>
<Form.Label>
Maximum Y-Level
</Form.Label>
<Form.Control
required
type="number"
value={state.maxY}
min={1}
max={255}
onChange={(evt) => {
const maxY = (state.maxY < state.minY)
? state.minY + 1
: parseInt(evt.target.value, 10);
setStateWithPropogation({ ...state, maxY });
}}
/>
</Form.Group>
<Form.Group>
<Form.Label>
Minimum Y-Level
</Form.Label>
<Form.Control
required
type="number"
value={state.minY}
min={0}
max={254}
onChange={(evt) => {
const minY = (state.minY > state.maxY)
? state.maxY - 1
: parseInt(evt.target.value, 10);
setStateWithPropogation({ ...state, minY });
}}
/>
</Form.Group>
<Form.Group>
<Form.Label>
Chance (
<a rel="noreferrer noopener" target="_blank" href="https://oitsjustjo.se/u/M3NfQxBsZ">Relative To All Chances</a>
{' '}
)
</Form.Label>
<Form.Control
required
type="number"
value={state.chance}
min={0}
onChange={(evt) => setStateWithPropogation(
{ ...state, chance: parseInt(evt.target.value, 10) },
)}
/>
</Form.Group>
<Form.Group>
<Form.Label>
Size
</Form.Label>
<Form.Control
required
type="number"
value={state.size}
min={1}
onChange={(evt) => setStateWithPropogation(
{ ...state, size: parseInt(evt.target.value, 10) },
)}
/>
</Form.Group>
<Form.Group>
<Form.Label>
Density
</Form.Label>
<OverlayTrigger
placement="top"
overlay={(
<Tooltip id={`density-${idx}`}>
Any Decimal Between 0 and 1
</Tooltip>
)}
>
<Form.Control
required
type="number"
value={state.density}
onChange={(evt) => {
if (evt.target.value > 1) {
setStateWithPropogation(
{ ...state, density: 1 },
);
} else if (evt.target.value < 0) {
setStateWithPropogation(
{ ...state, density: 0 },
);
} else {
setStateWithPropogation(
{ ...state, density: Number(evt.target.value) },
);
}
}}
/>
</OverlayTrigger>
</Form.Group>
{state.depType.toLowerCase().includes('biome') && (
<Form.Group>
<Form.Label>
Biomes To Spawn / Not Spawn
</Form.Label>
<ExtendableBiomeInput onChangeSuper={(wlState) => setStateWithPropogation({
...state,
...wlState,
})}
/>
</Form.Group>
)}
<Form.Group>
<Form.Label>
Dimension Blacklist
</Form.Label>
<ExtendableInput
type={mc114 ? 'text' : 'number'}
tooltipText={mc114 ? 'Format: <modid:dimension>' : 'Any Dimension ID (e.g. -1, 1)'}
onChangeSuper={(dimBlacklist) => setStateWithPropogation(
{ ...state, dimBlacklist },
)}
/>
</Form.Group>
<Form.Group>
<Form.Label>
Blocks This Deposit May Replace
</Form.Label>
<ExtendableInput
type="text"
tooltipText="Format: <modid:block> or <modid:block:meta>"
onChangeSuper={(blockStateMatchers) => setStateWithPropogation(
{ ...state, blockStateMatchers },
)}
/>
</Form.Group>
</Form>
</Card.Body>
</Accordion.Collapse>
</Card>
);
};

View file

@ -0,0 +1,154 @@
import { faMinus, faPlus } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import React, { useState } from 'react';
import {
Accordion, Button, ButtonGroup, Card, Form,
} from 'react-bootstrap';
import ExtendableInput from '../modules/Config/ExtendableInput';
export default ({
mc114, idx, onEntryCreation, onEntryDeletion, onConfigChange,
}) => {
const [state, setState] = useState({
block: '',
maxY: 1,
minY: 0,
chance: 0,
size: 1,
dimBlacklist: [],
});
const setStateWithPropogation = (newState) => {
console.log(newState);
setState(newState);
onConfigChange(idx, newState);
};
return (
<Card>
<Card.Header>
<ButtonGroup>
<Accordion.Toggle as={Button} variant="outline-secondary" eventKey={`${idx}`}>
Config Entry
</Accordion.Toggle>
<Button variant="success" onClick={onEntryCreation}>
<FontAwesomeIcon icon={faPlus} />
</Button>
{idx !== 0 && (
<Button variant="danger" onClick={() => onEntryDeletion(idx)}>
<FontAwesomeIcon icon={faMinus} />
</Button>
)}
</ButtonGroup>
</Card.Header>
<Accordion.Collapse eventKey={`${idx}`}>
<Card.Body>
<Form style={{ padding: '12px' }} onSubmit={null}>
<Form.Group>
<Form.Label>
Stone Block
</Form.Label>
<Form.Control
required
onChange={(evt) => setStateWithPropogation({ ...state, block: evt.target.value })}
type="text"
/>
</Form.Group>
<Form.Group>
<Form.Label>
Maximum Y-Level
</Form.Label>
<Form.Control
required
type="number"
value={state.maxY}
min={1}
max={255}
onChange={(evt) => {
const maxY = (state.maxY < state.minY)
? state.minY + 1
: parseInt(evt.target.value, 10);
setStateWithPropogation({ ...state, maxY });
}}
/>
</Form.Group>
<Form.Group>
<Form.Label>
Minimum Y-Level
</Form.Label>
<Form.Control
required
type="number"
value={state.minY}
min={0}
max={254}
onChange={(evt) => {
const minY = (state.minY > state.maxY)
? state.maxY - 1
: parseInt(evt.target.value, 10);
setStateWithPropogation({ ...state, minY });
}}
/>
</Form.Group>
<Form.Group>
<Form.Label>
Chance (
<a rel="noreferrer noopener" target="_blank" href="https://oitsjustjo.se/u/M3NfQxBsZ">Relative To All Chances</a>
{' '}
)
</Form.Label>
<Form.Control
required
type="number"
value={state.chance}
min={0}
onChange={(evt) => setStateWithPropogation(
{ ...state, chance: parseInt(evt.target.value, 10) },
)}
/>
</Form.Group>
<Form.Group>
<Form.Label>
Size
</Form.Label>
<Form.Control
required
type="number"
value={state.size}
min={1}
onChange={(evt) => setStateWithPropogation(
{ ...state, size: parseInt(evt.target.value, 10) },
)}
/>
</Form.Group>
<Form.Group>
<Form.Label>
Dimension Blacklist
</Form.Label>
<ExtendableInput
type={mc114 ? 'text' : 'number'}
tooltipText={mc114 ? 'Format: <modid:dimension>' : 'Any Dimension ID (e.g. -1, 1)'}
onChangeSuper={(dimBlacklist) => setStateWithPropogation(
{ ...state, dimBlacklist },
)}
/>
</Form.Group>
</Form>
</Card.Body>
</Accordion.Collapse>
</Card>
);
};

View file

@ -4,6 +4,7 @@ import { connect } from 'react-redux';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faSignInAlt } from '@fortawesome/free-solid-svg-icons';
import { CSSTransition } from 'react-transition-group';
import { NavLink } from 'react-router-dom';
import postLogin from '../../axios/Login';
import Notification from '../modules/Notification';
@ -19,7 +20,7 @@ const LoginComponent = ({
useEffect(() => {
if (isAuthenticated) {
window.location.reload();
window.location.href = '/';
}
}, [isAuthenticated]);
@ -39,7 +40,7 @@ const LoginComponent = ({
className="mx-auto perfect-width"
>
<h2 className="text-center">
Admin Login
User Login
</h2>
<Form onSubmit={submit}>
<Form.Group>
@ -47,6 +48,7 @@ const LoginComponent = ({
Username
</Form.Label>
<Form.Control
required
type="text"
onChange={(evt) => { setState({ ...state, username: evt.target.value }); }}
/>
@ -56,18 +58,25 @@ const LoginComponent = ({
Password
</Form.Label>
<Form.Control
required
type="password"
onChange={(evt) => { setState({ ...state, password: evt.target.value }); }}
/>
</Form.Group>
<Button
type="submit"
>
<FontAwesomeIcon icon={faSignInAlt} />
{' '}
Log In
</Button>
<div className="d-flex" style={{ justifyContent: 'space-between' }}>
<NavLink to="/register">
<Button variant="secondary">
Register
</Button>
</NavLink>
<Button type="submit">
<FontAwesomeIcon icon={faSignInAlt} />
{' '}
Log In
</Button>
</div>
</Form>
</Container>
</div>

View file

@ -0,0 +1,117 @@
import React, { useEffect, useState } from 'react';
import { Button, Container, Form } from 'react-bootstrap';
import { connect } from 'react-redux';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faSignInAlt } from '@fortawesome/free-solid-svg-icons';
import { CSSTransition } from 'react-transition-group';
import postRegister from '../../axios/Register';
import Notification from '../modules/Notification';
const LoginComponent = ({
isAuthenticated,
}) => {
const [state, setState] = useState({
username: null,
password: null,
passwordConf: null,
usernameDup: false,
});
const [error, setError] = useState(null);
useEffect(() => {
if (isAuthenticated) {
window.location.href = '/';
}
}, [isAuthenticated]);
const submit = (evt) => {
evt.preventDefault();
if (state.password === state.passwordConf) {
const { username, password } = state;
postRegister({ username, password }).catch((ex) => {
if (ex.response && ex.response.data === 'USERNAME ALREADY EXISTS') {
setState({ ...state, usernameDup: true });
} else {
setError(`${ex.response.data}`);
}
});
}
};
return (
<CSSTransition classNames="react-router" appear in timeout={300}>
<div>
<div className="v-center">
<Container className="mx-auto perfect-width">
<h2 className="text-center">
New User Registration
</h2>
<Form onSubmit={submit}>
<Form.Group>
<Form.Label>
Username
</Form.Label>
<Form.Control
required
type="text"
onChange={(evt) => { setState({ ...state, username: evt.target.value }); }}
/>
{state.usernameDup && (
<Form.Text className="text-danger">Username Already Exists</Form.Text>
)}
</Form.Group>
<Form.Group>
<Form.Label>
Password
</Form.Label>
<Form.Control
required
type="password"
onChange={(evt) => { setState({ ...state, password: evt.target.value }); }}
/>
</Form.Group>
<Form.Group>
<Form.Label>
(Confirm)
</Form.Label>
<Form.Control
required
type="password"
onChange={(evt) => { setState({ ...state, passwordConf: evt.target.value }); }}
/>
{state.password !== state.passwordConf && (
<Form.Text className="text-danger">Passwords Do Not Match</Form.Text>
)}
</Form.Group>
<Button type="submit" disabled={!(!!state.username && !!state.password && state.password === state.passwordConf)}>
<FontAwesomeIcon icon={faSignInAlt} />
{' '}
Register
</Button>
</Form>
</Container>
</div>
<Notification
title="Failed to Register"
contents={error}
show={!!error}
onHide={() => setError(null)}
/>
</div>
</CSSTransition>
);
};
const mapStateToProps = (state) => ({
isAuthenticated: state.isAuthenticated,
user: state.user,
});
export default connect(mapStateToProps)(LoginComponent);

40
frontend/src/css/App.css Normal file
View file

@ -0,0 +1,40 @@
.perfect-width {
max-width: 384px;
width: 85%;
}
.v-center {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: calc(100vh - 3.5em);
}
.nav-link, .nav-sign-out {
transition: color ease-in-out 150ms;
}
.nav-sign-out:hover {
color: #dc3545 !important;
}
.react-router-appear {
opacity: 0;
transition: opacity ease-in-out 300ms;
}
.react-router-appear-done {
opacity: 1;
transition: opacity ease-in-out 300ms;
}
img.header {
width: 98vw;
max-width: 128px;
}
.switch-nav-item, .switch-nav-item * {
cursor: pointer !important;
color: #fff;
}

View file

@ -1,36 +1,34 @@
const defaultState = {
isAuthenticated: false,
user: null,
posts: null,
editingPost: null,
// editingPost: {
// id: null,
// title: null,
// contents: null,
// },
};
export default function reducer(
state = defaultState,
action,
) {
switch (action.type) {
case 'SET_USER':
return {
...state,
user: {
...action.user,
},
isAuthenticated: true,
};
case 'CLEAR_USER':
return {
...state,
user: null,
isAuthenticated: false,
};
default:
return state;
}
isAuthenticated: false,
user: null,
mc114: true,
};
export default function reducer(
state = defaultState,
action,
) {
switch (action.type) {
case 'SET_USER':
return {
...state,
user: {
...action.user,
},
isAuthenticated: true,
};
case 'CLEAR_USER':
return {
...state,
user: null,
isAuthenticated: false,
};
case 'TOGGLE_MC_VER':
return {
...state,
mc114: !state.mc114,
};
default:
return state;
}
}