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

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