Skip to content

Conversation

@mltbnz
Copy link
Member

@mltbnz mltbnz commented Dec 29, 2025

Summary

Fixes two UX issues in the Mastodon feed refresh mechanism:

  1. Refresh was incorrectly paginating instead of fetching the latest toots

Problem

Issue 1: Refresh Pagination Bug

When users pulled to refresh, the feed would load the next page of older toots instead of fetching the latest toots from the beginning. This happened because .fetchData was capturing lastId = state.toots.last?.id for both initial load and refresh actions.

Solution

1. Separate Refresh Logic from Pagination

Updated TootFeedFeature.swift:

  • .refresh action: Sets isRefreshing = true (does NOT clear toots)
  • .fetchData action: Always fetches with nil lastId to get latest toots
  • .loadNextPage action: Continues to correctly use lastId for pagination

Before:

case .fetchData:
  return .run { [lastId = state.toots.last?.id] send in
    await send(.fetchDataResponse(Result { try await tootService.getToots(lastId) }))
  }

After:

case .refresh:
  state.isRefreshing = true
  return .send(.fetchData)

case .fetchData:
  return .run { send in
    await send(.fetchDataResponse(Result { try await tootService.getToots(nil) }))
  }

Test Coverage

Initial Load Tests

  • Verifies initial load fetches with nil lastId
  • Ensures onAppear doesn't refetch when toots exist

Refresh Tests

  • Confirms refresh keeps toots visible during refresh
  • Validates refresh fetches with nil lastId (not paginating)
  • Ensures refresh doesn't use last toot ID

Pagination Tests

  • Verifies load next page uses lastId correctly
  • Prevents loading when already loading
  • Sets hasMore = false on empty response

Error Handling Tests

  • Handles fetch errors gracefully
  • Stops refreshing on error

Behavior Changes

Action Before After
Initial load Used lastId ❌ Fetches latest with nil
Pull to refresh Paginated from last toot ❌ Fetches latest, keeps content visible ✅
Load next page Correctly paginated ✅ Still correctly paginated ✅

UX Improvements

Aspect Before After
Visual feedback Flash of empty state Smooth transition
Content visibility Briefly hidden Always visible
User experience Jarring Standard iOS pattern
Follows iOS HIG No Yes ✅

Testing

Run the test suite:

xcodebuild test -scheme CriticalMapsKit -destination 'platform=iOS Simulator,name=iPhone 17 Pro' -only-testing:MastodonFeedFeatureTests/TootFeedFeatureTests

@mltbnz mltbnz changed the title fix pagination issue when refreshing mastodon feed FIX - pagination issue when refreshing mastodon feed Dec 29, 2025
@mltbnz mltbnz marked this pull request as ready for review January 3, 2026 12:39
@mltbnz mltbnz requested a review from a team as a code owner January 3, 2026 12:39
@mltbnz mltbnz merged commit 76b012e into main Jan 3, 2026
2 checks passed
@mltbnz mltbnz deleted the fix/mastodon-feed-refresh-paging branch January 3, 2026 13:44
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.

2 participants