From 671cf4a755266674d92da4576781183c3caaf785 Mon Sep 17 00:00:00 2001 From: Betsy Castro <5490820+betsyecastro@users.noreply.github.com> Date: Mon, 11 Nov 2024 16:48:52 -0600 Subject: [PATCH 01/11] Adds method to submit form after selecting an image for upload Automatically submit form after image selection, eliminating the need to manually click 'Replace Image' --- public/js/app.js | 14 +++++++++++++- public/mix-manifest.json | 2 +- resources/assets/js/app.js | 16 +++++++++++++++- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/public/js/app.js b/public/js/app.js index 8b9b4d0a..fead4a92 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -84,6 +84,16 @@ var profiles = function ($, undefined) { $(file_input).siblings('.invalid-feedback').removeClass('d-block'); }; + /** + * Submits img update + * + * @param {Event} event the triggered event + */ + var submit_img_update = function submit_img_update(event) { + var file_input = event.target; + $(file_input).closest('form').submit(); + }; + /** * Reindex numbers in field ids, names, and labels to match sort order, * e.g. if the first item's name is "thing[3]", rename it to "thing[0]" @@ -610,6 +620,7 @@ var profiles = function ($, undefined) { deobfuscate_mail_links: deobfuscate_mail_links, on_list_updated: on_list_updated, preview_selected_image: preview_selected_image, + submit_img_update: submit_img_update, replace_icon: replace_icon, registerTagEditors: registerTagEditors, registerProfilePickers: registerProfilePickers, @@ -629,7 +640,8 @@ $(function () { //show preview of uploaded image $('input[type="file"]').on('change', function (e) { - return profiles.preview_selected_image(e); + profiles.preview_selected_image(e); + profiles.submit_img_update(e); }); // enable drag and drop sorting for items with sortable class diff --git a/public/mix-manifest.json b/public/mix-manifest.json index de5f1463..b550576d 100644 --- a/public/mix-manifest.json +++ b/public/mix-manifest.json @@ -1,5 +1,5 @@ { - "/js/app.js": "/js/app.js?id=24be537863fbbe2259218dfb56ecef72", + "/js/app.js": "/js/app.js?id=d764e6cb74d3a3a53a24d6b53f91e9c0", "/js/manifest.js": "/js/manifest.js?id=dc9ead3d7857b522d7de22d75063453c", "/css/app.css": "/css/app.css?id=bff46e69abe7a97b008296b99e4abadd", "/js/vendor.js": "/js/vendor.js?id=4d3313683b3a2faf8ca0278ce47f3880" diff --git a/resources/assets/js/app.js b/resources/assets/js/app.js index c187b44f..e69e522c 100644 --- a/resources/assets/js/app.js +++ b/resources/assets/js/app.js @@ -74,6 +74,16 @@ var profiles = (function ($, undefined) { $(file_input).siblings('.invalid-feedback').removeClass('d-block'); }; + /** + * Submits img update + * + * @param {Event} event the triggered event + */ + const submit_img_update = function (event) { + const file_input = event.target; + $(file_input).closest('form').submit(); + }; + /** * Reindex numbers in field ids, names, and labels to match sort order, * e.g. if the first item's name is "thing[3]", rename it to "thing[0]" @@ -547,6 +557,7 @@ var profiles = (function ($, undefined) { deobfuscate_mail_links: deobfuscate_mail_links, on_list_updated: on_list_updated, preview_selected_image: preview_selected_image, + submit_img_update : submit_img_update, replace_icon: replace_icon, registerTagEditors: registerTagEditors, registerProfilePickers: registerProfilePickers, @@ -569,7 +580,10 @@ $(function() { $('.datepicker.month').datepicker(profiles.config.datepicker.month); //show preview of uploaded image - $('input[type="file"]').on('change', (e) => profiles.preview_selected_image(e)); + $('input[type="file"]').on('change', function(e) { + profiles.preview_selected_image(e); + profiles.submit_img_update(e); + }); // enable drag and drop sorting for items with sortable class if ($('.sortable').length > 0) { From 5a62b1be0ad620ff89f252e34ab404a4c6f2f4a6 Mon Sep 17 00:00:00 2001 From: Betsy Castro <5490820+betsyecastro@users.noreply.github.com> Date: Tue, 19 Nov 2024 10:30:36 -0600 Subject: [PATCH 02/11] =?UTF-8?q?=F0=9F=9A=B8=20Refactor=20profile=20pictu?= =?UTF-8?q?re=20upload=20process=20to=20use=20a=20Livewire=20component?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/ProfilesController.php | 2 +- .../Livewire/ProfilePictureEditorModal.php | 40 +++++++++++++++++++ public/js/app.js | 12 ------ public/mix-manifest.json | 2 +- resources/assets/js/app.js | 12 ------ .../profile-picture-editor-modal.blade.php | 36 +++++++++++++++++ .../views/profiles/edit/information.blade.php | 22 +++------- resources/views/profiles/show.blade.php | 4 ++ 8 files changed, 87 insertions(+), 43 deletions(-) create mode 100644 app/Http/Livewire/ProfilePictureEditorModal.php create mode 100644 resources/views/livewire/profile-picture-editor-modal.blade.php diff --git a/app/Http/Controllers/ProfilesController.php b/app/Http/Controllers/ProfilesController.php index 34caee05..768043dd 100644 --- a/app/Http/Controllers/ProfilesController.php +++ b/app/Http/Controllers/ProfilesController.php @@ -272,7 +272,7 @@ public function update(Profile $profile, string $section, ProfileUpdateRequest $ public function updateImage(Profile $profile, ProfileImageRequest $request): RedirectResponse { - return redirect()->route('profiles.edit', [$profile->slug, 'information'])->with('flash_message', $profile->processImage($request->file('image'), 'images')); + return redirect()->route('profiles.show', [$profile->slug, 'information'])->with('flash_message', $profile->processImage($request->file('image'), 'images')); } /** diff --git a/app/Http/Livewire/ProfilePictureEditorModal.php b/app/Http/Livewire/ProfilePictureEditorModal.php new file mode 100644 index 00000000..3f08f052 --- /dev/null +++ b/app/Http/Livewire/ProfilePictureEditorModal.php @@ -0,0 +1,40 @@ +user = auth()->user(); + } + + public function updatedImage() + { + $this->validate([ + 'image' => $this->uploadedImageRules(), + ]); + } + + public function submit() + { + $msg = $this->profile->processImage($this->image); + return redirect(route('profiles.show', $this->profile))->with('flash_message', $msg, 'images'); + } + + public function render() + { + return view('livewire.profile-picture-editor-modal'); + } +} diff --git a/public/js/app.js b/public/js/app.js index fead4a92..e35ff256 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -84,16 +84,6 @@ var profiles = function ($, undefined) { $(file_input).siblings('.invalid-feedback').removeClass('d-block'); }; - /** - * Submits img update - * - * @param {Event} event the triggered event - */ - var submit_img_update = function submit_img_update(event) { - var file_input = event.target; - $(file_input).closest('form').submit(); - }; - /** * Reindex numbers in field ids, names, and labels to match sort order, * e.g. if the first item's name is "thing[3]", rename it to "thing[0]" @@ -620,7 +610,6 @@ var profiles = function ($, undefined) { deobfuscate_mail_links: deobfuscate_mail_links, on_list_updated: on_list_updated, preview_selected_image: preview_selected_image, - submit_img_update: submit_img_update, replace_icon: replace_icon, registerTagEditors: registerTagEditors, registerProfilePickers: registerProfilePickers, @@ -641,7 +630,6 @@ $(function () { //show preview of uploaded image $('input[type="file"]').on('change', function (e) { profiles.preview_selected_image(e); - profiles.submit_img_update(e); }); // enable drag and drop sorting for items with sortable class diff --git a/public/mix-manifest.json b/public/mix-manifest.json index b550576d..4fada57e 100644 --- a/public/mix-manifest.json +++ b/public/mix-manifest.json @@ -1,5 +1,5 @@ { - "/js/app.js": "/js/app.js?id=d764e6cb74d3a3a53a24d6b53f91e9c0", + "/js/app.js": "/js/app.js?id=f1170fe3e2888e47851541584fd2b3e9", "/js/manifest.js": "/js/manifest.js?id=dc9ead3d7857b522d7de22d75063453c", "/css/app.css": "/css/app.css?id=bff46e69abe7a97b008296b99e4abadd", "/js/vendor.js": "/js/vendor.js?id=4d3313683b3a2faf8ca0278ce47f3880" diff --git a/resources/assets/js/app.js b/resources/assets/js/app.js index e69e522c..bbaca78e 100644 --- a/resources/assets/js/app.js +++ b/resources/assets/js/app.js @@ -74,16 +74,6 @@ var profiles = (function ($, undefined) { $(file_input).siblings('.invalid-feedback').removeClass('d-block'); }; - /** - * Submits img update - * - * @param {Event} event the triggered event - */ - const submit_img_update = function (event) { - const file_input = event.target; - $(file_input).closest('form').submit(); - }; - /** * Reindex numbers in field ids, names, and labels to match sort order, * e.g. if the first item's name is "thing[3]", rename it to "thing[0]" @@ -557,7 +547,6 @@ var profiles = (function ($, undefined) { deobfuscate_mail_links: deobfuscate_mail_links, on_list_updated: on_list_updated, preview_selected_image: preview_selected_image, - submit_img_update : submit_img_update, replace_icon: replace_icon, registerTagEditors: registerTagEditors, registerProfilePickers: registerProfilePickers, @@ -582,7 +571,6 @@ $(function() { //show preview of uploaded image $('input[type="file"]').on('change', function(e) { profiles.preview_selected_image(e); - profiles.submit_img_update(e); }); // enable drag and drop sorting for items with sortable class diff --git a/resources/views/livewire/profile-picture-editor-modal.blade.php b/resources/views/livewire/profile-picture-editor-modal.blade.php new file mode 100644 index 00000000..f8468b8a --- /dev/null +++ b/resources/views/livewire/profile-picture-editor-modal.blade.php @@ -0,0 +1,36 @@ +