Skip to content

Commit

Permalink
fix: IndexChangeService updated
Browse files Browse the repository at this point in the history
  • Loading branch information
raronpxcsw committed Nov 27, 2024
1 parent 9ae97e5 commit 6ded949
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
36 changes: 22 additions & 14 deletions projects/aas-lib/src/lib/index-change.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { WebSocketSubject } from 'rxjs/webSocket';
import { WebSocketData, AASServerMessage } from 'aas-core';
import { WebSocketFactoryService } from './web-socket-factory.service';
import { HttpClient } from '@angular/common/http';
import { map, Observable, zip } from 'rxjs';

interface State {
documentCount: number;
Expand All @@ -37,18 +38,17 @@ export class IndexChangeService {
) {
this.subscribeIndexChanged();

this.http.get<{ count: number }>('/api/v1/endpoints/count').subscribe({
next: result => {
this.state.update(state => ({ ...state, endpointCount: result.count }));
},
error: error => {
console.debug(error);
},
});

this.http
.get<{ count: number }>('/api/v1/documents/count')
.subscribe(result => this.state.update(state => ({ ...state, documentCount: result.count })));
zip(
this.http.get<{ count: number }>('/api/v1/endpoints/count'),
this.http.get<{ count: number }>('/api/v1/documents/count'),
)
.pipe(
map(([endpointCount, documentCount]) => [endpointCount.count, documentCount.count]),
map(([endpointCount, documentCount]) =>
this.state.update(state => ({ ...state, endpointCount, documentCount })),
),
)
.subscribe();
}

public readonly reset = new EventEmitter();
Expand All @@ -68,8 +68,16 @@ export class IndexChangeService {

public readonly changedDocuments = computed(() => this.state().changedDocuments);

public clear(): void {
this.state.update(state => ({ ...state, changedDocuments: 0 }));
public clear(): Observable<void> {
return zip(
this.http.get<{ count: number }>('/api/v1/endpoints/count'),
this.http.get<{ count: number }>('/api/v1/documents/count'),
).pipe(
map(([endpointCount, documentCount]) => [endpointCount.count, documentCount.count]),
map(([endpointCount, documentCount]) =>
this.state.set({ endpointCount, documentCount, changedDocuments: 0 }),
),
);
}

private subscribeIndexChanged = (): void => {
Expand Down
2 changes: 1 addition & 1 deletion projects/aas-portal/src/app/main/main.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class MainComponent implements OnInit {
}

public clear(): void {
this.indexChange.clear();
this.indexChange.clear().subscribe();
}

public onKeyDown($event: KeyboardEvent): void {
Expand Down

0 comments on commit 6ded949

Please sign in to comment.