update dependencies, migrate subscribe, add submit type to buttons
This commit is contained in:
@@ -8,7 +8,7 @@ import { Subscription } from 'rxjs';
|
||||
@Component({
|
||||
selector: 'page-settings',
|
||||
templateUrl: './settings.page.html',
|
||||
styleUrls: [ './settings.page.scss' ]
|
||||
styleUrls: ['./settings.page.scss']
|
||||
})
|
||||
export class PageSettings implements OnInit, OnDestroy {
|
||||
|
||||
@@ -27,33 +27,37 @@ export class PageSettings implements OnInit, OnDestroy {
|
||||
|
||||
ngOnInit(): void {
|
||||
this.form = this.formBuilder.group({
|
||||
username: [ { disabled: true }, Validators.nullValidator ],
|
||||
email: [ '', Validators.nullValidator ],
|
||||
about: [ '', Validators.nullValidator ],
|
||||
gravity: [ '', Validators.nullValidator ],
|
||||
entryDelay: [ '', Validators.nullValidator ],
|
||||
commentDelay: [ '', Validators.nullValidator ],
|
||||
pageSize: [ '', Validators.nullValidator ],
|
||||
username: [{ disabled: true }, Validators.nullValidator],
|
||||
email: ['', Validators.nullValidator],
|
||||
about: ['', Validators.nullValidator],
|
||||
gravity: ['', Validators.nullValidator],
|
||||
entryDelay: ['', Validators.nullValidator],
|
||||
commentDelay: ['', Validators.nullValidator],
|
||||
pageSize: ['', Validators.nullValidator],
|
||||
});
|
||||
|
||||
this.form.get('username').disable();
|
||||
|
||||
this.userService.get().subscribe(user => {
|
||||
this.user = user;
|
||||
if (!this.user.settings) {
|
||||
this.user.settings = {};
|
||||
}
|
||||
this.form.get('username').setValue(this.user.username);
|
||||
this.form.get('email').setValue(this.user.email);
|
||||
this.form.get('about').setValue(this.user.about);
|
||||
this.userService.get().subscribe({
|
||||
next: (user) => {
|
||||
this.user = user;
|
||||
if (!this.user.settings) {
|
||||
this.user.settings = {};
|
||||
}
|
||||
this.form.get('username').setValue(this.user.username);
|
||||
this.form.get('email').setValue(this.user.email);
|
||||
this.form.get('about').setValue(this.user.about);
|
||||
|
||||
this.settingsSubscription = this.settingsService.settings.subscribe((settings) => {
|
||||
this.settings = settings;
|
||||
this.form.get('gravity').setValue(this.user.settings.gravity || this.settings.defaultGravity);
|
||||
this.form.get('entryDelay').setValue(this.user.settings.entryDelay || this.settings.defaultEntryDelay);
|
||||
this.form.get('commentDelay').setValue(this.user.settings.commentDelay || this.settings.defaultCommentDelay);
|
||||
this.form.get('pageSize').setValue(this.user.settings.pageSize || this.settings.defaultPageSize);
|
||||
});
|
||||
this.settingsSubscription = this.settingsService.settings.subscribe({
|
||||
next: (settings) => {
|
||||
this.settings = settings;
|
||||
this.form.get('gravity').setValue(this.user.settings.gravity || this.settings.defaultGravity);
|
||||
this.form.get('entryDelay').setValue(this.user.settings.entryDelay || this.settings.defaultEntryDelay);
|
||||
this.form.get('commentDelay').setValue(this.user.settings.commentDelay || this.settings.defaultCommentDelay);
|
||||
this.form.get('pageSize').setValue(this.user.settings.pageSize || this.settings.defaultPageSize);
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -62,7 +66,7 @@ export class PageSettings implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
hasError(controlName: string): boolean {
|
||||
return this.form.controls[ controlName ].errors != null;
|
||||
return this.form.controls[controlName].errors != null;
|
||||
}
|
||||
|
||||
resetGravity(): void {
|
||||
@@ -124,25 +128,28 @@ export class PageSettings implements OnInit, OnDestroy {
|
||||
this.user.settings.pageSize = this.form.get('pageSize').value;
|
||||
}
|
||||
|
||||
this.userService.update(this.user).subscribe((data) => {
|
||||
this.user = data;
|
||||
if (!this.user.settings) {
|
||||
this.user.settings = {};
|
||||
}
|
||||
this.working = false;
|
||||
this.success = true;
|
||||
this.settingsService.getSettings();
|
||||
}, (error) => {
|
||||
this.working = false;
|
||||
if (error.status == 422) {
|
||||
let errors = {};
|
||||
for (let code of error.error) {
|
||||
errors[ code.field ] = errors[ code.field ] || {};
|
||||
errors[ code.field ][ code.code ] = true;
|
||||
this.userService.update(this.user).subscribe({
|
||||
next: (data) => {
|
||||
this.user = data;
|
||||
if (!this.user.settings) {
|
||||
this.user.settings = {};
|
||||
}
|
||||
this.working = false;
|
||||
this.success = true;
|
||||
this.settingsService.getSettings();
|
||||
},
|
||||
error: (error) => {
|
||||
this.working = false;
|
||||
if (error.status == 422) {
|
||||
let errors = {};
|
||||
for (let code of error.error) {
|
||||
errors[code.field] = errors[code.field] || {};
|
||||
errors[code.field][code.code] = true;
|
||||
}
|
||||
|
||||
for (let code in errors) {
|
||||
this.form.get(code).setErrors(errors[ code ]);
|
||||
for (let code in errors) {
|
||||
this.form.get(code).setErrors(errors[code]);
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user