Work done so far on the ContentView and the BrowseView views.
This commit is contained in:
parent
08edb6b7ec
commit
0ba14e85fc
@ -32,17 +32,12 @@ struct ContentView: View {
|
|||||||
// MARK: Body
|
// MARK: Body
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationView {
|
Container(user: $user) {
|
||||||
BrowseView(folder: .init(
|
// TODO: create a new folder
|
||||||
id: user?.rootFolder.id,
|
} uploadFile: {
|
||||||
name: user?.rootFolder.name
|
// TODO: upload a new file
|
||||||
)) {
|
} showProfile: {
|
||||||
// ...
|
showSheet = .profile
|
||||||
} uploadFile: {
|
|
||||||
// ...
|
|
||||||
} showProfile: {
|
|
||||||
showSheet = .profile
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.sheet(item: $showSheet) { sheet in
|
.sheet(item: $showSheet) { sheet in
|
||||||
switch sheet {
|
switch sheet {
|
||||||
@ -65,6 +60,41 @@ struct ContentView: View {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Views
|
||||||
|
|
||||||
|
private extension ContentView {
|
||||||
|
struct Container: View {
|
||||||
|
|
||||||
|
// MARK: Properties
|
||||||
|
|
||||||
|
@Binding var user: User?
|
||||||
|
let createFolder: ActionClosure
|
||||||
|
let uploadFile: ActionClosure
|
||||||
|
let showProfile: ActionClosure
|
||||||
|
|
||||||
|
// MARK: Body
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
if let user {
|
||||||
|
NavigationView {
|
||||||
|
BrowseView(
|
||||||
|
folder: .init(
|
||||||
|
id: user.rootFolder.id,
|
||||||
|
name: user.rootFolder.name
|
||||||
|
),
|
||||||
|
createFolder: createFolder,
|
||||||
|
uploadFile: uploadFile,
|
||||||
|
showProfile: showProfile
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
EmptyView()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Helpers
|
// MARK: - Helpers
|
||||||
|
|
||||||
private extension ContentView {
|
private extension ContentView {
|
||||||
|
@ -28,3 +28,7 @@ public struct Folder {
|
|||||||
// MARK: - ModelIdentifiable
|
// MARK: - ModelIdentifiable
|
||||||
|
|
||||||
extension Folder: ModelIdentifiable {}
|
extension Folder: ModelIdentifiable {}
|
||||||
|
|
||||||
|
// MARK: - Equatable
|
||||||
|
|
||||||
|
extension Folder: Equatable {}
|
||||||
|
@ -7,10 +7,19 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import DataModels
|
import DataModels
|
||||||
|
import KeychainStorage
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
public struct BrowseView: View {
|
public struct BrowseView: View {
|
||||||
|
|
||||||
|
// MARK: Storages
|
||||||
|
|
||||||
|
@KeychainStorage(key: .KeychainStorage.account) private var account: Account?
|
||||||
|
|
||||||
|
// MARK: States
|
||||||
|
|
||||||
|
@State private var items: [any ModelIdentifiable] = []
|
||||||
|
|
||||||
// MARK: Properties
|
// MARK: Properties
|
||||||
|
|
||||||
private let folder: Folder
|
private let folder: Folder
|
||||||
@ -18,6 +27,8 @@ public struct BrowseView: View {
|
|||||||
private let uploadFile: ActionClosure
|
private let uploadFile: ActionClosure
|
||||||
private let showProfile: ActionClosure
|
private let showProfile: ActionClosure
|
||||||
|
|
||||||
|
private let getItems: GetItemsUseCase = .init()
|
||||||
|
|
||||||
// MARK: Initialisers
|
// MARK: Initialisers
|
||||||
|
|
||||||
public init(
|
public init(
|
||||||
@ -36,92 +47,102 @@ public struct BrowseView: View {
|
|||||||
|
|
||||||
public var body: some View {
|
public var body: some View {
|
||||||
List {
|
List {
|
||||||
Group {
|
ForEach(items, id: \.id) { item in
|
||||||
Group {
|
if let folder = item as? Folder {
|
||||||
FolderItem(name: "Some folder #1 name")
|
FolderItem(name: folder.name)
|
||||||
FolderItem(name: "Some folder #2 name")
|
} else if let file = item as? File {
|
||||||
FolderItem(name: "Some folder #3 name")
|
|
||||||
FolderItem(name: "Some folder #4 name")
|
|
||||||
FolderItem(name: "Some folder #5 name")
|
|
||||||
FolderItem(name: "Some folder #6 name")
|
|
||||||
FolderItem(name: "Some folder #7 name")
|
|
||||||
}
|
|
||||||
Group {
|
|
||||||
DocumentItem(
|
DocumentItem(
|
||||||
name: "Some document #1 name",
|
name: file.name,
|
||||||
lastModified: "3 months ago",
|
lastModified: "-",
|
||||||
fileSize: "1,23 Mbytes"
|
fileSize: "-"
|
||||||
)
|
|
||||||
DocumentItem(
|
|
||||||
name: "Some document #2 name",
|
|
||||||
lastModified: "2 years ago",
|
|
||||||
fileSize: "123 Kbytes"
|
|
||||||
)
|
|
||||||
DocumentItem(
|
|
||||||
name: "Some document #3 name",
|
|
||||||
lastModified: "13 days ago",
|
|
||||||
fileSize: "12 bytes"
|
|
||||||
)
|
|
||||||
DocumentItem(
|
|
||||||
name: "Some document #4 name",
|
|
||||||
lastModified: "13 hours ago",
|
|
||||||
fileSize: "12,3 Gbytes"
|
|
||||||
)
|
|
||||||
DocumentItem(
|
|
||||||
name: "Some document #5 name",
|
|
||||||
lastModified: "13 minutes ago",
|
|
||||||
fileSize: "123 Tbytes"
|
|
||||||
)
|
|
||||||
DocumentItem(
|
|
||||||
name: "Some document #6 name",
|
|
||||||
lastModified: "13 seconds ago",
|
|
||||||
fileSize: "123 Tbytes"
|
|
||||||
)
|
|
||||||
DocumentItem(
|
|
||||||
name: "Some document #7 name",
|
|
||||||
lastModified: "13 nanoseconds ago",
|
|
||||||
fileSize: "123 Tbytes"
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.swipeActions(
|
// Group {
|
||||||
edge: .trailing,
|
// Group {
|
||||||
allowsFullSwipe: true
|
// FolderItem(name: "Some folder #1 name")
|
||||||
) {
|
// FolderItem(name: "Some folder #2 name")
|
||||||
Button {
|
// FolderItem(name: "Some folder #3 name")
|
||||||
// TODO: Implement the removal of the item from the API.
|
// FolderItem(name: "Some folder #4 name")
|
||||||
} label: {
|
// FolderItem(name: "Some folder #5 name")
|
||||||
Label {
|
// FolderItem(name: "Some folder #6 name")
|
||||||
Text(
|
// FolderItem(name: "Some folder #7 name")
|
||||||
"browse.swipe_action.delete_item.text",
|
// }
|
||||||
bundle: .module,
|
// Group {
|
||||||
comment: "Delete item swipe action text."
|
// DocumentItem(
|
||||||
)
|
// name: "Some document #1 name",
|
||||||
} icon: {
|
// lastModified: "3 months ago",
|
||||||
Image.trash
|
// fileSize: "1,23 Mbytes"
|
||||||
}
|
// )
|
||||||
}
|
// DocumentItem(
|
||||||
.tint(.red)
|
// name: "Some document #2 name",
|
||||||
|
// lastModified: "2 years ago",
|
||||||
// TODO: allow download only if item is a file.
|
// fileSize: "123 Kbytes"
|
||||||
Button {
|
// )
|
||||||
// TODO: Implement the downloading of the data of the item from the API into the device.
|
// DocumentItem(
|
||||||
} label: {
|
// name: "Some document #3 name",
|
||||||
Label {
|
// lastModified: "13 days ago",
|
||||||
Text(
|
// fileSize: "12 bytes"
|
||||||
"browse.swipe_action.download_item.text",
|
// )
|
||||||
bundle: .module,
|
// DocumentItem(
|
||||||
comment: "Download item swipe action text."
|
// name: "Some document #4 name",
|
||||||
)
|
// lastModified: "13 hours ago",
|
||||||
} icon: {
|
// fileSize: "12,3 Gbytes"
|
||||||
Image.download
|
// )
|
||||||
}
|
// DocumentItem(
|
||||||
}
|
// name: "Some document #5 name",
|
||||||
.tint(.orange)
|
// lastModified: "13 minutes ago",
|
||||||
}
|
// fileSize: "123 Tbytes"
|
||||||
|
// )
|
||||||
|
// DocumentItem(
|
||||||
|
// name: "Some document #6 name",
|
||||||
|
// lastModified: "13 seconds ago",
|
||||||
|
// fileSize: "123 Tbytes"
|
||||||
|
// )
|
||||||
|
// DocumentItem(
|
||||||
|
// name: "Some document #7 name",
|
||||||
|
// lastModified: "13 nanoseconds ago",
|
||||||
|
// fileSize: "123 Tbytes"
|
||||||
|
// )
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// .swipeActions(
|
||||||
|
// edge: .trailing,
|
||||||
|
// allowsFullSwipe: true
|
||||||
|
// ) {
|
||||||
|
// Button {
|
||||||
|
// // TODO: Implement the removal of the item from the API.
|
||||||
|
// } label: {
|
||||||
|
// Label {
|
||||||
|
// Text(
|
||||||
|
// "browse.swipe_action.delete_item.text",
|
||||||
|
// bundle: .module,
|
||||||
|
// comment: "Delete item swipe action text."
|
||||||
|
// )
|
||||||
|
// } icon: {
|
||||||
|
// Image.trash
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// .tint(.red)
|
||||||
|
//
|
||||||
|
// // TODO: allow download only if item is a file.
|
||||||
|
// Button {
|
||||||
|
// // TODO: Implement the downloading of the data of the item from the API into the device.
|
||||||
|
// } label: {
|
||||||
|
// Label {
|
||||||
|
// Text(
|
||||||
|
// "browse.swipe_action.download_item.text",
|
||||||
|
// bundle: .module,
|
||||||
|
// comment: "Download item swipe action text."
|
||||||
|
// )
|
||||||
|
// } icon: {
|
||||||
|
// Image.download
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// .tint(.orange)
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
.listStyle(.inset)
|
.listStyle(.inset)
|
||||||
.background(Color.red)
|
|
||||||
.navigationTitle(folder.name)
|
.navigationTitle(folder.name)
|
||||||
.toolbar {
|
.toolbar {
|
||||||
BrowseToolbar(
|
BrowseToolbar(
|
||||||
@ -130,6 +151,29 @@ public struct BrowseView: View {
|
|||||||
showProfile: showProfile
|
showProfile: showProfile
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
.task(id: folder) {
|
||||||
|
await getItemsOrStop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Helpers
|
||||||
|
|
||||||
|
private extension BrowseView {
|
||||||
|
func getItemsOrStop() async {
|
||||||
|
guard let account else { return }
|
||||||
|
|
||||||
|
do {
|
||||||
|
items = try await getItems(
|
||||||
|
id: folder.id,
|
||||||
|
username: account.username,
|
||||||
|
password: account.password
|
||||||
|
)
|
||||||
|
} catch let error {
|
||||||
|
print(folder)
|
||||||
|
print(error)
|
||||||
|
// TODO: Handle the error.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user