fasd
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
<mat-dialog-content>
|
<mat-dialog-content>
|
||||||
<mat-tab-group>
|
<mat-tab-group>
|
||||||
@for (item of list | async; track item.id) {
|
@for (item of list(); track item.id) {
|
||||||
<mat-tab>
|
<mat-tab>
|
||||||
<ng-template matTabLabel>
|
<ng-template matTabLabel>
|
||||||
<span>{{ item.name }}</span>
|
<span>{{ item.name }}</span>
|
||||||
@@ -19,8 +19,8 @@
|
|||||||
class="flex-col square-button"
|
class="flex-col square-button"
|
||||||
matRipple
|
matRipple
|
||||||
(click)="select(m)"
|
(click)="select(m)"
|
||||||
[class.primary]="selectedIds.indexOf(m.id) === -1"
|
[class.primary]="selectedIds().indexOf(m.id) === -1"
|
||||||
[class.strong-primary]="selectedIds.indexOf(m.id) !== -1"
|
[class.strong-primary]="selectedIds().indexOf(m.id) !== -1"
|
||||||
>
|
>
|
||||||
<h3>{{ m.name }}</h3>
|
<h3>{{ m.name }}</h3>
|
||||||
</mat-card>
|
</mat-card>
|
||||||
@@ -31,5 +31,5 @@
|
|||||||
</mat-tab-group>
|
</mat-tab-group>
|
||||||
</mat-dialog-content>
|
</mat-dialog-content>
|
||||||
<mat-dialog-actions align="end">
|
<mat-dialog-actions align="end">
|
||||||
<button mat-button [mat-dialog-close]="selected">Done</button>
|
<button mat-button [mat-dialog-close]="selected()">Done</button>
|
||||||
</mat-dialog-actions>
|
</mat-dialog-actions>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { CdkScrollable } from '@angular/cdk/scrolling';
|
import { CdkScrollable } from '@angular/cdk/scrolling';
|
||||||
import { AsyncPipe } from '@angular/common';
|
import { Component, inject, signal, computed } from '@angular/core';
|
||||||
import { Component, inject } from '@angular/core';
|
import { toSignal } from '@angular/core/rxjs-interop';
|
||||||
import { MatBadgeModule } from '@angular/material/badge';
|
import { MatBadgeModule } from '@angular/material/badge';
|
||||||
import { MatButtonModule } from '@angular/material/button';
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
import { MatCardModule } from '@angular/material/card';
|
import { MatCardModule } from '@angular/material/card';
|
||||||
@@ -18,7 +18,6 @@ import { ModifierCategory } from '../../core/modifier-category';
|
|||||||
templateUrl: './modifiers.component.html',
|
templateUrl: './modifiers.component.html',
|
||||||
styleUrls: ['./modifiers.component.sass'],
|
styleUrls: ['./modifiers.component.sass'],
|
||||||
imports: [
|
imports: [
|
||||||
AsyncPipe,
|
|
||||||
CdkScrollable,
|
CdkScrollable,
|
||||||
MatBadgeModule,
|
MatBadgeModule,
|
||||||
MatButtonModule,
|
MatButtonModule,
|
||||||
@@ -35,25 +34,17 @@ export class ModifiersComponent {
|
|||||||
selected: Modifier[];
|
selected: Modifier[];
|
||||||
}>(MAT_DIALOG_DATA);
|
}>(MAT_DIALOG_DATA);
|
||||||
|
|
||||||
list: Observable<ModifierCategory[]>;
|
list = toSignal(this.data.list, { initialValue: [] });
|
||||||
selected: Modifier[];
|
selected = signal<Modifier[]>(this.data.selected ? [...this.data.selected] : []);
|
||||||
selectedIds: (string | undefined)[];
|
selectedIds = computed(() => this.selected().map((e) => e.id));
|
||||||
|
|
||||||
constructor() {
|
|
||||||
const data = this.data;
|
|
||||||
|
|
||||||
this.list = data.list;
|
|
||||||
this.selected = data.selected;
|
|
||||||
this.selectedIds = this.selected.map((e) => e.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
select(m: Modifier) {
|
select(m: Modifier) {
|
||||||
const index = this.selectedIds.indexOf(m.id);
|
this.selected.update((list) => {
|
||||||
if (index === -1) {
|
const index = list.findIndex((e) => e.id === m.id);
|
||||||
this.selected.push(m);
|
if (index === -1) {
|
||||||
} else {
|
return [...list, m];
|
||||||
this.selected.splice(index, 1);
|
}
|
||||||
}
|
return list.filter((e) => e.id !== m.id);
|
||||||
this.selectedIds = this.selected.map((e) => e.id);
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user