mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
ui: fix distinctUntilChanged()
This commit is contained in:
committed by
Aiden McClelland
parent
0937c81e46
commit
e1200c2991
@@ -103,13 +103,18 @@
|
|||||||
<p><a (click)="copyTor()">{{ vars.torAddress }} <ion-icon name="copy-outline" class="tiny-icon"></ion-icon></a></p>
|
<p><a (click)="copyTor()">{{ vars.torAddress }} <ion-icon name="copy-outline" class="tiny-icon"></ion-icon></a></p>
|
||||||
</ion-label>
|
</ion-label>
|
||||||
</ion-item>
|
</ion-item>
|
||||||
<ion-item *ngIf="vars.ui" lines="none">
|
<ion-item *ngIf="vars.lanAddress" lines="none">
|
||||||
<ion-label class="ion-text-wrap">
|
<ion-label class="ion-text-wrap">
|
||||||
<h2>LAN Address</h2>
|
<h2>LAN Address</h2>
|
||||||
<p><a (click)="copyLan()">{{ vars.lanAddress }} <ion-icon name="copy-outline" class="tiny-icon"></ion-icon></a></p>
|
<p>
|
||||||
|
<a (click)="copyLan()">{{ vars.lanAddress }} <ion-icon name="copy-outline" class="tiny-icon"></ion-icon></a>
|
||||||
|
</p>
|
||||||
|
<p *ngIf="vars.testingLanConnection" style="display: flex; align-items: center; font-size: x-small">
|
||||||
|
<ion-text color="dark">Testing Connection</ion-text>
|
||||||
|
<ion-spinner style="height: 15px; margin-left: 5px;" name="dots" color="dark"></ion-spinner>
|
||||||
|
</p>
|
||||||
</ion-label>
|
</ion-label>
|
||||||
<ion-toggle *ngIf="!vars.testingLanConnection" (ionChange)="$lanToggled$.next($event)" [checked]="vars.lanEnabled" slot="end" fill="clear" class="lan-toggle" [disabled]="vars.status !== 'RUNNING'"></ion-toggle>
|
<ion-toggle (ionChange)="$lanToggled$.next($event)" [checked]="vars.lanEnabled" slot="end" class="lan-toggle" [disabled]="vars.status !== 'RUNNING' || vars.testingLanConnection"></ion-toggle>
|
||||||
<ion-spinner slot="end" *ngIf="vars.testingLanConnection" name="lines" color="medium"></ion-spinner>
|
|
||||||
</ion-item>
|
</ion-item>
|
||||||
|
|
||||||
<ion-item-divider>Backups</ion-item-divider>
|
<ion-item-divider>Backups</ion-item-divider>
|
||||||
|
|||||||
@@ -65,5 +65,4 @@
|
|||||||
height: 1em;
|
height: 1em;
|
||||||
--handle-width: 0.9em;
|
--handle-width: 0.9em;
|
||||||
--handle-height: 0.9em;
|
--handle-height: 0.9em;
|
||||||
margin-right: 10px;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { copyToClipboard } from 'src/app/util/web.util'
|
|||||||
import { AppModel, AppStatus } from 'src/app/models/app-model'
|
import { AppModel, AppStatus } from 'src/app/models/app-model'
|
||||||
import { AppInstalledFull } from 'src/app/models/app-types'
|
import { AppInstalledFull } from 'src/app/models/app-types'
|
||||||
import { ModelPreload } from 'src/app/models/model-preload'
|
import { ModelPreload } from 'src/app/models/model-preload'
|
||||||
import { chill, modulateTime, pauseFor } from 'src/app/util/misc.util'
|
import { chill, modulateTime, pauseFor, traceWheel } from 'src/app/util/misc.util'
|
||||||
import { PropertySubject, peekProperties } from 'src/app/util/property-subject.util'
|
import { PropertySubject, peekProperties } from 'src/app/util/property-subject.util'
|
||||||
import { AppBackupPage } from 'src/app/modals/app-backup/app-backup.page'
|
import { AppBackupPage } from 'src/app/modals/app-backup/app-backup.page'
|
||||||
import { LoaderService, markAsLoadingDuring$, markAsLoadingDuringP } from 'src/app/services/loader.service'
|
import { LoaderService, markAsLoadingDuring$, markAsLoadingDuringP } from 'src/app/services/loader.service'
|
||||||
@@ -83,6 +83,8 @@ export class AppInstalledShowPage extends Cleanup {
|
|||||||
combineLatest([app.lanEnabled, this.$lanConnected$, app.status, this.$testingLanConnection$]).pipe(
|
combineLatest([app.lanEnabled, this.$lanConnected$, app.status, this.$testingLanConnection$]).pipe(
|
||||||
filter(([_, __, s, alreadyConnecting]) => s === AppStatus.RUNNING && !alreadyConnecting),
|
filter(([_, __, s, alreadyConnecting]) => s === AppStatus.RUNNING && !alreadyConnecting),
|
||||||
concatMap(([enabled, connected]) => {
|
concatMap(([enabled, connected]) => {
|
||||||
|
// console.log('enabled', enabled)
|
||||||
|
// console.log('connected', connected)
|
||||||
if (enabled && !connected) return markAsLoadingDuring$(this.$testingLanConnection$, this.testLanConnection())
|
if (enabled && !connected) return markAsLoadingDuring$(this.$testingLanConnection$, this.testLanConnection())
|
||||||
if (!enabled && connected) return of(this.$lanConnected$.next(false))
|
if (!enabled && connected) return of(this.$lanConnected$.next(false))
|
||||||
return of()
|
return of()
|
||||||
@@ -90,19 +92,23 @@ export class AppInstalledShowPage extends Cleanup {
|
|||||||
),
|
),
|
||||||
// toggle lan
|
// toggle lan
|
||||||
combineLatest([this.$lanToggled$, app.lanEnabled, this.$testingLanConnection$]).pipe(
|
combineLatest([this.$lanToggled$, app.lanEnabled, this.$testingLanConnection$]).pipe(
|
||||||
distinctUntilChanged(([toggled1], [toggled2]) => toggled1 !== toggled2),
|
|
||||||
filter(([_, __, alreadyLoading]) => !alreadyLoading),
|
filter(([_, __, alreadyLoading]) => !alreadyLoading),
|
||||||
map(([e, _]) => [(e as any).detail.checked, _]),
|
map(([e, _]) => [(e as any).detail.checked, _]),
|
||||||
|
distinctUntilChanged(([toggled1], [toggled2]) => toggled1 === toggled2),
|
||||||
// if the app is already in the desired state, we bail
|
// if the app is already in the desired state, we bail
|
||||||
// this can happen because ionChange triggers when the [checked] value changes
|
// this can happen because ionChange triggers when the [checked] value changes
|
||||||
filter(([uiEnabled, appEnabled]) => (uiEnabled && !appEnabled) || (!uiEnabled && appEnabled)),
|
filter(([uiEnabled, appEnabled]) => (uiEnabled && !appEnabled) || (!uiEnabled && appEnabled)),
|
||||||
map(([enabled]) => enabled
|
concatMap( ([enabled]) => {
|
||||||
? this.enableLan().pipe(concatMap(() => this.testLanConnection()))
|
let o: Observable<void>
|
||||||
: this.disableLan(),
|
if (enabled) {
|
||||||
),
|
o = this.enableLan().pipe(concatMap(() => this.testLanConnection()))
|
||||||
concatMap(o => markAsLoadingDuring$(this.$testingLanConnection$, o).pipe(
|
} else {
|
||||||
catchError(e => this.setError(e)),
|
o = this.disableLan()
|
||||||
)),
|
}
|
||||||
|
return markAsLoadingDuring$(this.$testingLanConnection$, o).pipe(
|
||||||
|
catchError(e => this.setError(e)),
|
||||||
|
)
|
||||||
|
}),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
), //must be final in stack
|
), //must be final in stack
|
||||||
@@ -119,6 +125,7 @@ export class AppInstalledShowPage extends Cleanup {
|
|||||||
retryWhen(errors => errors.pipe(delay(2500), take(20))),
|
retryWhen(errors => errors.pipe(delay(2500), take(20))),
|
||||||
catchError(() => of(false)),
|
catchError(() => of(false)),
|
||||||
take(1),
|
take(1),
|
||||||
|
traceWheel('lan connected test'),
|
||||||
map(connected => this.$lanConnected$.next(connected)),
|
map(connected => this.$lanConnected$.next(connected)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,8 +45,8 @@ export class MockApiService extends ApiService {
|
|||||||
async testConnection (): Promise<true> {
|
async testConnection (): Promise<true> {
|
||||||
console.log('testing connection')
|
console.log('testing connection')
|
||||||
this.testCounter ++
|
this.testCounter ++
|
||||||
await pauseFor(1000)
|
await pauseFor(10000000)
|
||||||
if (this.testCounter > 5) {
|
if (this.testCounter > 3) {
|
||||||
return true
|
return true
|
||||||
} else {
|
} else {
|
||||||
throw new Error('Not Connected')
|
throw new Error('Not Connected')
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"useMocks": false,
|
"useMocks": true,
|
||||||
"mockOver": "lan",
|
"mockOver": "lan",
|
||||||
"skipStartupAlerts": false
|
"skipStartupAlerts": true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user