Guide 3.21: Real Projects
Add Leaderboards
Gamification is the secret to retaining users in EdTech. By implementing a global leaderboard, students will take more exams in an effort to beat their peers.
Database Structure
3.21.1Assuming you have set up a backend (like Firebase or Supabase), you should create a scores collection. When a user submits an exam, push a document containing:
{
"user_id": "uid_12345",
"username": "Jambite99",
"subject": "physics",
"score": 38,
"timestamp": "2024-05-12T10:00:00Z"
}Querying Top Scores
3.21.2On your Home Screen, alongside the "Recent Scores" table, you can add a "Global Top 10" table. Query your backend database to sort the scores collection by the score field descending.
// Example Firebase query
const q = query(
collection(db, "scores"),
where("subject", "==", "physics"),
orderBy("score", "desc"),
limit(10)
);