Skip to content

Fix recent stories showing only 1 record and add Load More pagination - #55

Merged
santoshyadavdev merged 2 commits into
mainfrom
santoshyadavdev-fix-recent-stories-limit
Jul 16, 2026
Merged

Fix recent stories showing only 1 record and add Load More pagination#55
santoshyadavdev merged 2 commits into
mainfrom
santoshyadavdev-fix-recent-stories-limit

Conversation

@santoshyadavdev

@santoshyadavdev santoshyadavdev commented Jul 16, 2026

Copy link
Copy Markdown
Owner

Why

The "Recent Stories" section on the dashboard was only showing a single story even though more than 10 existed in KV. This happened because the __recent_stories_index__ (introduced for fast lookups) contained only stories created after the index feature was deployed. Once the index existed -- even with just 1 entry -- the legacy KV scan fallback was completely skipped, hiding all older stories.

Additionally, the default limit was only 5, with no way to see more.

What changed

Server-side fix (server.ts):

  • When the recent stories index has fewer entries than the requested limit, the handler now falls through to the legacy KV scan and merges results, deduplicating by key. This ensures pre-index stories are still returned.
  • Added offset query parameter for pagination and a hasMore boolean in the response.
  • Bumped the default limit from 5 to 10 (max from 20 to 50).

Frontend (story.service.ts + dashboard.component.ts):

  • Service now accepts an offset parameter.
  • Dashboard loads 10 stories on init instead of 5.
  • Added a "Load More" button that fetches the next 10 stories and appends them, with a loading spinner while fetching.

Notes

  • The early-return optimization is preserved: if the index has enough entries for the requested page, the legacy scan is skipped entirely.
  • The pre-existing test failure (ThemeService) is unrelated to these changes.

Summary by CodeRabbit

  • New Features
    • Added pagination to the dashboard’s Recent Stories list.
    • Added a “Load More” option with loading feedback when additional stories are available.
    • Recent stories now load in batches of 10 and continue seamlessly as more are requested.
    • Improved recent-story retrieval to combine available sources and indicate when more stories exist.

santoshyadavdev and others added 2 commits July 16, 2026 22:24
When the recent stories index exists but has fewer entries than the
requested limit (e.g. only stories created after the index feature
was deployed), the handler now falls through to the legacy KV scan
to pick up older pre-index stories. Duplicate entries are skipped
by tracking indexed keys in a Set.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
- Server: add offset query param, return hasMore flag, increase default
  limit from 5 to 10 (max 50)
- Service: pass offset param to API
- Dashboard: load 10 stories initially, show 'Load More' button when
  more are available, append next page on click with loading spinner

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
commitstory 8e4e76f Commit Preview URL

Branch Preview URL
Jul 16 2026, 08:30 PM

@santoshyadavdev
santoshyadavdev merged commit 9bccc5a into main Jul 16, 2026
2 of 3 checks passed
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: db4f0c40-a2ba-46e3-b300-4a83c8558c57

📥 Commits

Reviewing files that changed from the base of the PR and between ac2dee2 and 8e4e76f.

📒 Files selected for processing (3)
  • yourstory/src/app/core/services/story.service.ts
  • yourstory/src/app/pages/dashboard/dashboard.component.ts
  • yourstory/src/server.ts

📝 Walkthrough

Walkthrough

Recent Stories now support paginated requests and responses. The server merges indexed and legacy results, while the dashboard appends additional pages through a loading-aware “Load More” control.

Changes

Recent Stories Pagination

Layer / File(s) Summary
Paginated recent stories API
yourstory/src/server.ts
The endpoint accepts capped limit and offset values, merges and deduplicates indexed and legacy stories, then returns a page with hasMore.
Story service pagination contract
yourstory/src/app/core/services/story.service.ts
getRecentStories sends both pagination parameters and RecentStoriesResponse exposes optional hasMore.
Dashboard load-more flow
yourstory/src/app/pages/dashboard/dashboard.component.ts
Dashboard state tracks pagination and loading, appends fetched stories, and displays a conditional loading-aware Load More button.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant DashboardComponent
  participant StoryService
  participant handleRecentStories
  participant KV
  DashboardComponent->>StoryService: Request recent stories page
  StoryService->>handleRecentStories: Send limit and offset
  handleRecentStories->>KV: Read indexed and legacy stories
  KV-->>handleRecentStories: Return story data
  handleRecentStories-->>StoryService: Return stories and hasMore
  StoryService-->>DashboardComponent: Update list and pagination state
  DashboardComponent->>StoryService: Request next page on Load More
Loading

Suggested labels: enhancement

Poem

I’m a rabbit with pages to hop,
More stories arrive with each stop.
The index and keys join the queue,
While a spinner says, “Fetching for you!”
Click Load More—then onward we go!

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch santoshyadavdev-fix-recent-stories-limit

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


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

@coderabbitai coderabbitai Bot added the enhancement New feature or request label Jul 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant