Skip to content

fix lobby - #6

Merged
djzet merged 1 commit into
mainfrom
sea
Aug 20, 2026
Merged

fix lobby#6
djzet merged 1 commit into
mainfrom
sea

Conversation

@djzet

@djzet djzet commented Aug 20, 2026

Copy link
Copy Markdown
Owner

Summary by Sourcery

Improve lobby creation and joining by handling player membership reliably and localizing participant names.

New Features:

  • Automatically copy newly created lobby codes to the clipboard and confirm the action to the user.

Bug Fixes:

  • Prevent duplicate player records and stale lobby membership when joining, while avoiding duplicate joins to the current lobby.

Enhancements:

  • Use localized host and player names with a fallback translation helper.

@sourcery-ai

sourcery-ai Bot commented Aug 20, 2026

Copy link
Copy Markdown

Reviewer's Guide

Fixes lobby join/creation behaviors, adds translation support for lobby-related names and messages, handles duplicate player records, and auto-copies lobby code on creation.

Sequence diagram for updated lobby join flow

sequenceDiagram
    participant AppLobby
    participant Supabase
    participant LocaleManager

    AppLobby->>AppLobby: join(code)
    AppLobby->>AppLobby: getSupabase()
    AppLobby->>Supabase: from(lobbies).select('*').eq('code', code).single()
    Supabase-->>AppLobby: lobby
    AppLobby->>Supabase: from(players).select('*').eq('lobby_code', code)
    Supabase-->>AppLobby: existingPlayers
    AppLobby->>Supabase: from(players).delete().eq('lobby_code', code).eq('player_id', myId)
    AppLobby->>LocaleManager: t('playerName')
    LocaleManager-->>AppLobby: localizedName
    AppLobby->>Supabase: from(players).insert({ lobby_code, player_id, name, color })
    Supabase-->>AppLobby: insert result
    AppLobby-->>AppLobby: state.me = { playerId, name, color }
Loading

Sequence diagram for lobby creation and auto-copy behavior

sequenceDiagram
    actor User
    participant UIPanels
    participant AppLobby
    participant AppShare
    participant LocaleManager

    User->>UIPanels: createLobby()
    UIPanels->>AppLobby: create(AppPoints.getA(), AppPoints.getB(), AppWeapons.get())
    AppLobby-->>UIPanels: code
    UIPanels->>AppShare: copyToClipboard(code)
    UIPanels->>LocaleManager: t('lobbyCreated')
    UIPanels->>LocaleManager: t('codeCopied')
    LocaleManager-->>UIPanels: messages
    UIPanels->>AppShare: showToast(message, 'success')
    AppShare-->>User: toast with code and copy info
Loading

File-Level Changes

Change Details Files
Introduce localization helper and use translated strings for host and player names.
  • Add local t(key) helper that delegates to window.LocaleManager.t if available, falling back to the key.
  • Replace hardcoded host name with localized 'hostName' string.
  • Generate player names using localized 'playerName' prefix instead of hardcoded Russian string.
js/features/lobby.js
Prevent duplicate/constraint errors when rejoining lobbies by cleaning up existing player entries and improving join logic.
  • On join, leave current lobby if already in a different lobby before proceeding.
  • Short-circuit join when already in the target lobby, returning existing lobby configuration without inserting a new player.
  • Delete any existing player record for the current player in the target lobby before inserting, avoiding 23505 unique constraint violations.
  • Base color assignment and player numbering only on other players (excluding current player) so counts are correct and state map is built from that filtered list.
js/features/lobby.js
Improve UX when creating a lobby by auto-copying the lobby code and updating toast message.
  • Call AppShare.copyToClipboard(code) after successful lobby creation to copy lobby code to clipboard.
  • Extend lobby created toast to include a localized 'codeCopied' message alongside the lobby code.
js/ui/panels.js

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • In join, the unconditional delete before insert may hide Supabase errors and introduce race conditions; consider checking for existing player and using upsert or at least handling potential delete failures explicitly.
  • The new t helper in lobby.js uses key as a fallback string, which may show raw keys like hostName to users; if you expect missing translations, consider a more user-friendly fallback or logging missing keys.
  • In panels.js, copyToClipboard is awaited but errors are not handled while the toast always claims the code was copied; consider wrapping the call in try/catch and adjusting the message based on success or failure.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `join`, the unconditional `delete` before insert may hide Supabase errors and introduce race conditions; consider checking for existing player and using `upsert` or at least handling potential delete failures explicitly.
- The new `t` helper in `lobby.js` uses `key` as a fallback string, which may show raw keys like `hostName` to users; if you expect missing translations, consider a more user-friendly fallback or logging missing keys.
- In `panels.js`, `copyToClipboard` is awaited but errors are not handled while the toast always claims the code was copied; consider wrapping the call in try/catch and adjusting the message based on success or failure.

## Individual Comments

### Comment 1
<location path="js/features/lobby.js" line_range="117-118" />
<code_context>
                 .from('players').select('*').eq('lobby_code', code);

-            const takenColors = (existingPlayers || []).map(p => p.color);
+            // ─── ФИКС 23505: удаляем старую запись игрока перед insert ───
+            await sb.from('players').delete().eq('lobby_code', code).eq('player_id', myId);
+
+            const others = (existingPlayers || []).filter(p => p.player_id !== myId);
</code_context>
<issue_to_address>
**issue (bug_risk):** Deletion before insert ignores potential Supabase errors.

The delete is a good approach to avoid 23505, but right now its result is ignored. If Supabase returns an error (network, permissions, etc.), you still proceed with the insert, which can re-trigger the constraint error or hide a failure. Consider checking `{ error }` from the delete and either abort the join or at least log the issue before continuing.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread js/features/lobby.js
Comment on lines +117 to +118
// ─── ФИКС 23505: удаляем старую запись игрока перед insert ───
await sb.from('players').delete().eq('lobby_code', code).eq('player_id', myId);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): Deletion before insert ignores potential Supabase errors.

The delete is a good approach to avoid 23505, but right now its result is ignored. If Supabase returns an error (network, permissions, etc.), you still proceed with the insert, which can re-trigger the constraint error or hide a failure. Consider checking { error } from the delete and either abort the join or at least log the issue before continuing.

@djzet
djzet merged commit b7d3b3b into main Aug 20, 2026
3 checks passed
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.

1 participant