mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-20 13:49:39 +02:00
* 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 <47796704+crobbo@users.noreply.github.com> Co-authored-by: Christian Robinson <christian@robbo.dev>
27 lines
923 B
JavaScript
27 lines
923 B
JavaScript
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();
|
|
}
|
|
}
|