Improved the ProfileView view for the Profile module with the integration of the StringAdapter and the DataAdapter adapter and the ProfileSection component.

This commit is contained in:
Javier Cicchelli 2022-12-12 02:52:25 +01:00
parent 8b8f0d9f1f
commit c1f790edca

View File

@ -6,18 +6,27 @@
// Copyright © 2022 Röck+Cöde. All rights reserved.
//
import DataModels
import SwiftUI
public struct ProfileView: View {
// MARK: Properties
private let logOut: () -> Void
private let user: User?
private let logout: ActionClosure
private let stringAdapter = StringAdapter()
private let dateAdapter = DateAdapter()
// MARK: Initialisers
public init(logOut: @escaping () -> Void) {
self.logOut = logOut
public init(
user: User?,
logout: @escaping ActionClosure
) {
self.user = user
self.logout = logout
}
// MARK: Body
@ -33,96 +42,45 @@ public struct ProfileView: View {
}
.listRowBackground(Color.clear)
Section {
Label {
Text("Javier")
} icon: {
Text(
"profile.sections.names.label.first_name.text",
bundle: .module,
comment: "First name label text."
ProfileSection(
header: "profile.sections.names.header.text",
items: [
.init(
key: "profile.sections.names.label.first_name.text",
value: stringAdapter(value: user?.profile.firstName)
),
.init(
key: "profile.sections.names.label.last_name.text",
value: stringAdapter(value: user?.profile.lastName)
)
}
.labelStyle(.nameAndValue)
Label {
Text("Cicchelli")
} icon: {
Text(
"profile.sections.names.label.last_name.text",
bundle: .module,
comment: "Last name label text."
]
)
ProfileSection(
header: "profile.sections.root_info.header.text",
items: [
.init(
key: "profile.sections.root_info.label.identifier.text",
value: stringAdapter(value: user?.rootFolder.id)
),
.init(
key: "profile.sections.root_info.label.name.text",
value: stringAdapter(value: user?.rootFolder.name)
),
.init(
key: "profile.sections.root_info.label.last_modified.text",
value: dateAdapter(value: user?.rootFolder.lastModifiedAt)
)
}
.labelStyle(.nameAndValue)
} header: {
Text(
"profile.sections.names.header.text",
bundle: .module,
comment: "Names section header text."
)
}
]
)
Section {
Label {
Text("71207ee4c0573fde80b03643caafe62731406404")
} icon: {
Text(
"profile.sections.root_info.label.identifier.text",
bundle: .module,
comment: "Identifier label text."
)
}
.labelStyle(.nameAndValue)
Label {
Text("Yes")
} icon: {
Text(
"profile.sections.root_info.label.is_directory.text",
bundle: .module,
comment: "Is directory label text."
)
}
.labelStyle(.nameAndValue)
Label {
Text("3 days ago")
} icon: {
Text(
"profile.sections.root_info.label.last_modified.text",
bundle: .module,
comment: "Last modified label text."
)
}
.labelStyle(.nameAndValue)
Label {
Text("My files")
} icon: {
Text(
"profile.sections.root_info.label.name.text",
bundle: .module,
comment: "Root name label text."
)
}
.labelStyle(.nameAndValue)
} header: {
Text(
"profile.sections.root_info.header.text",
bundle: .module,
comment: "Root item information header text."
)
}
Section {
Button {
logOut()
logout()
} label: {
Text(
"profile.button.log_out.text",
bundle: .module,
comment: "Log out button text."
bundle: .module
)
.fontWeight(.semibold)
.foregroundColor(.primary)
@ -137,6 +95,7 @@ public struct ProfileView: View {
}
.background(Color.red)
}
}
// MARK: - Images+Constants
@ -149,8 +108,18 @@ private extension Image {
struct ProfileView_Previews: PreviewProvider {
static var previews: some View {
ProfileView {
// closure for log out action.
ProfileView(user: .init(
profile: .init(
firstName: "Some first name...",
lastName: "Some last name..."
),
rootFolder: .init(
id: "1234567890",
name: "Some folder name...",
lastModifiedAt: .now
)
)) {
// closure for logout action.
}
}
}