better wifi ux

This commit is contained in:
Matt Hill
2026-03-18 16:52:47 -06:00
parent 9ed6c1263c
commit 6e56682c11

View File

@@ -3,6 +3,7 @@ import {
ChangeDetectorRef, ChangeDetectorRef,
Component, Component,
inject, inject,
signal,
} from '@angular/core' } from '@angular/core'
import { toSignal } from '@angular/core/rxjs-interop' import { toSignal } from '@angular/core/rxjs-interop'
import { FormsModule } from '@angular/forms' import { FormsModule } from '@angular/forms'
@@ -15,10 +16,26 @@ import {
pauseFor, pauseFor,
} from '@start9labs/shared' } from '@start9labs/shared'
import { TuiButton, TuiLoader, TuiNotificationService } from '@taiga-ui/core' import { TuiButton, TuiLoader, TuiNotificationService } from '@taiga-ui/core'
import { TuiNotificationMiddleService, TuiSwitch } from '@taiga-ui/kit' import {
TuiButtonLoading,
TuiNotificationMiddleService,
TuiSwitch,
} from '@taiga-ui/kit'
import { TuiCardLarge } from '@taiga-ui/layout' import { TuiCardLarge } from '@taiga-ui/layout'
import { PatchDB } from 'patch-db-client' import { PatchDB } from 'patch-db-client'
import { catchError, defer, map, merge, Observable, of, Subject } from 'rxjs' import {
catchError,
defer,
finalize,
first,
map,
merge,
Observable,
of,
Subject,
switchMap,
tap,
} from 'rxjs'
import { import {
FormComponent, FormComponent,
FormContext, FormContext,
@@ -55,10 +72,23 @@ import { wifiSpec } from './wifi.const'
</a> </a>
@if (status()?.interface) { @if (status()?.interface) {
@if (status()?.enabled) {
<button
tuiIconButton
size="s"
appearance="icon"
iconStart="@tui.refresh-cw"
[style.margin-inline-start]="'auto'"
[loading]="refreshing()"
(click)="refresh()"
>
{{ 'Refresh' | i18n }}
</button>
}
<input <input
type="checkbox" type="checkbox"
tuiSwitch tuiSwitch
[style.margin-inline-start]="'auto'" [style.margin-inline-start]="status()?.enabled ? '' : 'auto'"
[showIcons]="false" [showIcons]="false"
[ngModel]="status()?.enabled" [ngModel]="status()?.enabled"
(ngModelChange)="onToggle($event)" (ngModelChange)="onToggle($event)"
@@ -106,6 +136,7 @@ import { wifiSpec } from './wifi.const'
imports: [ imports: [
FormsModule, FormsModule,
TuiButton, TuiButton,
TuiButtonLoading,
TuiSwitch, TuiSwitch,
TuiCardLarge, TuiCardLarge,
TuiLoader, TuiLoader,
@@ -123,13 +154,35 @@ export default class SystemWifiComponent {
private readonly api = inject(ApiService) private readonly api = inject(ApiService)
private readonly alerts = inject(TuiNotificationService) private readonly alerts = inject(TuiNotificationService)
private readonly update$ = new Subject<WifiData>() private readonly update$ = new Subject<WifiData>()
private readonly refresh$ = new Subject<void>()
private readonly formDialog = inject(FormDialogService) private readonly formDialog = inject(FormDialogService)
private readonly cdr = inject(ChangeDetectorRef) private readonly cdr = inject(ChangeDetectorRef)
private readonly patch = inject<PatchDB<DataModel>>(PatchDB) private readonly patch = inject<PatchDB<DataModel>>(PatchDB)
private readonly i18n = inject(i18nPipe) private readonly i18n = inject(i18nPipe)
readonly status = toSignal(this.patch.watch$('serverInfo', 'network', 'wifi')) private readonly status$ = this.patch.watch$('serverInfo', 'network', 'wifi')
readonly wifi = toSignal(merge(this.getWifi$(), this.update$)) readonly status = toSignal(this.status$)
readonly wifi = toSignal(
merge(
this.status$.pipe(
first(s => !!s?.interface),
switchMap(() => this.getWifi$()),
),
this.refresh$.pipe(
tap(() => this.refreshing.set(true)),
switchMap(() =>
this.getWifi$().pipe(finalize(() => this.refreshing.set(false))),
),
),
this.update$,
),
)
readonly refreshing = signal(false)
refresh() {
this.refresh$.next()
}
async onToggle(enable: boolean) { async onToggle(enable: boolean) {
const loader = this.loader const loader = this.loader