The phone's list learns a second order — sort boards by name or by recency

A segmented control above the mobile board list, remembered across
launches: Name keeps the index's stable title order, Recent sorts by
content-change date descending with undated boards last and ties held
stable against refresh reshuffling.

Claude-Session: https://claude.ai/code/session_01SR4XGjmBE16ZUYWpfFHXwY
This commit is contained in:
2026-08-08 12:21:35 -04:00
parent 09a21cf5a0
commit 8cf1457814
4 changed files with 70 additions and 2 deletions
+28 -2
View File
@@ -6,12 +6,17 @@ import SwiftUI
/// Renders both of `BoardIndexStore.Phase`'s live states and, above the list, the iCloud notice
/// which is a row, not a wall (softened 2026-08-08). A phone with no account still has a device home
/// and therefore still has boards, so the missing half of the app is reported next to the half that
/// works rather than in place of it.
/// works rather than in place of it. A segmented control above the rows lets the list be sorted by
/// name or by most recent change, remembered across launches.
struct BoardsTabView: View {
@Environment(BoardIndexStore.self) private var index
@State private var isPresentingNewBoard = false
/// Persisted as its raw value, not the enum itself `AppStorage` needs a property-list type, and
/// the raw `String` is exactly what `BoardSortOrder` promises to keep stable.
@AppStorage("boardListSortOrder") private var sortOrderRaw = BoardSortOrder.name.rawValue
/// The board whose settings sheet is up. A value, not a URL: the sheet renders the row's own
/// summary, and a successful move dismisses it before the stale copy could matter.
@State private var boardInSettings: BoardSummary?
@@ -55,6 +60,19 @@ struct BoardsTabView: View {
}
}
/// The stored raw value as the enum, defaulting to `.name` on anything the store didn't write
/// itself an unset key or a stale raw value from a build that no longer has this case.
private var sortOrder: Binding<BoardSortOrder> {
Binding(
get: { BoardSortOrder(rawValue: sortOrderRaw) ?? .name },
set: { sortOrderRaw = $0.rawValue }
)
}
private var sortedBoards: [BoardSummary] {
sortOrder.wrappedValue.sorted(index.boards)
}
@ViewBuilder
private var content: some View {
switch index.phase {
@@ -75,7 +93,15 @@ struct BoardsTabView: View {
)
}
} else {
ForEach(index.boards) { board in
Picker("Sort", selection: sortOrder) {
Text("Name").tag(BoardSortOrder.name)
Text("Recent").tag(BoardSortOrder.recent)
}
.pickerStyle(.segmented)
.listRowBackground(Color.clear)
.listRowSeparator(.hidden)
ForEach(sortedBoards) { board in
NavigationLink(value: BoardRoute.lanes(boardRoot: board.rootURL)) {
BoardSummaryRow(board: board)
}