wip
This commit is contained in:
@@ -42,5 +42,12 @@ export class CandidateDataService {
|
||||
);
|
||||
}
|
||||
|
||||
deleteCandidate(id: number) {
|
||||
return this.httpClient.delete(`${environment.hostUrl}/app/candidate/${id}`).pipe(
|
||||
tap(() => {
|
||||
this.cachedApplicationList = this.cachedApplicationList.filter(c => c.id !== id);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,10 +25,27 @@ export class SocketIOService {
|
||||
});
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
this.socket.disconnect();
|
||||
onCandidateDeleted(): Observable<any> {
|
||||
return new Observable(observer => {
|
||||
this.socket.on('candidateDeleted', (data) => {
|
||||
observer.next(data);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
onStatsUpdated(): Observable<any> {
|
||||
return new Observable(observer => {
|
||||
this.socket.on('statsUpdated', (data) => {
|
||||
observer.next(data);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// disconnect() {
|
||||
// this.socket.disconnect();
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
36
src/app/services/stats.service.ts
Normal file
36
src/app/services/stats.service.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { Injectable, signal, effect, inject } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { SocketIOService } from './socket-io.service';
|
||||
import { environment } from '../../environments/environment';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class StatsService {
|
||||
http = inject(HttpClient);
|
||||
socket = inject(SocketIOService);
|
||||
|
||||
|
||||
totalVisits = signal(0);
|
||||
totalClicks = signal(0);
|
||||
|
||||
private socketEffect = effect(() => {
|
||||
this.socket.onStatsUpdated().subscribe(stats => {
|
||||
this.totalVisits.set(stats.totalVisits);
|
||||
this.totalClicks.set(stats.totalClicks);
|
||||
});
|
||||
});
|
||||
|
||||
loadInitial() {
|
||||
this.http.get<any>(`${environment.hostUrl}/stats`).subscribe(stats => {
|
||||
this.totalVisits.set(stats.totalVisits);
|
||||
this.totalClicks.set(stats.totalClicks);
|
||||
});
|
||||
}
|
||||
|
||||
incrementVisit() {
|
||||
return this.http.post(`${environment.hostUrl}/stats/visit`, {});
|
||||
}
|
||||
|
||||
incrementClick() {
|
||||
return this.http.post(`${environment.hostUrl}/stats/click`, {});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user