refactor: extract loading status to shared library (#2282)

* refactor: extract loading status to shared library

* chore: remove inline style
This commit is contained in:
Alex Inkin
2023-05-26 00:04:47 +04:00
committed by Aiden McClelland
parent 52c0bb5302
commit 3804a46f3b
27 changed files with 320 additions and 218 deletions

View File

@@ -2,7 +2,7 @@ import { BehaviorSubject, Observable } from 'rxjs'
import { Update } from 'patch-db-client'
import { RR, Encrypted, BackupTargetType, Metrics } from './api.types'
import { DataModel } from 'src/app/services/patch-db/data-model'
import { Log } from '@start9labs/shared'
import { Log, SetupStatus } from '@start9labs/shared'
import { WebSocketSubjectConfig } from 'rxjs/webSocket'
import type { JWK } from 'node-jose'
@@ -293,4 +293,6 @@ export abstract class ApiService {
abstract sideloadPackage(
params: RR.SideloadPackageReq,
): Promise<RR.SideloadPacakgeRes>
abstract getSetupStatus(): Promise<SetupStatus | null>
}

View File

@@ -8,6 +8,7 @@ import {
Method,
RpcError,
RPCOptions,
SetupStatus,
} from '@start9labs/shared'
import { ApiService } from './embassy-api.service'
import { BackupTargetType, Metrics, RR } from './api.types'
@@ -31,7 +32,9 @@ export class LiveApiService extends ApiService {
private readonly patch: PatchDB<DataModel>,
) {
super()
; (window as any).rpcClient = this
// @ts-ignore
this.document.defaultView.rpcClient = this
}
// for getting static files: ex icons, instructions, licenses
@@ -122,6 +125,10 @@ export class LiveApiService extends ApiService {
return this.openWebsocket(config)
}
async followLogs(): Promise<string> {
return this.rpcRequest({ method: 'setup.logs.follow', params: {} })
}
openLogsWebsocket$(config: WebSocketSubjectConfig<Log>): Observable<Log> {
return this.openWebsocket(config)
}
@@ -498,6 +505,13 @@ export class LiveApiService extends ApiService {
})
}
async getSetupStatus() {
return this.rpcRequest<SetupStatus | null>({
method: 'setup.status',
params: {},
})
}
private openWebsocket<T>(config: WebSocketSubjectConfig<T>): Observable<T> {
const { location } = this.document.defaultView!
const protocol = location.protocol === 'http:' ? 'ws' : 'wss'

View File

@@ -1,5 +1,5 @@
import { Injectable } from '@angular/core'
import { Log, pauseFor } from '@start9labs/shared'
import { pauseFor, Log, getSetupStatusMock } from '@start9labs/shared'
import { ApiService } from './embassy-api.service'
import {
Operation,
@@ -999,6 +999,10 @@ export class MockApiService extends ApiService {
return '4120e092-05ab-4de2-9fbd-c3f1f4b1df9e' // no significance, randomly generated
}
async getSetupStatus() {
return getSetupStatusMock()
}
private async updateProgress(id: string): Promise<void> {
const progress = { ...PROGRESS }
const phases = [