unoffical wafrn mirror wafrn.net
atproto social-network activitypub
at angular21 43 lines 1.4 kB view raw
1import { Component, effect, output, signal, inject } from '@angular/core' 2import { MatButtonModule } from '@angular/material/button' 3import { MatProgressSpinnerModule } from '@angular/material/progress-spinner' 4import { FontAwesomeModule } from '@fortawesome/angular-fontawesome' 5import { faImage, faUpload } from '@fortawesome/free-solid-svg-icons' 6import { SettingsService } from '../services/settings.service' 7 8// yes, I am rewriting file-upload just so it can have text and emit a different type 9 10@Component({ 11 selector: 'app-select-image-button', 12 imports: [MatButtonModule, MatProgressSpinnerModule, FontAwesomeModule], 13 templateUrl: './select-image-button.component.html', 14 styleUrl: './select-image-button.component.scss' 15}) 16export class SelectImageButtonComponent { 17 fileEvent = output<File>() 18 fileSelected = signal(false) 19 20 setIcon = faImage 21 uploadIcon = faUpload 22 fileName = '' 23 24 constructor() { 25 const settingsService = inject(SettingsService); 26 27 effect(() => { 28 if (!settingsService.settingsModified()) { 29 this.fileSelected.set(false) 30 } 31 }) 32 } 33 34 selectImage(event: Event) { 35 const elem = event.target as HTMLInputElement 36 if (elem.files === null || elem.files.length === 0) return 37 38 const file = elem.files[0] 39 this.fileEvent.emit(file) 40 this.fileSelected.set(true) 41 this.fileName = file.name 42 } 43}