Repository navigation
Add read-only Game Leaderboard canvas - #193
Open
sanjeevkumarcspl wants to merge 1 commit into
Open
sanjeevkumarcspl wants to merge 1 commit into
sanjeevkumarcspl wants to merge 1 commit into
Conversation
Ranks games by star rating with genre filtering, shared ranks for ties, and unrated games last. Closes github-samples#158 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
An unavailable database-client dependency blocks startup, the default database path conflicts with documented setup, and out-of-order requests can overwrite the selected genre’s results.
3 open issues
What changed in this PR
Adds a project-shared, read-only Game Leaderboard canvas for comparing catalog star ratings, addressing #158 without adding a public site page.
Changes:
- Adds a canvas UI and action with genre filtering and local database queries.
- Implements shared ranks for ties, deterministic ordering, and unrated games listed last.
- Adds ranking tests and documents setup, structure, and rating semantics.
| File | Description |
|---|---|
src/lib/leaderboard.test.ts |
Tests ranking, ties, filtering, empty results, and input preservation. |
README.md |
Documents the canvas, database setup, and rating semantics. |
.github/extensions/game-leaderboard/ranking.mjs |
Implements filtering and competition ranking. |
.github/extensions/game-leaderboard/ranking.d.mts |
Declares ranking input and output types. |
.github/extensions/game-leaderboard/extension.mjs |
Adds database reads, canvas UI, and lifecycle handlers. |
.github/copilot-instructions.md |
Documents canvas extensions and ranking test locations. |
Review effort: Balanced
| import { createServer } from "node:http"; | ||
| import { fileURLToPath } from "node:url"; | ||
| import { dirname, join, resolve } from "node:path"; | ||
| import { createClient } from "@libsql/client"; |
| const PROJECT_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..", "..", ".."); | ||
|
|
||
| function databaseUrl() { | ||
| return process.env.DATABASE_URL ?? `file:${join(PROJECT_ROOT, ".data", "tailspin.db")}`; |
Comment on lines
+86
to
+105
| const load = async () => { | ||
| status.textContent = "Loading..."; | ||
| status.className = "muted"; | ||
| try { | ||
| const response = await fetch("/api/leaderboard?genre=" + encodeURIComponent(genreSelect.value)); | ||
| const data = await response.json(); | ||
| if (!response.ok) throw new Error(data.error ?? "Request failed."); | ||
| if (genreSelect.options.length === 1) { | ||
| genreSelect.insertAdjacentHTML("beforeend", data.genres.map((g) => '<option value="' + escapeHtml(g) + '">' + escapeHtml(g) + "</option>").join("")); | ||
| } | ||
| if (!data.entries.length) { | ||
| result.innerHTML = '<div class="empty-state">No games found. Set up the local database with <code>npm run db:setup</code> or pick another genre.</div>'; | ||
| } else { | ||
| result.innerHTML = '<table><thead><tr><th scope="col">Rank</th><th scope="col">Game</th><th scope="col">Genre</th><th scope="col">Publisher</th><th scope="col">Star rating</th></tr></thead><tbody>' + | ||
| data.entries.map((e) => '<tr><td class="rank">' + (e.rank ?? "–") + "</td><td>" + escapeHtml(e.title) + "</td><td>" + escapeHtml(e.genre ?? "") + "</td><td>" + escapeHtml(e.publisher ?? "") + "</td><td>" + | ||
| (e.starRating === null ? '<span class="muted">Unrated</span>' : escapeHtml(e.starRating.toFixed(1))) + "</td></tr>").join("") + "</tbody></table>"; | ||
| } | ||
| status.textContent = data.entries.length + " game(s)"; | ||
| } catch (error) { | ||
| result.innerHTML = ""; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Description
Adds a project-shared, read-only Game Leaderboard canvas that ranks catalog games by their existing star rating, so prospective backers can compare games.
Related Issue
Closes #158
Type of Change
Changes Made
.github/extensions/game-leaderboard/(read-only; fixed SELECT, no user SQL), with a genre (category) filterranking.mjs(+ranking.d.mts): competition ranking for ties (1, 2, 2, 4), unrated games last with no rank, deterministic orderingsrc/lib/leaderboard.test.tscopilot-instructions.mdupdatedTesting
Data Layer Changes
npm run test:unit- all tests passnpm run db:generate) for any schema change (N/A, no schema change)Frontend Changes
npm run test:e2e- all tests pass (N/A, no site changes)data-testidattributes to interactive elements (N/A)npm run build) (N/A)Checklist
Additional Notes
Canvas only, per the approved plan; no public
/leaderboardpage.