Skip to content

Conversation

evanpelle
Copy link
Collaborator

@evanpelle evanpelle commented Aug 19, 2025

Description:

During logout, the pattern was still set, so you would fail to join any game. This PR clears & unsets the chosen pattern on logout.

Please complete the following:

  • I have added screenshots for all UI updates
  • I process any text displayed to the user through translateText() and I've added it to the en.json file
  • I have added relevant tests to the test directory
  • I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced

Please put your Discord username so you can be contacted if a bug or regression is found:

evan

Copy link
Contributor

coderabbitai bot commented Aug 19, 2025

Walkthrough

Added null handling in TerritoryPatternsModal.onUserMe: when userMeResponse is null, it clears the selected pattern in userSettings, resets the internal selectedPattern to undefined, then continues to load patterns and run the existing restoration logic.

Changes

Cohort / File(s) Summary
Modal user data handling
src/client/TerritoryPatternsModal.ts
Handle null userMe response: clear userSettings.selectedPattern, reset internal selectedPattern, then load patterns and proceed with prior restore flow. No exported/public signatures changed.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User
  participant M as TerritoryPatternsModal
  participant US as UserService
  participant S as UserSettings
  participant PS as PatternsService

  U->>M: Open modal
  M->>US: onUserMe()
  US-->>M: userMeResponse (nullable)

  alt userMeResponse is null
    M->>S: Clear selectedPattern
    note right of M: Set internal selectedPattern = undefined
    M->>PS: Load patterns
    PS-->>M: patterns
    M->>M: Run existing restoration logic
  else userMeResponse not null
    M->>PS: Load patterns
    PS-->>M: patterns
    M->>M: Run existing restoration logic
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A pattern once chosen went wandering away,
The modal now checks if userMe’s gray.
If null, it sweeps clean, resets with care,
Then loads the threads woven in air.
Click, fetch, restore—simple and bright,
A tidy guard for a smoother night.

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@evanpelle evanpelle added this to the v25 milestone Aug 19, 2025
@evanpelle evanpelle merged commit 53f4a10 into v25 Aug 19, 2025
9 of 22 checks passed
@evanpelle evanpelle deleted the evan-unset-pattern-logout branch August 19, 2025 21:35
@github-project-automation github-project-automation bot moved this from Triage to Complete in OpenFront Release Management Aug 19, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/client/TerritoryPatternsModal.ts (1)

98-109: Bug: inconsistent null/undefined checks for pattern.product

Elsewhere you use product !== null to mean “locked/purchasable.” Here you use !== undefined, which will also treat free patterns (null) as blocked. Tooltip and blocking will be inconsistent.

Apply this diff to align semantics:

-  if (this.hoveredPattern && this.hoveredPattern.product !== undefined) {
+  if (this.hoveredPattern && this.hoveredPattern.product !== null) {

Also recommend typing Pattern['product'] as a strict union: Product | null (not undefined) and using === null/!== null consistently.

🧹 Nitpick comments (2)
src/client/TerritoryPatternsModal.ts (2)

112-168: DRY up “locked” logic and make intent explicit

You repeat pattern.product === null/!== null checks across classes, click handler, and purchase button. Compute once to avoid drift and make the code easier to read.

   private renderPatternButton(pattern: Pattern): TemplateResult {
-    const isSelected = this.selectedPattern?.name === pattern.name;
+    const isSelected = this.selectedPattern?.name === pattern.name;
+    const isLocked = pattern.product !== null; // product present => needs purchase

     return html`
       <div style="flex: 0 1 calc(25% - 1rem); max-width: calc(25% - 1rem);">
         <button
           class="border p-2 rounded-lg shadow text-black dark:text-white text-left w-full
           ${isSelected
             ? "bg-blue-500 text-white"
             : "bg-gray-100 hover:bg-gray-200 dark:bg-gray-800 dark:hover:bg-gray-700"}
-          ${pattern.product !== null ? "opacity-50 cursor-not-allowed" : ""}"
-          @click=${() =>
-            pattern.product === null && this.selectPattern(pattern)}
+          ${isLocked ? "opacity-50 cursor-not-allowed" : ""}"
+          @click=${() => !isLocked && this.selectPattern(pattern)}
           @mouseenter=${(e: MouseEvent) => this.handleMouseEnter(pattern, e)}
           @mousemove=${(e: MouseEvent) => this.handleMouseMove(e)}
           @mouseleave=${() => this.handleMouseLeave()}
         >
           ...
         </button>
-        ${pattern.product !== null
+        ${isLocked
           ? html`
             <button
               class="w-full mt-2 px-3 py-1 bg-green-500 hover:bg-green-600 text-white text-xs font-medium rounded transition-colors"
               @click=${(e: Event) => {
                 e.stopPropagation();
                 handlePurchase(pattern.product!.priceId);
               }}
             >
               ${translateText("territory_patterns.purchase")}
               (${pattern.product!.price})
             </button>
           `
           : null}
       </div>
     `;
   }

248-256: Nit: use self-closing img tag

Minor HTML hygiene for Lit templates.

-      <img src="${generatePreviewDataUrl(pattern, width, height)}"></img>
+      <img src="${generatePreviewDataUrl(pattern, width, height)}" />
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between d314344 and f8a4880.

📒 Files selected for processing (1)
  • src/client/TerritoryPatternsModal.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-06-22T21:51:14.990Z
Learnt from: devalnor
PR: openfrontio/OpenFrontIO#1248
File: src/client/graphics/layers/TerritoryInfoLayer.ts:20-20
Timestamp: 2025-06-22T21:51:14.990Z
Learning: In TerritoryInfoLayer.ts, the highlightedTerritory field uses both null and undefined intentionally: undefined represents initial state or inactive layer (Ctrl released), while null represents active layer with no territory being highlighted at cursor position. This distinction is important for proper state change detection.

Applied to files:

  • src/client/TerritoryPatternsModal.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Deploy to openfront.dev
  • GitHub Check: 🔬 Test
🔇 Additional comments (2)
src/client/TerritoryPatternsModal.ts (2)

49-52: Good fix: clearing selected pattern on logout matches the PR objective

Setting both UserSettings and local state to undefined on null user is correct and prevents stale selection from blocking gameplay.


53-59: patterns() accepts null—no extra guard needed

The patterns function in src/client/Cosmetics.ts is declared as

export async function patterns(
  userMe: UserMeResponse | null,
): Promise<Map<string, Pattern>> {  }

so it already accepts null. Likewise, UserSettings.setSelectedPatternName takes string | undefined, so passing undefined here is fine.

Optional: if you want to skip the patterns fetch for logged-out users, you could early-return after clearing state—but it’s not required for type safety.

scottanderson pushed a commit that referenced this pull request Aug 24, 2025
## Description:

During logout, the pattern was still set, so you would fail to join any
game. This PR clears & unsets the chosen pattern on logout.

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced

## Please put your Discord username so you can be contacted if a bug or
regression is found:

evan
This was referenced Aug 24, 2025
TheGiraffe3 pushed a commit that referenced this pull request Sep 4, 2025
## Description:

During logout, the pattern was still set, so you would fail to join any
game. This PR clears & unsets the chosen pattern on logout.

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced

## Please put your Discord username so you can be contacted if a bug or
regression is found:

evan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

1 participant