feat: Refactor profile selection to support multiple miners and improve event handling

This commit is contained in:
Snider 2025-12-11 14:52:36 +00:00
parent eab37128cd
commit 52b4a1c6eb
2 changed files with 27 additions and 22 deletions

View file

@ -49,23 +49,27 @@
}
</wa-button>
} @else {
<div class="start-buttons">
<wa-select [value]="selectedProfileId()" (waSelect)="handleProfileSelection($event)">
<span slot="label">Profile</span>
@for(profile of state().profiles; track profile.id) {
@if(profile.minerType === miner.type) {
<wa-option [value]="profile.id">{{ profile.name }}</wa-option>
@if(miner.type) {
<div class="start-buttons">
<wa-select
[value]="selectedProfileIds().get(miner.type) ?? ''"
(change)="handleProfileSelection(miner.type, $event)">
<span slot="label">Profile</span>
@for(profile of state().profiles; track profile.id) {
@if(profile.minerType === miner.type) {
<wa-option [value]="profile.id">{{ profile.name }}</wa-option>
}
}
}
</wa-select>
<wa-button
variant="primary"
[disabled]="!selectedProfileId() || actionInProgress()?.startsWith('start-')"
(click)="startMiner()">
<wa-icon name="play-circle" slot="prefix"></wa-icon>
Start
</wa-button>
</div>
</wa-select>
<wa-button
variant="primary"
[disabled]="!selectedProfileIds().get(miner.type) || actionInProgress()?.startsWith('start-')"
(click)="startMiner(miner.type)">
<wa-icon name="play-circle" slot="prefix"></wa-icon>
Start
</wa-button>
</div>
}
}
</div>
}

View file

@ -33,11 +33,12 @@ export class MiningDashboardComponent {
error = signal<string | null>(null);
showProfileManager = signal(false);
selectedProfileId = signal<string | null>(null);
// Use a map to track the selected profile for each miner type
selectedProfileIds = signal<Map<string, string>>(new Map());
handleProfileSelection(event: any) {
// The value is in the detail property of the custom event
this.selectedProfileId.set(event.detail.value);
handleProfileSelection(minerType: string, event: Event) {
const selectedValue = (event.target as HTMLSelectElement).value;
this.selectedProfileIds.update(m => m.set(minerType, selectedValue));
}
private handleError(err: HttpErrorResponse, defaultMessage: string) {
@ -52,8 +53,8 @@ export class MiningDashboardComponent {
}
}
startMiner(): void {
const profileId = this.selectedProfileId();
startMiner(minerType: string): void {
const profileId = this.selectedProfileIds().get(minerType);
if (!profileId) {
this.error.set('Please select a profile to start.');
return;