]> git.localhorst.tv Git - alttp.git/commitdiff
add spoiler support
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 27 Mar 2023 13:13:01 +0000 (15:13 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Mon, 27 Mar 2023 13:13:01 +0000 (15:13 +0200)
app/Http/Controllers/RoundController.php
database/migrations/2023_03_23_202024_add_round_spoiler.php [new file with mode: 0644]
resources/js/components/rounds/EditForm.js
resources/js/components/rounds/SeedButton.js
resources/js/i18n/de.js
resources/js/i18n/en.js

index 6d31e9020897ee8968d7b2ce5040197a68368b86..8ec2b84d010eb7519f4e1da796b2e7717e8d1e01 100644 (file)
@@ -47,12 +47,14 @@ class RoundController extends Controller
                        'code.*' => 'string',
                        'rolled_by' => 'nullable|exists:App\\Models\\User,id',
                        'seed' => 'url',
+                       'spoiler' => 'url',
                        'title' => 'string',
                ]);
 
                $round->code = array_filter($validatedData['code']);
                $round->rolled_by = $validatedData['rolled_by'];
                $round->seed = $validatedData['seed'];
+               $round->spoiler = $validatedData['spoiler'];
                $round->title = $validatedData['title'];
                $round->update();
 
diff --git a/database/migrations/2023_03_23_202024_add_round_spoiler.php b/database/migrations/2023_03_23_202024_add_round_spoiler.php
new file mode 100644 (file)
index 0000000..8d13ab2
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+       /**
+        * Run the migrations.
+        *
+        * @return void
+        */
+       public function up()
+       {
+               Schema::table('rounds', function(Blueprint $table) {
+                       $table->string('spoiler')->default('');
+               });
+       }
+
+       /**
+        * Reverse the migrations.
+        *
+        * @return void
+        */
+       public function down()
+       {
+               Schema::table('rounds', function(Blueprint $table) {
+                       $table->dropColumn('spoiler');
+               });
+       }
+};
index 623e1fb4bb4d8c1c6e29739181bf3e44aab83d65..ac2cd427628217a14f29478570c9d8dd1793c952 100644 (file)
@@ -59,6 +59,24 @@ const EditForm = ({
                                : null}
                        </Form.Group>
                </Row>
+               <Row>
+                       <Form.Group as={Col} controlId="round.spoiler">
+                               <Form.Label>{i18n.t('rounds.spoiler')}</Form.Label>
+                               <Form.Control
+                                       isInvalid={!!(touched.spoiler && errors.spoiler)}
+                                       name="spoiler"
+                                       onBlur={handleBlur}
+                                       onChange={handleChange}
+                                       type="text"
+                                       value={values.spoiler || ''}
+                               />
+                               {touched.spoiler && errors.spoiler ?
+                                       <Form.Control.Feedback type="invalid">
+                                               {i18n.t(errors.spoiler)}
+                                       </Form.Control.Feedback>
+                               : null}
+                       </Form.Group>
+               </Row>
                <Row>
                        <Form.Group as={Col}>
                                <Form.Label>{i18n.t('rounds.code')}</Form.Label>
@@ -114,6 +132,7 @@ EditForm.propTypes = {
                code: PropTypes.arrayOf(PropTypes.string),
                rolled_by: PropTypes.string,
                seed: PropTypes.string,
+               spoiler: PropTypes.string,
                title: PropTypes.string,
        }),
        handleBlur: PropTypes.func,
@@ -124,6 +143,7 @@ EditForm.propTypes = {
                code: PropTypes.arrayOf(PropTypes.bool),
                rolled_by: PropTypes.bool,
                seed: PropTypes.bool,
+               spoiler: PropTypes.bool,
                title: PropTypes.bool,
        }),
        values: PropTypes.shape({
@@ -131,6 +151,7 @@ EditForm.propTypes = {
                game: PropTypes.string,
                rolled_by: PropTypes.string,
                seed: PropTypes.string,
+               spoiler: PropTypes.string,
                title: PropTypes.string,
        }),
 };
@@ -161,12 +182,14 @@ export default withFormik({
                rolled_by: round.rolled_by || null,
                round_id: round.id,
                seed: round.seed || '',
+               spoiler: round.spoiler || '',
                title: round.title || '',
        }),
        validationSchema: yup.object().shape({
                code: yup.array().of(yup.string()),
                rolled_by: yup.string().nullable(),
                seed: yup.string().url(),
+               spoiler: yup.string().url(),
                title: yup.string(),
        }),
 })(withTranslation()(EditForm));
index d9d343304eca067fc7996fa72c940f187a85badc..71299cc7b84c0036b30da90cc3422f7b477ad4df 100644 (file)
@@ -12,11 +12,21 @@ const SeedButton = ({ round, tournament, user }) => {
        const [showDialog, setShowDialog] = useState(false);
 
        if (round.seed) {
-               return (
+               return <>
                        <Button href={round.seed} target="_blank" variant="primary">
                                {i18n.t('rounds.seed')}
                        </Button>
-               );
+                       {round.spoiler ?
+                               <Button
+                                       className="ms-2"
+                                       href={round.spoiler}
+                                       target="_blank"
+                                       variant="outline-primary"
+                               >
+                                       {i18n.t('rounds.spoiler')}
+                               </Button>
+                       : null}
+               </>;
        }
        if (maySetSeed(user, tournament, round)) {
                return <>
@@ -36,6 +46,7 @@ const SeedButton = ({ round, tournament, user }) => {
 SeedButton.propTypes = {
        round: PropTypes.shape({
                seed: PropTypes.string,
+               spoiler: PropTypes.string,
        }),
        tournament: PropTypes.shape({
        }),
index e5534e381ef62fe3349c6e27c20237cb2cd05339..d8cf86134cadbdcf336c46b57883ea1c545e87b4 100644 (file)
@@ -543,6 +543,7 @@ export default {
                        setSeed: 'Seed eintragen',
                        setSeedError: 'Seed konnte nicht eintragen werden',
                        setSeedSuccess: 'Seed eingetragen',
+                       spoiler: 'Spoiler',
                        title: 'Titel',
                        unlock: 'Runde entsperren',
                        unlockDescription: 'Die Runde wird wieder freigegeben und Runner können wieder Änderungen an ihrem Ergebnis vornehmen.',
index 4d8a8992852c58a836ae1904d57fb8e4eb8bd4a6..d143eb0afbdc2f589ab26e0aad0f6b10b140cbf9 100644 (file)
@@ -543,6 +543,7 @@ export default {
                        setSeed: 'Set seed',
                        setSeedError: 'Seed could not be set',
                        setSeedSuccess: 'Seed set',
+                       spoiler: 'Spoiler',
                        title: 'Title',
                        unlock: 'Unock round',
                        unlockDescription: 'The round is unlocked and runers are free to submit or change their results again.',