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