refactor: extend base settings add class to edit

This commit is contained in:
2026-02-17 01:36:12 -03:00
parent 736a658323
commit 3c87de3d51
6 changed files with 29 additions and 21 deletions

View File

@@ -5,7 +5,7 @@ import { ActionBtn } from '../action-btn/action-btn';
import { TranslatePipe } from '@ngx-translate/core'; import { TranslatePipe } from '@ngx-translate/core';
import { UpperfirstPipe } from '../../pipes/upperfirst-pipe'; import { UpperfirstPipe } from '../../pipes/upperfirst-pipe';
import { ChainSettings } from '../../services/chain-settings'; import { ChainSettings } from '../../services/chain-settings';
import { SettingsBaseAdd } from '../settings-base-add/settings-base-add'; import { SettingsBaseAddEdit } from '../settings-base-add-edit/settings-base-add-edit';
@Component({ @Component({
selector: 'app-chain-add', selector: 'app-chain-add',
@@ -14,15 +14,17 @@ import { SettingsBaseAdd } from '../settings-base-add/settings-base-add';
TranslatePipe, TranslatePipe,
UpperfirstPipe, UpperfirstPipe,
], ],
templateUrl: './../settings-base-add/settings-base-add.html', templateUrl: './../settings-base-add-edit/settings-base-add-edit.html',
styleUrl: './../settings-base-add/settings-base-add.scss', styleUrl: './../settings-base-add-edit/settings-base-add-edit.scss',
}) })
export class ChainAdd extends SettingsBaseAdd { export class ChainAdd extends SettingsBaseAddEdit {
private readonly chainSettings = inject(ChainSettings); private readonly chainSettings = inject(ChainSettings);
readonly form = new ChainFormGroup(); readonly form = new ChainFormGroup();
btnText = 'common.save';
title = 'settings.chain.new_chain'; title = 'settings.chain.new_chain';
async save() { async submit() {
const name = this.form.controls.name.value; const name = this.form.controls.name.value;
const img = this.form.controls.image.value; const img = this.form.controls.image.value;
//TODO: the sqlite bridge can't handle null as param //TODO: the sqlite bridge can't handle null as param

View File

@@ -0,0 +1,9 @@
<h3>{{title|translate|upperfirst}}</h3>
<ng-content></ng-content>
<app-action-btn
(click)="submit()"
(keydown)="submit()"
[disabled]="this.disabled"
class="top-auto"
text="{{btnText|translate|upperfirst}}"
/>

View File

@@ -0,0 +1,13 @@
import { FormGroup } from '@angular/forms';
export abstract class SettingsBaseAddEdit {
abstract btnText: string;
abstract title: string;
abstract form: FormGroup;
protected abstract submit(): Promise<void>
get disabled() {
return this.form.invalid || this.form.pristine;
}
}

View File

@@ -1,8 +0,0 @@
<h3>{{title|translate|upperfirst}}</h3>
<ng-content></ng-content>
<app-action-btn
(click)="save()"
[disabled]="this.form.invalid"
class="top-auto"
text="{{'common.save'|translate|upperfirst}}"
/>

View File

@@ -1,8 +0,0 @@
import { FormGroup } from '@angular/forms';
export abstract class SettingsBaseAdd {
abstract title: string;
abstract form: FormGroup;
protected abstract save(): Promise<void>
}