Documentation 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.
RankingService provides TriviaPP’s online leaderboard functionality by reading and writing player scores to a Firebase Firestore collection named ranking. Each document records a player name, their session score, and the calendar date of the session. When retrieving the leaderboard, the service fetches all documents ordered by score and then filters client-side to today’s date, effectively presenting a fresh daily ranking on every load.
For instructions on setting up the Firebase project and providing your Firestore credentials, see the Firebase setup guide.
Constructor / Dependencies
RankingService is provided in the root injector and has no Angular constructor dependencies — it initialises Firebase and Firestore directly in the class body using the modular Firebase SDK.
getApps().length before calling initializeApp(). This guard prevents a “Firebase app already exists” error when multiple services or hot-module reloads attempt to initialise the same Firebase project.
firebaseConfig is imported from src/firebase.config.ts. Keep this file out of version control and provide the credentials via environment variables or a CI secret. See the Firebase setup guide for details.Firestore Document Shape
Every document written to theranking collection follows this structure:
Methods
addScore()
Writes a new score document to the ranking Firestore collection, stamped with today’s date.
The player’s display name (sourced from
StorageService.getProfile().displayName).The total score achieved in the completed game session.
date field is derived automatically:
getDailyRanking()
Retrieves all documents from the ranking collection ordered by score descending, then filters them client-side to return only entries whose date matches today.
score descending. Returns an empty array [] if no scores have been recorded today.
Firestore query issued:
The
orderBy('score', 'desc') query requires a composite index in Firestore if combined with a where clause. The current implementation avoids a Firestore where filter by doing the date comparison in memory, so no composite index is required.