Conversation
Reviewer's GuideFixes 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 flowsequenceDiagram
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 }
Sequence diagram for lobby creation and auto-copy behaviorsequenceDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In
join, the unconditionaldeletebefore insert may hide Supabase errors and introduce race conditions; consider checking for existing player and usingupsertor at least handling potential delete failures explicitly. - The new
thelper inlobby.jsuseskeyas a fallback string, which may show raw keys likehostNameto users; if you expect missing translations, consider a more user-friendly fallback or logging missing keys. - In
panels.js,copyToClipboardis 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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| // ─── ФИКС 23505: удаляем старую запись игрока перед insert ─── | ||
| await sb.from('players').delete().eq('lobby_code', code).eq('player_id', myId); |
There was a problem hiding this comment.
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.
Summary by Sourcery
Improve lobby creation and joining by handling player membership reliably and localizing participant names.
New Features:
Bug Fixes:
Enhancements: