mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2024-05-17 04:12:40 +00:00
338633ce72
They can prevent tree shaking
57 lines
1.8 KiB
TypeScript
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)
|
|
})
|
|
}
|
|
}
|