TriviaPP maintains two parallel ranking systems: an online leaderboard stored in Firebase Firestore that aggregates scores from all players on a given day, and a local leaderboard stored in the device’sDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/dreancaste/TriviaPP/llms.txt
Use this file to discover all available pages before exploring further.
localStorage that persists the top 20 scores for the current 24-hour window. Both are written simultaneously at the end of every trivia session.
Online Ranking (Firebase Firestore)
RankingService is the Angular service responsible for all Firestore interactions. It initializes the Firebase app on first use (or reuses an existing app instance) and holds a reference to the Firestore database.
Writing a score — addScore(name, score) creates a new document in the ranking collection:
getDailyRanking() queries the ranking collection ordered by score descending, then filters the results in memory to entries whose date field matches today’s ISO date string:
RankingPage calls getDailyRanking() in ngOnInit and binds the returned array to the leaderboard view.
Local Ranking (localStorage)
StorageService maintains a local copy of the leaderboard under the storage key sw_ranking. Key behaviors:
- Top 20 cap — after every insert the array is sorted by score descending and trimmed to 20 entries.
- Name-based upsert — if a player with the same display name (case-insensitive) already exists, only their score is updated — and only if the new score is higher.
- Automatic 24-hour reset — a companion key
sw_ranking_reset_timerecords the Unix timestamp of the last reset. Every call togetRanking()oraddRankingItem()checks whether 24 hours have elapsed; if so,sw_rankingis cleared and the reset timestamp is refreshed.
RankingItem Interface
Both the Firebase documents and the local storage entries are shaped by theRankingItem model:
date field is optional on the interface; the Firestore writer always populates it, while the local storage writer omits it.
When Scores Are Saved
Scores are written at the very end of a trivia session insideTriviaPage.finishGame(). The sequence is:
StorageService.addHistory(historyItem)— session saved to history.StorageService.addRankingItem(rankingItem)— local leaderboard updated.StorageService.updateStats(score, correctCount)— cumulative stats updated.RankingService.addScore(displayName, score)— entry posted to Firestore.