diff --git a/Piper/Sources/Logic/Models/Repository.swift b/Piper/Sources/Logic/Models/Repository.swift index ba64914..2abe47a 100644 --- a/Piper/Sources/Logic/Models/Repository.swift +++ b/Piper/Sources/Logic/Models/Repository.swift @@ -15,24 +15,34 @@ final class Repository { // MARK: Properties @Attribute(.unique) var path: URL - + var addedAt: Date - var sortOrder: Int + var active: Bool // MARK: Initialisers init( _ path: URL, - sortOrder: Int, + active: Bool = true, addedAt: Date = .now ) { self.path = path self.addedAt = addedAt - self.sortOrder = sortOrder + self.active = active } // MARK: Computed - @Transient var name: String { path.lastPathComponent } + @Transient var folder: String { + path.deletingLastPathComponent().relativePath + } + + @Transient var name: String { + path.lastPathComponent + } } + +// MARK: - Identifiable + +extension Repository: Identifiable {} diff --git a/Piper/Sources/Previews/Extensions/Repository+Samples.swift b/Piper/Sources/Previews/Extensions/Repository+Samples.swift index f275d5b..5757343 100644 --- a/Piper/Sources/Previews/Extensions/Repository+Samples.swift +++ b/Piper/Sources/Previews/Extensions/Repository+Samples.swift @@ -18,18 +18,16 @@ extension Repository { let context = container.mainContext context.insert(Repository( - URL(filePath: "/full/path/to/repository/name-0.git"), - sortOrder: 0 + URL(filePath: "/full/path/to/repository/name-0.git") )) context.insert(Repository( URL(filePath: "/full/path/to/repository/name-1.git"), - sortOrder: 1 + active: false )) context.insert(Repository( - URL(filePath: "/full/path/to/repository/name-2.git"), - sortOrder: 2 + URL(filePath: "/full/path/to/repository/name-2.git") )) } diff --git a/Piper/Sources/UI/Components/ListItem.swift b/Piper/Sources/UI/Components/ListItem.swift index 0b97888..64d2f99 100644 --- a/Piper/Sources/UI/Components/ListItem.swift +++ b/Piper/Sources/UI/Components/ListItem.swift @@ -62,24 +62,15 @@ struct ItemLabelStyle: LabelStyle { #Preview("List Item component") { List { - ListItem( - repository: .init( - .init(filePath: "/full/path/to/repository/name.git")!, - sortOrder: 0 - ) - ) - ListItem( - repository: .init( - .init(filePath: "/full/path/to/repository/name.git")!, - sortOrder: 0 - ) - ) - ListItem( - repository: .init( - .init(filePath: "/full/path/to/repository/name.git")!, - sortOrder: 0 - ) - ) + ListItem(repository: .init( + .init(filePath: "/full/path/to/repository/name.git")! + )) + ListItem(repository: .init( + .init(filePath: "/full/path/to/repository/name.git")! + )) + ListItem(repository: .init( + .init(filePath: "/full/path/to/repository/name.git")! + )) } .frame(width: 400, height: 220) }