native macOS codings agent orchestrator
6
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix Shelf empty state fallback

onevcat ca586734 e6fff5b7

+43 -4
+11
supacode/Features/Shelf/Models/ShelfBook.swift
··· 115 115 var openShelfBookID: Worktree.ID? { 116 116 selectedTerminalWorktree?.id 117 117 } 118 + 119 + /// The rendered book matching the current Shelf selection, if any. 120 + /// 121 + /// `openShelfBookID` can briefly point at a worktree/folder that has 122 + /// just been retired from `openedWorktreeIDs` after its last tab closes. 123 + /// Views should use this lookup rather than assuming a non-nil open ID 124 + /// means an open book is still present in `orderedShelfBooks()`. 125 + func openShelfBook(in books: [ShelfBook]) -> ShelfBook? { 126 + guard let openShelfBookID else { return nil } 127 + return books.first(where: { $0.id == openShelfBookID }) 128 + } 118 129 }
+5 -4
supacode/Features/Shelf/Views/ShelfView.swift
··· 32 32 let _ = shelfLogger.event("ShelfView.body") 33 33 let state = store.state 34 34 let books = state.orderedShelfBooks(customTitles: state.repositoryCustomTitles) 35 - let openBookID = state.openShelfBookID 36 - let openIndex = openBookID.flatMap { id in 37 - books.firstIndex(where: { $0.id == id }) 35 + let openBook = state.openShelfBook(in: books) 36 + let openBookID = openBook?.id 37 + let openIndex = openBook.flatMap { book in 38 + books.firstIndex(where: { $0.id == book.id }) 38 39 } 39 40 40 41 HStack(spacing: 0) { ··· 44 45 openBookArea(for: book, state: state) 45 46 } 46 47 } 47 - if openBookID == nil { 48 + if openBook == nil { 48 49 emptyOpenArea() 49 50 } 50 51 }
+27
supacodeTests/ShelfBookOrderingTests.swift
··· 182 182 #expect(state.openShelfBookID == worktree.id) 183 183 } 184 184 185 + @Test func openShelfBookReturnsNilWhenSelectedBookIsNoLongerRendered() { 186 + let rootURL = URL(fileURLWithPath: "/tmp/repo") 187 + let worktree = Worktree( 188 + id: "/tmp/repo", 189 + name: "main", 190 + detail: "", 191 + workingDirectory: rootURL, 192 + repositoryRootURL: rootURL 193 + ) 194 + let repository = Repository( 195 + id: rootURL.path(percentEncoded: false), 196 + rootURL: rootURL, 197 + name: "repo", 198 + worktrees: IdentifiedArray(uniqueElements: [worktree]) 199 + ) 200 + var state = RepositoriesFeature.State(repositories: [repository]) 201 + state.repositoryRoots = [rootURL] 202 + state.repositoryOrderIDs = [repository.id] 203 + state.selection = .worktree(worktree.id) 204 + state.openedWorktreeIDs = [] 205 + 206 + let books = state.orderedShelfBooks() 207 + #expect(books.isEmpty) 208 + #expect(state.openShelfBookID == worktree.id) 209 + #expect(state.openShelfBook(in: books) == nil) 210 + } 211 + 185 212 @Test func openShelfBookIDResolvesPlainFolderViaRepositoryID() { 186 213 let rootURL = URL(fileURLWithPath: "/tmp/plain") 187 214 let repository = Repository(