Fix/patch fe (#2444)

* clear caches on logout

* fix uninstall pkg missing error
This commit is contained in:
Matt Hill
2023-10-05 19:04:10 -06:00
committed by GitHub
parent eb521b2332
commit caaf9d26db
8 changed files with 19 additions and 34 deletions

View File

@@ -1,6 +1,6 @@
import { Pipe, PipeTransform } from '@angular/core' import { Pipe, PipeTransform } from '@angular/core'
import { Observable, combineLatest, firstValueFrom } from 'rxjs' import { Observable, combineLatest, firstValueFrom } from 'rxjs'
import { map } from 'rxjs/operators' import { filter, map } from 'rxjs/operators'
import { DataModel } from 'src/app/services/patch-db/data-model' import { DataModel } from 'src/app/services/patch-db/data-model'
import { getPackageInfo, PkgInfo } from '../../../util/get-package-info' import { getPackageInfo, PkgInfo } from '../../../util/get-package-info'
import { PatchDB } from 'patch-db-client' import { PatchDB } from 'patch-db-client'
@@ -17,7 +17,7 @@ export class PackageInfoPipe implements PipeTransform {
transform(pkgId: string): Observable<PkgInfo> { transform(pkgId: string): Observable<PkgInfo> {
return combineLatest([ return combineLatest([
this.patch.watch$('package-data', pkgId), this.patch.watch$('package-data', pkgId).pipe(filter(Boolean)),
this.depErrorService.getPkgDepErrors$(pkgId), this.depErrorService.getPkgDepErrors$(pkgId),
]).pipe(map(([pkg, depErrors]) => getPackageInfo(pkg, depErrors))) ]).pipe(map(([pkg, depErrors]) => getPackageInfo(pkg, depErrors)))
} }

View File

@@ -1,4 +1,4 @@
import { BehaviorSubject, Observable } from 'rxjs' import { Observable, Subject } from 'rxjs'
import { Update } from 'patch-db-client' import { Update } from 'patch-db-client'
import { RR } from './api.types' import { RR } from './api.types'
import { DataModel } from 'src/app/services/patch-db/data-model' import { DataModel } from 'src/app/services/patch-db/data-model'
@@ -6,7 +6,7 @@ import { Log } from '@start9labs/shared'
import { WebSocketSubjectConfig } from 'rxjs/webSocket' import { WebSocketSubjectConfig } from 'rxjs/webSocket'
export abstract class ApiService { export abstract class ApiService {
readonly patchStream$ = new BehaviorSubject<Update<DataModel>[]>([]) readonly patchStream$ = new Subject<Update<DataModel>[]>()
// http // http

View File

@@ -26,7 +26,8 @@ import {
interval, interval,
map, map,
Observable, Observable,
ReplaySubject, shareReplay,
Subject,
switchMap, switchMap,
tap, tap,
timer, timer,
@@ -50,8 +51,8 @@ const PROGRESS: InstallProgress = {
@Injectable() @Injectable()
export class MockApiService extends ApiService { export class MockApiService extends ApiService {
readonly mockWsSource$ = new ReplaySubject<Update<DataModel>>() readonly mockWsSource$ = new Subject<Update<DataModel>>()
private readonly revertTime = 2000 private readonly revertTime = 1800
sequence = 0 sequence = 0
constructor( constructor(
@@ -149,7 +150,6 @@ export class MockApiService extends ApiService {
async echo(params: RR.EchoReq, url?: string): Promise<RR.EchoRes> { async echo(params: RR.EchoReq, url?: string): Promise<RR.EchoRes> {
if (url) { if (url) {
const num = Math.floor(Math.random() * 10) + 1 const num = Math.floor(Math.random() * 10) + 1
console.warn(num)
if (num > 8) return params.message if (num > 8) return params.message
throw new Error() throw new Error()
} }
@@ -158,7 +158,9 @@ export class MockApiService extends ApiService {
} }
openPatchWebsocket$(): Observable<Update<DataModel>> { openPatchWebsocket$(): Observable<Update<DataModel>> {
return this.mockWsSource$ return this.mockWsSource$.pipe(
shareReplay({ bufferSize: 1, refCount: true }),
)
} }
openLogsWebsocket$(config: WebSocketSubjectConfig<Log>): Observable<Log> { openLogsWebsocket$(config: WebSocketSubjectConfig<Log>): Observable<Log> {

View File

@@ -2,7 +2,6 @@ import {
DataModel, DataModel,
DockerIoFormat, DockerIoFormat,
HealthResult, HealthResult,
Manifest,
PackageMainStatus, PackageMainStatus,
PackageState, PackageState,
} from 'src/app/services/patch-db/data-model' } from 'src/app/services/patch-db/data-model'

View File

@@ -1,14 +1,6 @@
import { Injectable } from '@angular/core' import { Injectable } from '@angular/core'
import { Emver } from '@start9labs/shared' import { Emver } from '@start9labs/shared'
import { import { distinctUntilChanged, map, shareReplay } from 'rxjs/operators'
distinctUntilChanged,
filter,
map,
pairwise,
shareReplay,
startWith,
tap,
} from 'rxjs/operators'
import { PatchDB } from 'patch-db-client' import { PatchDB } from 'patch-db-client'
import { import {
DataModel, DataModel,
@@ -43,7 +35,7 @@ export class DepErrorService {
), ),
), ),
distinctUntilChanged(deepEqual), distinctUntilChanged(deepEqual),
shareReplay(1), shareReplay({ bufferSize: 1, refCount: true }),
) )
constructor( constructor(

View File

@@ -77,7 +77,7 @@ export class MarketplaceService implements AbstractMarketplaceService {
map(({ 'selected-url': url, 'known-hosts': hosts }) => map(({ 'selected-url': url, 'known-hosts': hosts }) =>
toStoreIdentity(url, hosts[url]), toStoreIdentity(url, hosts[url]),
), ),
shareReplay(1), shareReplay({ bufferSize: 1, refCount: true }),
) )
private readonly marketplace$ = this.knownHosts$.pipe( private readonly marketplace$ = this.knownHosts$.pipe(
@@ -105,7 +105,7 @@ export class MarketplaceService implements AbstractMarketplaceService {
}, },
{}, {},
), ),
shareReplay(1), shareReplay({ bufferSize: 1, refCount: true }),
) )
private readonly filteredMarketplace$ = combineLatest([ private readonly filteredMarketplace$ = combineLatest([

View File

@@ -13,13 +13,9 @@ import { LocalStorageBootstrap } from './patch-db/local-storage-bootstrap'
export class PatchMonitorService extends Observable<any> { export class PatchMonitorService extends Observable<any> {
// @TODO not happy with Observable<void> // @TODO not happy with Observable<void>
private readonly stream$ = this.authService.isVerified$.pipe( private readonly stream$ = this.authService.isVerified$.pipe(
tap(verified => { tap(verified =>
if (verified) { verified ? this.patch.start(this.bootstrapper) : this.patch.stop(),
this.patch.start(this.bootstrapper) ),
} else {
this.patch.stop()
}
}),
) )
constructor( constructor(

View File

@@ -18,11 +18,7 @@ import { combineLatest, from, timer } from 'rxjs'
export class TimeService { export class TimeService {
private readonly startTimeMs$ = this.patch private readonly startTimeMs$ = this.patch
.watch$('server-info', 'system-start-time') .watch$('server-info', 'system-start-time')
.pipe( .pipe(map(startTime => new Date(startTime).valueOf()))
take(1),
map(startTime => new Date(startTime).valueOf()),
shareReplay(),
)
readonly systemTime$ = from(this.apiService.getSystemTime({})).pipe( readonly systemTime$ = from(this.apiService.getSystemTime({})).pipe(
switchMap(utcStr => { switchMap(utcStr => {