Skip to content

fix(marketplace): surface vote failures#370

Open
Zekbot001 wants to merge 2 commits into
profullstack:masterfrom
Zekbot001:money/ugig-marketplace-vote-errors
Open

fix(marketplace): surface vote failures#370
Zekbot001 wants to merge 2 commits into
profullstack:masterfrom
Zekbot001:money/ugig-marketplace-vote-errors

Conversation

@Zekbot001
Copy link
Copy Markdown

Summary

  • surface rejected and failed vote requests in directory, skill, MCP, and prompt widgets
  • clear stale errors on retry and reliably restore enabled controls through finally
  • cover all four public vote widgets with one table-driven regression

Paid task

https://ugig.net/gigs/abd6b2a0-e728-48cf-a46f-f99e419ed94e

Verification

  • pnpm exec vitest run src/components/MarketplaceVoteButton.test.tsx
  • pnpm exec eslint src/components/directory/DirectoryVoteButton.tsx src/components/mcp/McpVoteButton.tsx src/components/prompts/PromptVoteButton.tsx src/components/skills/SkillVoteButton.tsx src/components/MarketplaceVoteButton.test.tsx
  • git diff --check

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 31, 2026

Greptile Summary

This PR fixes silent vote failures across all four marketplace vote widgets (directory, MCP, prompt, skill) by adding an error state that is populated from API error responses or network rejections, and by moving setLoading(false) into a finally block to guarantee controls are always re-enabled.

  • Error surfacing: all four widgets now read the server's error field (falling back to a generic message) and display it via a role="alert" paragraph; errors are cleared on each new attempt.
  • Reliable loading reset: setLoading(false) moved to finally so it fires on the early-return error path, the success path, and the catch path without duplication.
  • Test coverage: a new table-driven test in MarketplaceVoteButton.test.tsx exercises the 403-response path for every widget, and a separate test covers the network-rejection (catch) path for the directory widget.

Confidence Score: 5/5

Safe to merge — the changes are a straightforward, well-contained fix that replaces silent failures with visible error feedback across four widgets.

All four widgets correctly surface API errors and network failures, reliably clear the loading state via finally, and prevent accidental form submission with explicit type="button". The new test suite validates the changed paths (403 responses for every widget, network rejection for directory). No logic regressions or missing guards were found in the changed code paths.

No files require special attention.

Important Files Changed

Filename Overview
src/components/directory/DirectoryVoteButton.tsx Adds error state, surfaces API errors, uses finally for reliable loading reset, and adds type="button" to both buttons; indentation of inner elements updated consistently.
src/components/mcp/McpVoteButton.tsx Same error-surfacing and finally improvements as DirectoryVoteButton; type="button" added; inner button indentation not re-aligned but JSX nesting is functionally correct.
src/components/prompts/PromptVoteButton.tsx Same error-surfacing and finally improvements as other widgets; type="button" added to both buttons.
src/components/skills/SkillVoteButton.tsx Same error-surfacing and finally improvements as other widgets; type="button" added to both buttons.
src/components/MarketplaceVoteButton.test.tsx New table-driven test covers the 403 error path for all four widgets, plus a network-rejection test for DirectoryVoteButton; correctly asserts alert text and re-enabled buttons after failure.

Sequence Diagram

sequenceDiagram
    participant User
    participant VoteButton
    participant API

    User->>VoteButton: click Upvote / Downvote
    VoteButton->>VoteButton: setLoading(true), setError(null)
    VoteButton->>API: "POST /api/{type}/{id}/vote"

    alt HTTP 2xx
        API-->>VoteButton: "{ upvotes, downvotes, score, user_vote }"
        VoteButton->>VoteButton: update vote counts
    else HTTP 4xx / 5xx
        API-->>VoteButton: "{ error: "..." } (or non-JSON)"
        VoteButton->>VoteButton: "setError(data.error || "Failed to update vote")"
    else Network failure
        API-->>VoteButton: fetch rejects (Error)
        VoteButton->>VoteButton: setError("Failed to update vote")
    end

    VoteButton->>VoteButton: finally → setLoading(false)
    VoteButton-->>User: re-enable buttons, show error alert (if any)
Loading

Reviews (2): Last reviewed commit: "fix(marketplace): declare vote action bu..." | Re-trigger Greptile

Comment thread src/components/mcp/McpVoteButton.tsx
Comment thread src/components/prompts/PromptVoteButton.tsx
Comment thread src/components/skills/SkillVoteButton.tsx
Comment thread src/components/MarketplaceVoteButton.test.tsx
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