Skip to content

Commit

Permalink
fix(xp-tracker): auto remove players not present in hiscores
Browse files Browse the repository at this point in the history
  • Loading branch information
FreekMencke committed Feb 25, 2024
1 parent 84df0c6 commit c2e4a83
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 58 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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();
}
}
10 changes: 10 additions & 0 deletions src/app/features/trackers/xp-tracker/xp-tracker-storage.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) ?? '[]');
}
Expand Down
56 changes: 8 additions & 48 deletions src/sitemap-items.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15796,22 +15796,6 @@
<loc>https://osrs-tracker.freekmencke.com/trackers/price/28177</loc>
<priority>0.7</priority>
</url>
<url>
<loc>https://osrs-tracker.freekmencke.com/trackers/price/28179</loc>
<priority>0.7</priority>
</url>
<url>
<loc>https://osrs-tracker.freekmencke.com/trackers/price/28181</loc>
<priority>0.7</priority>
</url>
<url>
<loc>https://osrs-tracker.freekmencke.com/trackers/price/28184</loc>
<priority>0.7</priority>
</url>
<url>
<loc>https://osrs-tracker.freekmencke.com/trackers/price/28190</loc>
<priority>0.7</priority>
</url>
<url>
<loc>https://osrs-tracker.freekmencke.com/trackers/price/28193</loc>
<priority>0.7</priority>
Expand Down Expand Up @@ -16028,38 +16012,6 @@
<loc>https://osrs-tracker.freekmencke.com/trackers/price/28628</loc>
<priority>0.7</priority>
</url>
<url>
<loc>https://osrs-tracker.freekmencke.com/trackers/price/28644</loc>
<priority>0.7</priority>
</url>
<url>
<loc>https://osrs-tracker.freekmencke.com/trackers/price/28646</loc>
<priority>0.7</priority>
</url>
<url>
<loc>https://osrs-tracker.freekmencke.com/trackers/price/28651</loc>
<priority>0.7</priority>
</url>
<url>
<loc>https://osrs-tracker.freekmencke.com/trackers/price/28653</loc>
<priority>0.7</priority>
</url>
<url>
<loc>https://osrs-tracker.freekmencke.com/trackers/price/28657</loc>
<priority>0.7</priority>
</url>
<url>
<loc>https://osrs-tracker.freekmencke.com/trackers/price/28659</loc>
<priority>0.7</priority>
</url>
<url>
<loc>https://osrs-tracker.freekmencke.com/trackers/price/28665</loc>
<priority>0.7</priority>
</url>
<url>
<loc>https://osrs-tracker.freekmencke.com/trackers/price/28667</loc>
<priority>0.7</priority>
</url>
<url>
<loc>https://osrs-tracker.freekmencke.com/trackers/price/28684</loc>
<priority>0.7</priority>
Expand Down Expand Up @@ -16160,4 +16112,12 @@
<loc>https://osrs-tracker.freekmencke.com/trackers/price/28790</loc>
<priority>0.7</priority>
</url>
<url>
<loc>https://osrs-tracker.freekmencke.com/trackers/price/28810</loc>
<priority>0.7</priority>
</url>
<url>
<loc>https://osrs-tracker.freekmencke.com/trackers/price/28813</loc>
<priority>0.7</priority>
</url>
</urlset>
2 changes: 1 addition & 1 deletion src/sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
</sitemap>
<sitemap>
<loc>https://osrs-tracker.freekmencke.com/sitemap-items.xml</loc>
<lastmod>2024-01-24T11:57:46.992Z</lastmod>
<lastmod>2024-02-25T10:57:04.288Z</lastmod>
</sitemap>
</sitemapindex>

0 comments on commit c2e4a83

Please sign in to comment.