Skip to content

Comments

feat: sort slides listing by date DESC, title DESC as tiebreaker#81

Open
claudinethelobster wants to merge 1 commit intoDEVxNetwork:mainfrom
claudinethelobster:feat/sort-slides-by-date-desc-alpha
Open

feat: sort slides listing by date DESC, title DESC as tiebreaker#81
claudinethelobster wants to merge 1 commit intoDEVxNetwork:mainfrom
claudinethelobster:feat/sort-slides-by-date-desc-alpha

Conversation

@claudinethelobster
Copy link
Contributor

Summary

Updates the slides listing to use a deterministic sort order:

  1. Date DESC (newest first) — using the timestamp ISO field from each slide's metadata.json
  2. Title alphabetical DESC — as a tiebreaker when timestamps are equal

Changes

app/slides/slidesData.ts

  • Added exported compareSlides(a, b) comparator function
  • Updated getAllSlides() to .sort(compareSlides) before returning

Comparator logic:

  • Parses timestamps via Date.parse()
  • Valid timestamps sort newer-first (bTime - aTime)
  • Tiebreaker: b.title.localeCompare(a.title) (DESC)
  • Missing/invalid timestamps fall to the end, with title DESC tiebreaker among themselves

app/slides/slidesData.test.ts (new)

  • 7 vitest unit tests covering: newer-first, title-DESC tiebreak, identical slides, missing timestamp fallback, invalid timestamp fallback, two invalid timestamps, and a full array integration test
  • All 7 tests pass ✅

package.json

  • Added vitest devDependency
  • Added "test": "vitest run" script

Test Results

✓ app/slides/slidesData.test.ts (7 tests) 10ms
Test Files  1 passed (1)
Tests  7 passed (7)

- Add compareSlides() comparator to slidesData.ts
- Primary sort: timestamp DESC (newest first)
- Tiebreaker: title alphabetical DESC
- Graceful fallback: slides with missing/invalid timestamps sort to end
- Wire sort into getAllSlides()
- Add slidesData.test.ts with 7 vitest unit tests covering all cases
- Add vitest devDependency + test script to package.json
Copy link
Contributor

@samholmes samholmes left a comment

Choose a reason for hiding this comment

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

Remove vitest. If you want to write tests, write it in a dedicated tests/ directory and not app/ directory and use bun's test framework (less dependencies).

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