Replaced the FileSystemItemable protocol with the FileSystemItem one for the Browse module.

This commit is contained in:
Javier Cicchelli 2022-12-16 17:20:19 +01:00
parent 228438454f
commit 13010816e1
9 changed files with 13 additions and 29 deletions

View File

@ -8,7 +8,7 @@
import Foundation import Foundation
struct Document { struct Document: FileSystemItem {
// MARK: Properties // MARK: Properties
@ -35,7 +35,3 @@ struct Document {
} }
} }
// MARK: - FileSystemItemable
extension Document: FileSystemItemable {}

View File

@ -6,7 +6,7 @@
// Copyright © 2022 Röck+Cöde. All rights reserved. // Copyright © 2022 Röck+Cöde. All rights reserved.
// //
public struct Folder { public struct Folder: FileSystemItem {
// MARK: Properties // MARK: Properties
@ -24,11 +24,3 @@ public struct Folder {
} }
} }
// MARK: - FileSystemItemable
extension Folder: FileSystemItemable {}
// MARK: - Equatable
extension Folder: Equatable {}

View File

@ -6,11 +6,7 @@
// Copyright © 2022 Röck+Cöde. All rights reserved. // Copyright © 2022 Röck+Cöde. All rights reserved.
// //
protocol FileSystemItem { protocol FileSystemItem: Identifiable, Hashable, Equatable {
var id: String { get } var id: String { get }
var name: String { get } var name: String { get }
} }
// MARK: - Type aliases
typealias FileSystemItemable = FileSystemItem & Identifiable & Hashable

View File

@ -22,7 +22,7 @@ struct GetItemsUseCase {
id: String, id: String,
username: String, username: String,
password: String password: String
) async throws -> [any FileSystemItemable] { ) async throws -> [any FileSystemItem] {
let items = try await apiService.getItems( let items = try await apiService.getItems(
id: id, id: id,
credentials: .init( credentials: .init(
@ -32,7 +32,7 @@ struct GetItemsUseCase {
) )
return items return items
.compactMap { item -> any FileSystemItemable in .compactMap { item -> any FileSystemItem in
if item.isDirectory { if item.isDirectory {
return Folder( return Folder(
id: item.id, id: item.id,

View File

@ -13,7 +13,7 @@ struct DocumentItem: View {
// MARK: Properties // MARK: Properties
let item: FileSystemItem let item: any FileSystemItem
let select: ActionClosure let select: ActionClosure
let download: ActionClosure let download: ActionClosure
let delete: ActionClosure let delete: ActionClosure

View File

@ -13,7 +13,7 @@ struct FolderItem: View {
// MARK: Properties // MARK: Properties
let item: FileSystemItem let item: any FileSystemItem
let select: ActionClosure let select: ActionClosure
let delete: ActionClosure let delete: ActionClosure

View File

@ -22,7 +22,7 @@ extension View {
} }
func delete( func delete(
item: Binding<(any FileSystemItemable)?>, item: Binding<(any FileSystemItem)?>,
) -> some View { ) -> some View {
modifier(DeleteItemViewModifier(item: item)) modifier(DeleteItemViewModifier(item: item))
} }

View File

@ -15,7 +15,7 @@ struct DeleteItemViewModifier: ViewModifier {
// MARK: Bindings // MARK: Bindings
@Binding var item: (any FileSystemItemable)? @Binding var item: (any FileSystemItem)?
// MARK: Body // MARK: Body

View File

@ -19,9 +19,9 @@ public struct BrowseView: View {
// MARK: States // MARK: States
@State private var status: ViewStatus = .loading @State private var status: ViewStatus = .loading
@State private var items: [any FileSystemItemable] = [] @State private var items: [any FileSystemItem] = []
@State private var stack: Stack? @State private var stack: Stack?
@State private var itemToDelete: (any FileSystemItemable)? @State private var itemToDelete: (any FileSystemItem)?
// MARK: Properties // MARK: Properties
@ -114,7 +114,7 @@ private extension BrowseView {
// MARK: Functions // MARK: Functions
@ViewBuilder func makeFolderItem( @ViewBuilder func makeFolderItem(
for item: any FileSystemItemable for item: any FileSystemItem
) -> some View { ) -> some View {
if let folder = item as? Folder { if let folder = item as? Folder {
FolderItem(item: item) { FolderItem(item: item) {
@ -139,7 +139,7 @@ private extension BrowseView {
} }
@ViewBuilder func makeDocumentItem( @ViewBuilder func makeDocumentItem(
for item: any FileSystemItemable for item: any FileSystemItem
) -> some View { ) -> some View {
if let document = item as? Document { if let document = item as? Document {
DocumentItem(item: item) { DocumentItem(item: item) {