Skip to content

fix(feed): show poll results to anonymous viewers#365

Open
Zekbot001 wants to merge 1 commit into
profullstack:masterfrom
Zekbot001:money/ugig-poll-login-state
Open

fix(feed): show poll results to anonymous viewers#365
Zekbot001 wants to merge 1 commit into
profullstack:masterfrom
Zekbot001:money/ugig-poll-login-state

Conversation

@Zekbot001
Copy link
Copy Markdown

Summary

  • pass the actual viewer login state from PostCard into PollDisplay
  • show read-only poll results to anonymous feed viewers instead of vote controls that silently fail with 401
  • cover anonymous and authenticated integration paths with focused component tests

Paid task

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

Verification

  • pnpm exec vitest run src/components/feed/PostCard.test.tsx
  • pnpm exec eslint src/components/feed/PostCard.tsx src/components/feed/PostCard.test.tsx
  • git diff --check

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 31, 2026

Greptile Summary

This PR fixes a one-line bug in PostCard where PollDisplay was always receiving isLoggedIn={true}, causing anonymous viewers to see vote buttons that would silently fail with a 401. The fix correctly derives the boolean from the optional currentUserId prop using !!currentUserId, matching the pattern already used elsewhere in the same component (e.g., canEdit).

  • PostCard.tsx: isLoggedIn={true}isLoggedIn={!!currentUserId} — single-character-class change that wires real auth state into PollDisplay.
  • PostCard.test.tsx: New test file with two focused cases verifying that anonymous viewers receive isLoggedIn: false and authenticated viewers receive isLoggedIn: true, using a minimal poll post fixture and a mock of PollDisplay.

Confidence Score: 5/5

Safe to merge — the change is a single targeted prop correction backed by focused tests.

The fix is minimal and self-contained: one prop expression corrected from a hardcoded true to !!currentUserId, matching the identical pattern already used in canEdit on line 46 of the same file. PollDisplay already handled isLoggedIn: false correctly (read-only result bars), so no downstream logic needed adjustment. The new tests cover both anonymous and authenticated render paths at the right level of abstraction.

No files require special attention.

Important Files Changed

Filename Overview
src/components/feed/PostCard.tsx Single-line fix: isLoggedIn={true} → isLoggedIn={!!currentUserId}, correctly wiring the optional currentUserId prop into PollDisplay's login-state gate.
src/components/feed/PostCard.test.tsx New integration test file covering both anonymous (no currentUserId) and authenticated (currentUserId present) rendering paths for poll posts; mocks PollDisplay and verifies isLoggedIn propagation.

Sequence Diagram

sequenceDiagram
    participant Parent as Page/Feed
    participant PC as PostCard
    participant PD as PollDisplay
    participant API as /api/posts/:id/poll/vote

    Note over Parent,PC: Anonymous viewer (currentUserId = undefined)
    Parent->>PC: render PostCard without currentUserId
    PC->>PD: "PollDisplay isLoggedIn=false"
    PD->>API: GET fetch results
    API-->>PD: options, total_votes
    Note over PD: showResults=true, renders read-only bars

    Note over Parent,PC: Authenticated viewer (currentUserId = user-1)
    Parent->>PC: render PostCard with currentUserId
    PC->>PD: "PollDisplay isLoggedIn=true"
    PD->>API: GET fetch results
    API-->>PD: options, total_votes, user_vote
    alt user has already voted
        Note over PD: showResults=true, result bars
    else user has not voted
        Note over PD: showResults=false, vote buttons
        PD->>API: POST option_id on click
        API-->>PD: updated results
    end
Loading

Reviews (1): Last reviewed commit: "fix(feed): show poll results to anonymou..." | Re-trigger Greptile

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