From 7dbb5572dc613186d45fd08275cac81249af06aa Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Mon, 27 Mar 2023 15:13:01 +0200 Subject: [PATCH] add spoiler support --- app/Http/Controllers/RoundController.php | 2 ++ .../2023_03_23_202024_add_round_spoiler.php | 32 +++++++++++++++++++ resources/js/components/rounds/EditForm.js | 23 +++++++++++++ resources/js/components/rounds/SeedButton.js | 15 +++++++-- resources/js/i18n/de.js | 1 + resources/js/i18n/en.js | 1 + 6 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 database/migrations/2023_03_23_202024_add_round_spoiler.php diff --git a/app/Http/Controllers/RoundController.php b/app/Http/Controllers/RoundController.php index 6d31e90..8ec2b84 100644 --- a/app/Http/Controllers/RoundController.php +++ b/app/Http/Controllers/RoundController.php @@ -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 index 0000000..8d13ab2 --- /dev/null +++ b/database/migrations/2023_03_23_202024_add_round_spoiler.php @@ -0,0 +1,32 @@ +string('spoiler')->default(''); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('rounds', function(Blueprint $table) { + $table->dropColumn('spoiler'); + }); + } +}; diff --git a/resources/js/components/rounds/EditForm.js b/resources/js/components/rounds/EditForm.js index 623e1fb..ac2cd42 100644 --- a/resources/js/components/rounds/EditForm.js +++ b/resources/js/components/rounds/EditForm.js @@ -59,6 +59,24 @@ const EditForm = ({ : null} + + + {i18n.t('rounds.spoiler')} + + {touched.spoiler && errors.spoiler ? + + {i18n.t(errors.spoiler)} + + : null} + + {i18n.t('rounds.code')} @@ -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)); diff --git a/resources/js/components/rounds/SeedButton.js b/resources/js/components/rounds/SeedButton.js index d9d3433..71299cc 100644 --- a/resources/js/components/rounds/SeedButton.js +++ b/resources/js/components/rounds/SeedButton.js @@ -12,11 +12,21 @@ const SeedButton = ({ round, tournament, user }) => { const [showDialog, setShowDialog] = useState(false); if (round.seed) { - return ( + return <> - ); + {round.spoiler ? + + : 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({ }), diff --git a/resources/js/i18n/de.js b/resources/js/i18n/de.js index e5534e3..d8cf861 100644 --- a/resources/js/i18n/de.js +++ b/resources/js/i18n/de.js @@ -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.', diff --git a/resources/js/i18n/en.js b/resources/js/i18n/en.js index 4d8a899..d143eb0 100644 --- a/resources/js/i18n/en.js +++ b/resources/js/i18n/en.js @@ -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.', -- 2.39.2