Skip to content

Add location label to game viewer stats display#1219

Merged
kixelated merged 3 commits into
mainfrom
claude/add-location-flag-lMn8O
Apr 6, 2026
Merged

Add location label to game viewer stats display#1219
kixelated merged 3 commits into
mainfrom
claude/add-location-flag-lMn8O

Conversation

@kixelated

Copy link
Copy Markdown
Collaborator

Summary

This PR adds support for displaying a location label in the game viewer's stats panel. The location is configurable via a command-line argument and is dynamically shown/hidden based on the game status updates.

Key Changes

  • Backend (Rust): Added --location CLI argument to allow specifying a location label (e.g., "Dallas, TX") that gets included in the game status JSON
  • Frontend (TypeScript):
    • Extended GameStatus interface with optional location field
    • Created a new locationEl DOM element in the controls panel to display the location
    • Added logic to show/hide the location element based on status updates
    • Updated #buildControls() return type to include the location element
  • Styling: Added CSS styling for the .location class with monospace font, green color (#8bac0f), and appropriate sizing to match the latency list styling

Implementation Details

  • The location element is initially hidden and only displayed when a location value is present in the game status
  • The location is positioned above the latency list in the controls panel
  • The backend conditionally includes the location in the JSON status only if the --location argument was provided
  • Styling matches the existing latency list aesthetic for visual consistency

https://claude.ai/code/session_01NqVUKRxJYpgtK8hRtPpwxw

Adds a --location CLI flag (e.g. --location "Dallas, TX") that gets
included in the status track JSON and displayed in the viewer debug
stats above the latency section.

https://claude.ai/code/session_01NqVUKRxJYpgtK8hRtPpwxw
@coderabbitai

coderabbitai Bot commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

The change adds optional location reporting across the project. The Rust backend Config gains a --location option and Status includes an optional location field (skipped in serialization when None), which is populated and emitted in status JSON. The TypeScript frontend extends GameStatus with location?: string, updates GameCard to conditionally render a .location element, and adds CSS for its display.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding a location label to the game viewer stats display, which aligns with all the modifications across backend and frontend.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, detailing backend CLI additions, frontend interface extensions, DOM element creation, and styling updates.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/add-location-flag-lMn8O
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch claude/add-location-flag-lMn8O

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
rs/moq-boy/src/main.rs (1)

294-301: Consider using serde_json's #[serde(skip_serializing_if)] for cleaner optional field handling.

The current approach of mutating the JSON value works correctly, but a more idiomatic approach would be to define a struct with #[serde(skip_serializing_if = "Option::is_none")] on the location field. This avoids manual mutation and clearly expresses intent.

That said, the current implementation is functional and the scope of change is minimal, so this is optional.

♻️ Optional: Define a status struct for cleaner serialization
// At module level
#[derive(serde::Serialize)]
struct StatusPayload<'a> {
    buttons: &'a [&'a str],
    reset_in: u64,
    latency: &'a serde_json::Map<String, serde_json::Value>,
    #[serde(skip_serializing_if = "Option::is_none")]
    location: Option<&'a str>,
}

// Then in the loop:
let new_status = StatusPayload {
    buttons: &held.iter().map(|s| s.as_str()).collect::<Vec<_>>(),
    reset_in: remaining,
    latency: &latency_map,
    location: location.as_deref(),
};
let new_status_str = serde_json::to_string(&new_status).unwrap();
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@rs/moq-boy/src/main.rs` around lines 294 - 301, Replace the manual JSON
mutation with a serde-serializable struct to let serde handle optional fields:
create a StatusPayload struct (derive Serialize) with fields matching buttons,
reset_in, latency and an Option<String> location annotated with
#[serde(skip_serializing_if = "Option::is_none")], then construct StatusPayload
using held, remaining, latency_map and location.as_deref()/cloned as appropriate
and serialize it with serde_json::to_string instead of building/ mutating
new_status; this removes the if let Some(loc) = &location block and makes
serialization for location automatic.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@rs/moq-boy/src/main.rs`:
- Around line 294-301: Replace the manual JSON mutation with a
serde-serializable struct to let serde handle optional fields: create a
StatusPayload struct (derive Serialize) with fields matching buttons, reset_in,
latency and an Option<String> location annotated with
#[serde(skip_serializing_if = "Option::is_none")], then construct StatusPayload
using held, remaining, latency_map and location.as_deref()/cloned as appropriate
and serialize it with serde_json::to_string instead of building/ mutating
new_status; this removes the if let Some(loc) = &location block and makes
serialization for location automatic.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0cf97814-5547-4cbb-9a5a-ebd4d63dce71

