Skip to content

LVT-40: Check if match exists and also switch alliance if selected wrong#84

Open
jackattack-4 wants to merge 2 commits into
mainfrom
jackshim415/lvt-40-warn-user-if-manually-entered-match-info-doesnt-match
Open

LVT-40: Check if match exists and also switch alliance if selected wrong#84
jackattack-4 wants to merge 2 commits into
mainfrom
jackshim415/lvt-40-warn-user-if-manually-entered-match-info-doesnt-match

Conversation

@jackattack-4

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI 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.

Pull request overview

Adds a pre-flight “match existence” check before starting scouting, and attempts to auto-correct the selected alliance color based on server data. This integrates a new API helper and uses network state to avoid running the check when not on Wi‑Fi.

Changes:

  • Added @react-native-community/netinfo dependency to support connectivity checks.
  • Introduced lib/lovatAPI/checkMatch.ts to call /v1/manager/checkmatch (with Wi‑Fi gating).
  • Updated the Home screen “Scout this match” action to (a) confirm match existence and (b) override alliance color when returned by the server.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 4 comments.

File Description
package.json Adds NetInfo dependency needed by the new match-check helper.
package-lock.json Locks NetInfo dependency resolution for reproducible installs.
lib/lovatAPI/checkMatch.ts New helper for checking match existence and returning alliance info.
app/home.tsx Uses checkMatch before scouting; prompts on failures and switches alliance color when available.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/lovatAPI/checkMatch.ts
Comment thread app/home.tsx Outdated
Comment thread app/home.tsx
Comment thread app/home.tsx Outdated

@MangoSwirl MangoSwirl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems like a very well thought-out implementation that would solve lots of issues at comps. I'm impressed.

The one issue I can see is that we're requiring a distinct network call every time new match info is entered. If I were to design this feature, I would use a single endpoint that fetches the entire match schedule to be saved on-device. That way, even if there are connection issues later, the feature would continue to work. We could also visibly switch the alliance color in the picker as the user is entering the team number without bombarding the server with requests.

Using API calls to update a local copy of the data is actually how we're currently handling scouter schedules, tourhaments, etc (see lib/services.ts) and there's a pretty straightforward system for it.

const state = await NetInfo.fetch();

if (!state.isConnected) {
return { exists: true, alliance: alliance };

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Having exists: true mean "we don't know whether it exists" seems counterintuitive to me

Comment on lines +40 to +44
alliance: exists
? responseSchema.parse(await response.json())?.alliance === "red"
? AllianceColor.Red
: AllianceColor.Blue
: alliance,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't see any client-side guard for if the server responds with 200 but with a null body. In that case the alliance color would always be blue.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also nit: I'm very against using nested ternaries. There's almost always a more readable way to write the code more reminiscent of how a human would explain the logic.

teamNumber: number,
alliance: AllianceColor,
) => {
const state = await NetInfo.fetch();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Checking the network state isn't super necessary to do. The pattern we typically follow is just surrounding the fetch call with a try/catch block.

I assume what you're trying to do here is have different behavior for a server-side failure (actual problem) vs connectivity failure (expected from time to time)

Comment thread app/home.tsx
}
reportState.scoutMatch({
...meta,
allianceColor: match.alliance,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If the user selects the incorrect alliance color in the manual match builder, it'll be silently corrected when the user taps "Scout this match". Effectively, this means that if the user has an internet connection, then the alliance color selector does nothing and will likely confuse users (a la elevator door close button)

We're also making it appear as though manually selecting an alliance color is always necessary when we could easily be saving users an extra tap.

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.

3 participants