]> git.localhorst.tv Git - alttp.git/commitdiff
basic seed code input
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 25 Oct 2022 12:29:23 +0000 (14:29 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 25 Oct 2022 12:29:23 +0000 (14:29 +0200)
app/Http/Controllers/RoundController.php
resources/js/components/rounds/EditForm.js
resources/js/components/rounds/Item.js
resources/js/components/rounds/SeedCodeInput.js [new file with mode: 0644]
resources/js/i18n/de.js
resources/js/i18n/en.js

index 2b6c617acfbaa03d93df72544f4881d2036eb812..337e1111fea27dcde1c2a229121e9d4cb429f8a9 100644 (file)
@@ -43,10 +43,13 @@ class RoundController extends Controller
                $this->authorize('update', $round);
 
                $validatedData = $request->validate([
                $this->authorize('update', $round);
 
                $validatedData = $request->validate([
+                       'code' => 'array',
+                       'code.*' => 'string',
                        'seed' => 'url',
                        'title' => 'string',
                ]);
 
                        'seed' => 'url',
                        'title' => 'string',
                ]);
 
+               $round->code = array_filter($validatedData['code']);
                $round->seed = $validatedData['seed'];
                $round->title = $validatedData['title'];
                $round->update();
                $round->seed = $validatedData['seed'];
                $round->title = $validatedData['title'];
                $round->update();
index 57ee95a5a6e1298c97d9891617beab9e121ac376..3d0d0b368ad0749008b4153327a5f85c37cc37ed 100644 (file)
@@ -6,6 +6,7 @@ import { Button, Col, Form, Modal, Row } from 'react-bootstrap';
 import { withTranslation } from 'react-i18next';
 import toastr from 'toastr';
 
 import { withTranslation } from 'react-i18next';
 import toastr from 'toastr';
 
+import SeedCodeInput from './SeedCodeInput';
 import laravelErrorsToFormik from '../../helpers/laravelErrorsToFormik';
 import i18n from '../../i18n';
 import yup from '../../schema/yup';
 import laravelErrorsToFormik from '../../helpers/laravelErrorsToFormik';
 import i18n from '../../i18n';
 import yup from '../../schema/yup';
@@ -57,6 +58,25 @@ const EditForm = ({
                                : null}
                        </Form.Group>
                </Row>
                                : null}
                        </Form.Group>
                </Row>
+               <Row>
+                       <Form.Group as={Col}>
+                               <Form.Label>{i18n.t('rounds.code')}</Form.Label>
+                               <Form.Control
+                                       as={SeedCodeInput}
+                                       game={values.game || 'mixed'}
+                                       isInvalid={!!(touched.code && errors.code)}
+                                       name="code"
+                                       onBlur={handleBlur}
+                                       onChange={handleChange}
+                                       value={values.code || []}
+                               />
+                               {touched.code && errors.code ?
+                                       <Form.Control.Feedback type="invalid">
+                                               {i18n.t(errors.code)}
+                                       </Form.Control.Feedback>
+                               : null}
+                       </Form.Group>
+               </Row>
        </Modal.Body>
        <Modal.Footer>
                {onCancel ?
        </Modal.Body>
        <Modal.Footer>
                {onCancel ?
@@ -72,6 +92,7 @@ const EditForm = ({
 
 EditForm.propTypes = {
        errors: PropTypes.shape({
 
 EditForm.propTypes = {
        errors: PropTypes.shape({
+               code: PropTypes.arrayOf(PropTypes.string),
                seed: PropTypes.string,
                title: PropTypes.string,
        }),
                seed: PropTypes.string,
                title: PropTypes.string,
        }),
@@ -80,10 +101,13 @@ EditForm.propTypes = {
        handleSubmit: PropTypes.func,
        onCancel: PropTypes.func,
        touched: PropTypes.shape({
        handleSubmit: PropTypes.func,
        onCancel: PropTypes.func,
        touched: PropTypes.shape({
+               code: PropTypes.arrayOf(PropTypes.bool),
                seed: PropTypes.bool,
                title: PropTypes.bool,
        }),
        values: PropTypes.shape({
                seed: PropTypes.bool,
                title: PropTypes.bool,
        }),
        values: PropTypes.shape({
+               code: PropTypes.arrayOf(PropTypes.string),
+               game: PropTypes.string,
                seed: PropTypes.string,
                title: PropTypes.string,
        }),
                seed: PropTypes.string,
                title: PropTypes.string,
        }),
@@ -110,11 +134,14 @@ export default withFormik({
                }
        },
        mapPropsToValues: ({ round }) => ({
                }
        },
        mapPropsToValues: ({ round }) => ({
+               code: round.code || [],
+               game: round.game || 'mixed',
                round_id: round.id,
                seed: round.seed || '',
                title: round.title || '',
        }),
        validationSchema: yup.object().shape({
                round_id: round.id,
                seed: round.seed || '',
                title: round.title || '',
        }),
        validationSchema: yup.object().shape({
+               code: yup.array().of(yup.string()),
                seed: yup.string().url(),
                title: yup.string(),
        }),
                seed: yup.string().url(),
                title: yup.string(),
        }),
index 92f55a06791098adda7b299ebf241665874ccdff..3197f6d9aa64da0a8df2c68a02b7f1a522deae7b 100644 (file)
@@ -51,7 +51,7 @@ const Item = ({
                                {i18n.t('rounds.date', { date: new Date(round.created_at) })}
                        </p>
                        <p className="seed">
                                {i18n.t('rounds.date', { date: new Date(round.created_at) })}
                        </p>
                        <p className="seed">
-                               {round.code ?
+                               {round.code && round.code.length ?
                                        <>
                                                <SeedCode code={round.code} game={round.game || 'alttpr'} />
                                                <br />
                                        <>
                                                <SeedCode code={round.code} game={round.game || 'alttpr'} />
                                                <br />
diff --git a/resources/js/components/rounds/SeedCodeInput.js b/resources/js/components/rounds/SeedCodeInput.js
new file mode 100644 (file)
index 0000000..03dd682
--- /dev/null
@@ -0,0 +1,162 @@
+import PropTypes from 'prop-types';
+import React from 'react';
+import { Form } from 'react-bootstrap';
+import { withTranslation } from 'react-i18next';
+
+import i18n from '../../i18n';
+
+const ALTTPR_CODES = [
+       'big-key',
+       'bow',
+       'blue-boomerang',
+       'bomb',
+       'bombos',
+       'book',
+       'boots',
+       'bottle',
+       'bow',
+       'bugnet',
+       'cape',
+       'compass',
+       'ether',
+       'flippers',
+       'flute',
+       'glove',
+       'green-mail',
+       'green-pendant',
+       'green-potion',
+       'hammer',
+       'heart-container',
+       'hookshot',
+       'ice-rod',
+       'lamp',
+       'map',
+       'mirror',
+       'mirror-shield',
+       'moonpearl',
+       'mushroom',
+       'powder',
+       'quake',
+       'shovel',
+];
+
+const SMR_CODES = [
+       'ALCOON',
+       'ATOMIC',
+       'BEETOM',
+       'BOYON',
+       'BULL',
+       'CHOOT',
+       'COVERN',
+       'EVIR',
+       'FUNE',
+       'GAMET',
+       'GEEMER',
+       'GERUTA',
+       'HOLTZ',
+       'KAGO',
+       'NAMIHE',
+       'OUM',
+       'OWTCH',
+       'POWAMP',
+       'PUROMI',
+       'PUYO',
+       'RINKA',
+       'RIPPER',
+       'SCISER',
+       'SKREE',
+       'SOVA',
+       'TATORI',
+       'VIOLA',
+       'WAVER',
+       'YARD',
+       'ZEBBO',
+       'ZEELA',
+       'ZOA',
+];
+
+const SeedCodeInput = ({
+       className,
+       game,
+       name,
+       onBlur,
+       onChange,
+       value,
+}) => {
+       if (game === 'alttpr') {
+               const code_trans = ALTTPR_CODES
+                       .map(code => ({ code, label: i18n.t(`icon.zelda.${code}`)}))
+                       .sort((a, b) => a.label.localeCompare(b.label));
+               return <div
+                       className={`${className} seed-code-input-alttpr`}
+               >
+                       {[0, 1, 2, 3, 4].map(num =>
+                               <Form.Select
+                                       key={num}
+                                       onBlur={onBlur}
+                                       onChange={onChange}
+                                       name={`${name}[${num}]`}
+                                       value={(value && value[num]) || ''}
+                               >
+                                       <option value=""></option>
+                                       {code_trans.map(({ code, label }) =>
+                                               <option key={code} value={code}>{label}</option>
+                                       )}
+                               </Form.Select>
+                       )}
+               </div>;
+       }
+       if (game === 'smr') {
+               return <div
+                       className={`${className} seed-code-input-smr`}
+               >
+                       {[0, 1, 2, 3].map(num =>
+                               <Form.Select
+                                       key={num}
+                                       onBlur={onBlur}
+                                       onChange={onChange}
+                                       name={`${name}[${num}]`}
+                                       value={(value && value[num]) || ''}
+                               >
+                                       <option value=""></option>
+                                       {SMR_CODES.sort((a, b) => a.localeCompare(b)).map(code =>
+                                               <option key={code} value={code}>{code}</option>
+                                       )}
+                               </Form.Select>
+                       )}
+               </div>;
+       }
+       return <div
+               className={`${className} seed-code-input-default`}
+       >
+               {[0, 1, 2, 3, 4].map(num =>
+                       <Form.Control
+                               key={num}
+                               onBlur={onBlur}
+                               onChange={onChange}
+                               name={`${name}[${num}]`}
+                               value={(value && value[num]) || ''}
+                       />
+               )}
+       </div>;
+};
+
+SeedCodeInput.propTypes = {
+       className: PropTypes.string,
+       game: PropTypes.string,
+       name: PropTypes.string,
+       onBlur: PropTypes.func,
+       onChange: PropTypes.func,
+       value: PropTypes.arrayOf(PropTypes.string),
+};
+
+SeedCodeInput.defaultProps = {
+       className: '',
+       game: '',
+       name: '',
+       onBlur: null,
+       onChange: null,
+       value: [],
+};
+
+export default withTranslation()(SeedCodeInput);
index 97958d6fceb480040012af05551a9c6dee3e06b4..4af252dcd5c47c390bf8d6e8de1d8ad9c563acfd 100644 (file)
@@ -425,6 +425,7 @@ export default {
                        time: 'Zeit: {{ time }}',
                },
                rounds: {
                        time: 'Zeit: {{ time }}',
                },
                rounds: {
+                       code: 'Code',
                        date: '{{ date, L }}',
                        edit: 'Runde bearbeiten',
                        editError: 'Fehler beim Speichern',
                        date: '{{ date, L }}',
                        edit: 'Runde bearbeiten',
                        editError: 'Fehler beim Speichern',
index e7e0c59d58c06cbc198051abf1f616a8552ea8fe..9944fd7685902ac2381ba022797b1ff259a099f5 100644 (file)
@@ -425,6 +425,7 @@ export default {
                        time: 'Time: {{ time }}',
                },
                rounds: {
                        time: 'Time: {{ time }}',
                },
                rounds: {
+                       code: 'Code',
                        date: '{{ date, L }}',
                        edit: 'Edit round',
                        editError: 'Error saving round',
                        date: '{{ date, L }}',
                        edit: 'Edit round',
                        editError: 'Error saving round',