diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1f4eb75..cf021da 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 2024/02/25
+
+- remove players that are missing from the hiscores from the xp tracker (name change, banned, etc)
+
## 2024/02/07
- skill overview in xp tracker
diff --git a/src/app/features/trackers/xp-tracker/player-widget/player-widget.component.ts b/src/app/features/trackers/xp-tracker/player-widget/player-widget.component.ts
index 0301865..2f7afd3 100644
--- a/src/app/features/trackers/xp-tracker/player-widget/player-widget.component.ts
+++ b/src/app/features/trackers/xp-tracker/player-widget/player-widget.component.ts
@@ -1,13 +1,24 @@
import { DecimalPipe } from '@angular/common';
-import { ChangeDetectionStrategy, Component, Input, OnChanges, WritableSignal, signal } from '@angular/core';
+import { HttpErrorResponse } from '@angular/common/http';
+import {
+ ChangeDetectionStrategy,
+ ChangeDetectorRef,
+ Component,
+ Input,
+ OnChanges,
+ WritableSignal,
+ signal,
+} from '@angular/core';
import { SkillEnum, getOverallXpDiff } from '@osrs-tracker/hiscores';
import { Player, PlayerStatus, PlayerType } from '@osrs-tracker/models';
-import { forkJoin } from 'rxjs';
+import { EMPTY, catchError, forkJoin } from 'rxjs';
import { SpinnerComponent } from 'src/app/common/components/general/spinner.component';
import { IconDirective } from 'src/app/common/directives/icon/icon.directive';
import { CapitalizePipe } from 'src/app/common/pipes/capitalize.pipe';
import { OsrsProxyRepo } from 'src/app/common/repositories/osrs-proxy.repo';
import { OsrsTrackerRepo } from 'src/app/common/repositories/osrs-tracker.repo';
+import { GoogleAnalyticsService } from 'src/app/common/services/google-analytics.service';
+import { XpTrackerStorageService } from '../xp-tracker-storage.service';
@Component({
standalone: true,
@@ -69,8 +80,11 @@ export class PlayerWidgetComponent implements OnChanges {
@Input() scrapingOffset: number;
constructor(
+ private changeDetectorRef: ChangeDetectorRef,
+ private googlAnalyticsService: GoogleAnalyticsService,
private osrsProxyRepo: OsrsProxyRepo,
private osrsTrackerRepo: OsrsTrackerRepo,
+ private xpTrackerStorageService: XpTrackerStorageService,
) {}
ngOnChanges(): void {
@@ -79,14 +93,37 @@ export class PlayerWidgetComponent implements OnChanges {
forkJoin([
this.osrsProxyRepo.getPlayerHiscore(this.username, this.scrapingOffset),
this.osrsTrackerRepo.getPlayerInfo(this.username, this.scrapingOffset, { includeLatestHiscoreEntry: true }),
- ]).subscribe(([hiscore, player]) => {
- this.playerDetails.set(player);
+ ])
+ .pipe(
+ catchError(err => {
+ if (err instanceof HttpErrorResponse && err.status === 404) {
+ this.removeMissingPlayer();
+ }
+ return EMPTY;
+ }),
+ )
+ .subscribe(([hiscore, player]) => {
+ this.playerDetails.set(player);
+
+ if (player.hiscoreEntries?.length) {
+ this.overallDiff.set(getOverallXpDiff(hiscore, player.hiscoreEntries[0]));
+ }
+
+ this.loading.set(false);
+ });
+ }
+
+ private removeMissingPlayer(): void {
+ if (this.xpTrackerStorageService.getRecentPlayers().includes(this.username)) {
+ this.xpTrackerStorageService.removeRecentPlayer(this.username);
+ }
+
+ if (this.xpTrackerStorageService.getFavoritePlayers().includes(this.username)) {
+ this.xpTrackerStorageService.toggleFavoritePlayer(this.username);
+ }
- if (player.hiscoreEntries?.length) {
- this.overallDiff.set(getOverallXpDiff(hiscore, player.hiscoreEntries[0]));
- }
+ this.googlAnalyticsService.trackEvent('remove-missing-player', 'xp-tracker', this.username, true);
- this.loading.set(false);
- });
+ this.changeDetectorRef.markForCheck();
}
}
diff --git a/src/app/features/trackers/xp-tracker/xp-tracker-storage.service.ts b/src/app/features/trackers/xp-tracker/xp-tracker-storage.service.ts
index ab69569..cfcbcbf 100644
--- a/src/app/features/trackers/xp-tracker/xp-tracker-storage.service.ts
+++ b/src/app/features/trackers/xp-tracker/xp-tracker-storage.service.ts
@@ -39,6 +39,16 @@ export class XpTrackerStorageService {
this.storageService.setItem(StorageKey.XpTrackerRecentPlayers, JSON.stringify(recentPlayers));
}
+ removeRecentPlayer(username: string): void {
+ const recentPlayers = this.getRecentPlayers();
+
+ if (recentPlayers.includes(username)) {
+ recentPlayers.splice(recentPlayers.indexOf(username), 1);
+ }
+
+ this.storageService.setItem(StorageKey.XpTrackerRecentPlayers, JSON.stringify(recentPlayers));
+ }
+
getFavoritePlayers(): string[] {
return JSON.parse(this.storageService.getItem(StorageKey.XpTrackerFavoritePlayers) ?? '[]');
}
diff --git a/src/sitemap-items.xml b/src/sitemap-items.xml
index 7303ef7..f1b4a16 100644
--- a/src/sitemap-items.xml
+++ b/src/sitemap-items.xml
@@ -15796,22 +15796,6 @@
https://osrs-tracker.freekmencke.com/trackers/price/28177
0.7
-
- https://osrs-tracker.freekmencke.com/trackers/price/28179
- 0.7
-
-
- https://osrs-tracker.freekmencke.com/trackers/price/28181
- 0.7
-
-
- https://osrs-tracker.freekmencke.com/trackers/price/28184
- 0.7
-
-
- https://osrs-tracker.freekmencke.com/trackers/price/28190
- 0.7
-
https://osrs-tracker.freekmencke.com/trackers/price/28193
0.7
@@ -16028,38 +16012,6 @@
https://osrs-tracker.freekmencke.com/trackers/price/28628
0.7
-
- https://osrs-tracker.freekmencke.com/trackers/price/28644
- 0.7
-
-
- https://osrs-tracker.freekmencke.com/trackers/price/28646
- 0.7
-
-
- https://osrs-tracker.freekmencke.com/trackers/price/28651
- 0.7
-
-
- https://osrs-tracker.freekmencke.com/trackers/price/28653
- 0.7
-
-
- https://osrs-tracker.freekmencke.com/trackers/price/28657
- 0.7
-
-
- https://osrs-tracker.freekmencke.com/trackers/price/28659
- 0.7
-
-
- https://osrs-tracker.freekmencke.com/trackers/price/28665
- 0.7
-
-
- https://osrs-tracker.freekmencke.com/trackers/price/28667
- 0.7
-
https://osrs-tracker.freekmencke.com/trackers/price/28684
0.7
@@ -16160,4 +16112,12 @@
https://osrs-tracker.freekmencke.com/trackers/price/28790
0.7
+
+ https://osrs-tracker.freekmencke.com/trackers/price/28810
+ 0.7
+
+
+ https://osrs-tracker.freekmencke.com/trackers/price/28813
+ 0.7
+
\ No newline at end of file
diff --git a/src/sitemap.xml b/src/sitemap.xml
index f7e3437..6ce7e88 100644
--- a/src/sitemap.xml
+++ b/src/sitemap.xml
@@ -6,6 +6,6 @@
https://osrs-tracker.freekmencke.com/sitemap-items.xml
- 2024-01-24T11:57:46.992Z
+ 2024-02-25T10:57:04.288Z
\ No newline at end of file