Skip to content

Sort sprite list by recently updated by default#116

Open
mcintyre94 wants to merge 1 commit intomainfrom
sort-sprite-list-now-c8dcb258
Open

Sort sprite list by recently updated by default#116
mcintyre94 wants to merge 1 commit intomainfrom
sort-sprite-list-now-c8dcb258

Conversation

@mcintyre94
Copy link
Copy Markdown
Owner

Summary

  • Decodes updated_at from the Sprites API response into a new updatedAt: Date? field on Sprite
  • Adds a "Recently Updated" sort option to the dashboard, ordered by updated_at descending
  • Makes "Recently Updated" the default sort (previously "Newest" / by created_at)
  • Extracts a shared sortedByDate(_:) helper on [Sprite] to avoid duplicating the date-sort closure

Test plan

  • Sprite list sorts by updated_at by default on launch
  • Switching to "Newest" still sorts by created_at
  • Switching to "Name" still sorts alphabetically
  • Sprites with no updated_at sort to the bottom

🤖 Generated with Claude Code

Adds `updated_at` from the API response to the Sprite model and introduces
a "Recently Updated" sort option (now the default) that orders sprites by
when they were last modified.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
@claude
Copy link
Copy Markdown

claude bot commented Mar 29, 2026

Code review

2 issues found — both related to missing unit tests per CLAUDE.md.


1. Missing unit tests for sortedByDate(_:) (Wisp/Utilities/Extensions.swift)

The new Array<Sprite>.sortedByDate(_:) helper has non-trivial logic (descending sort with .distantPast fallback for nil dates) but no tests were added to WispTests/ExtensionsTests.swift.

extension Array where Element == Sprite {
func sortedByDate(_ keyPath: KeyPath<Sprite, Date?>) -> [Sprite] {
sorted { ($0[keyPath: keyPath] ?? .distantPast) > ($1[keyPath: keyPath] ?? .distantPast) }
}
}

Suggested test cases:

  • Sprites with non-nil dates sort descending (most recent first)
  • Sprites with nil dates sort to the end (treated as .distantPast)
  • Mixed nil/non-nil dates sort correctly
  • Empty array returns empty

2. Missing unit tests for updatedAt decoding (Wisp/Models/API/Sprite.swift)

The new updatedAt field adds decoding/encoding logic to the Sprite model, but WispTests/APIModelTests.swift was not updated.

url = try container.decodeIfPresent(String.self, forKey: .url)
createdAt = try container.decodeIfPresent(Date.self, forKey: .createdAt)
updatedAt = try container.decodeIfPresent(Date.self, forKey: .updatedAt)
urlSettings = try container.decodeIfPresent(UrlSettings.self, forKey: .urlSettings)
}

The existing model tests should be extended to assert:

  • updated_at in JSON decodes into a non-nil updatedAt
  • A missing updated_at key yields updatedAt == nil
  • Round-trip encode/decode preserves the value

CLAUDE.md rule: "Add new unit tests when adding or modifying logic (models, parsers, utilities, view models)"

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