PeerTube/client/src/app/+my-account/my-account-settings/my-account-email-preferences/my-account-email-preferences.component.ts
Chocobozzz 338633ce72
Remove barrels
They can prevent tree shaking
2024-03-05 10:52:32 +01:00

57 lines
1.8 KiB
TypeScript

import { Subject } from 'rxjs'
import { Component, Input, OnInit } from '@angular/core'
import { Notifier, UserService } from '@app/core'
import { FormReactive } from '@app/shared/shared-forms/form-reactive'
import { FormReactiveService } from '@app/shared/shared-forms/form-reactive.service'
import { User, UserUpdateMe } from '@peertube/peertube-models'
import { PeertubeCheckboxComponent } from '../../../shared/shared-forms/peertube-checkbox.component'
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
@Component({
selector: 'my-account-email-preferences',
templateUrl: './my-account-email-preferences.component.html',
styleUrls: [ './my-account-email-preferences.component.scss' ],
standalone: true,
imports: [ FormsModule, ReactiveFormsModule, PeertubeCheckboxComponent ]
})
export class MyAccountEmailPreferencesComponent extends FormReactive implements OnInit {
@Input() user: User = null
@Input() userInformationLoaded: Subject<any>
constructor (
protected formReactiveService: FormReactiveService,
private userService: UserService,
private notifier: Notifier
) {
super()
}
ngOnInit () {
this.buildForm({
'email-public': null
})
this.userInformationLoaded.subscribe(() => {
this.form.patchValue({ 'email-public': this.user.emailPublic })
})
}
updateEmailPublic () {
const details: UserUpdateMe = {
emailPublic: this.form.value['email-public']
}
this.userService.updateMyProfile(details)
.subscribe({
next: () => {
if (details.emailPublic) this.notifier.success($localize`Email is now public`)
else this.notifier.success($localize`Email is now private`)
this.user.emailPublic = details.emailPublic
},
error: err => this.notifier.error(err.message)
})
}
}