📥 Commits

Reviewing files that changed from the base of the PR and between e50748e and 7f57c72.

📒 Files selected for processing (3)
  • js/moq-boy/src/index.ts
  • js/moq-boy/src/styles.ts
  • rs/moq-boy/src/main.rs

kixelated and others added 2 commits April 6, 2026 12:40
…lag-lMn8O

# Conflicts:
#	js/moq-boy/src/index.ts
#	js/moq-boy/src/styles.ts
#	rs/moq-boy/src/main.rs
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@kixelated kixelated enabled auto-merge (squash) April 6, 2026 19:44

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
js/moq-boy/src/index.ts (1)

13-18: Document the new public GameStatus.location field semantics

GameStatus is exported, and location semantics (omitted vs present) should be documented to keep API consumers aligned.

Suggested API doc addition
 export interface GameStatus {
 	buttons: string[];
 	latency: Record<string, number>;
+	/** Optional location label; omitted when backend has no configured location. */
 	location?: string;
 	stats?: GameStats;
 }

As per coding guidelines, "Document public APIs with clear docstrings or comments".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@js/moq-boy/src/index.ts` around lines 13 - 18, Add a docstring to the
exported GameStatus interface documenting the semantics of the optional location
field: describe when location will be present versus omitted, the expected
string format/values (examples if applicable), how consumers should interpret an
omitted value versus an empty string, and any guarantees (e.g., never null).
Update the comment directly above the location?: string; declaration in the
GameStatus interface in index.ts so API consumers can rely on consistent
behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@js/moq-boy/src/index.ts`:
- Around line 265-271: The current truthy check for json.location hides the
element when the payload contains an empty string; change the condition to an
explicit presence check (e.g., testing json.location !== undefined or
Object.prototype.hasOwnProperty.call(json, "location")) so that locationEl is
shown whenever the location field exists in the payload (even if empty) and
still hidden only when the field is absent; update the block around locationEl
and json.location to use that explicit check.

---

Nitpick comments:
In `@js/moq-boy/src/index.ts`:
- Around line 13-18: Add a docstring to the exported GameStatus interface
documenting the semantics of the optional location field: describe when location
will be present versus omitted, the expected string format/values (examples if
applicable), how consumers should interpret an omitted value versus an empty
string, and any guarantees (e.g., never null). Update the comment directly above
the location?: string; declaration in the GameStatus interface in index.ts so
API consumers can rely on consistent behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c619e9d1-36d6-4907-be4b-d072a48da8b9

📥 Commits

Reviewing files that changed from the base of the PR and between 7f57c72 and 3cf0eb9.

📒 Files selected for processing (3)
  • js/moq-boy/src/index.ts
  • js/moq-boy/src/styles.ts
  • rs/moq-boy/src/main.rs
✅ Files skipped from review due to trivial changes (1)
  • js/moq-boy/src/styles.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • rs/moq-boy/src/main.rs

Comment thread js/moq-boy/src/index.ts
Comment on lines +265 to +271
// Show location if available.
if (json.location) {
locationEl.style.display = "block";
locationEl.textContent = json.location;
} else {
locationEl.style.display = "none";
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Use explicit presence check for location instead of truthiness

Line [266] uses a truthy check, so "" is treated as “missing” even when the field is present in payload. Prefer checking for undefined.

Proposed fix
-					if (json.location) {
+					if (json.location !== undefined) {
 						locationEl.style.display = "block";
 						locationEl.textContent = json.location;
 					} else {
 						locationEl.style.display = "none";
 					}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@js/moq-boy/src/index.ts` around lines 265 - 271, The current truthy check for
json.location hides the element when the payload contains an empty string;
change the condition to an explicit presence check (e.g., testing json.location
!== undefined or Object.prototype.hasOwnProperty.call(json, "location")) so that
locationEl is shown whenever the location field exists in the payload (even if
empty) and still hidden only when the field is absent; update the block around
locationEl and json.location to use that explicit check.

@kixelated kixelated merged commit 8954b62 into main Apr 6, 2026
2 checks passed
@kixelated kixelated deleted the claude/add-location-flag-lMn8O branch April 6, 2026 20:06
@moq-bot moq-bot Bot mentioned this pull request Apr 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants