forked from maybe-finance/maybe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/profile image uploads (maybe-finance#687)
* Introduce ActiveStorage * Add active storage related service gems * Update storage.yml * Install image processing gem - sudo apt-get install libvips (required dependency) * Set default active storage service * Add profile image to user model * Amend form to allow profile images to be saved, introduce stimulus controller. * Purge image when form is blank * Update markup/stimulus controller * Add test for profile image uplaods * Add profile image validation * Use rails guide gem versions * Use correct ERB syntax and make all storage options configurable * Ensure form submits when user clears profile image * Add profile image thumbnail method * Extract profile image to a partial * Updates env.example and storage.yml * Fix bug with double form save * Add profile image to the sidenav * Update production config * Fix ERB formatting * normalize en.yml * Handle non-square images * Use pre-processing on thumbnail variant * Resovle gemfile.lock issues * Rubocop style changes --------- Signed-off-by: Christian <[email protected]> Co-authored-by: Christian Robinson <[email protected]>
- Loading branch information
Showing
17 changed files
with
349 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,3 +50,6 @@ | |
|
||
# Ignore .devcontainer files | ||
compose-dev.yaml | ||
|
||
# Ignore GCP keyfile | ||
gcp-storage-keyfile.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
app/javascript/controllers/profile_image_preview_controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
|
||
export default class extends Controller { | ||
static targets = ["imagePreview", "fileField", "deleteField", "clearBtn", "template"] | ||
|
||
preview(event) { | ||
const file = event.target.files[0]; | ||
if (file) { | ||
const reader = new FileReader(); | ||
reader.onload = (e) => { | ||
this.imagePreviewTarget.innerHTML = `<img src="${e.target.result}" alt="Preview" class="w-24 h-24 rounded-full object-cover" />`; | ||
this.templateTarget.classList.add("hidden"); | ||
this.clearBtnTarget.classList.remove("hidden"); | ||
}; | ||
reader.readAsDataURL(file); | ||
} | ||
} | ||
|
||
clear() { | ||
this.deleteFieldTarget.value = true; | ||
this.fileFieldTarget.value = null; | ||
this.templateTarget.classList.remove("hidden"); | ||
this.imagePreviewTarget.innerHTML = this.templateTarget.innerHTML; | ||
this.clearBtnTarget.classList.add("hidden"); | ||
this.element.submit(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.