Mercurial > public > geoquiz
diff GeoQuiz/ProfileEditModalView.swift @ 16:1011e56b7832
implement user profile
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Thu, 20 Oct 2022 13:49:42 +0200 |
parents | GeoQuiz/Components/ProfileEditModalView.swift@136928bae534 |
children | f140bb277c96 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GeoQuiz/ProfileEditModalView.swift Thu Oct 20 13:49:42 2022 +0200 @@ -0,0 +1,70 @@ +// +// ProfileEditModalView.swift +// GeoQuiz +// +// Created by Dennis Concepción Martín on 19/10/22. +// + +import SwiftUI +import PhotosUI + +struct ProfileEditModalView: View { + @ObservedObject var user: User + @Environment(\.dismiss) var dismiss + + @State private var selectedItem: PhotosPickerItem? = nil + + var body: some View { + NavigationStack { + Form { + Section { + HStack { + Spacer() + ZStack { + UserImage(uiImage: user.data.uiImage) + .onChange(of: selectedItem) { newItem in + Task { + if let data = try? await newItem?.loadTransferable(type: Data.self) { + user.data.imageData = data + } + } + } + + PhotosPicker( + selection: $selectedItem, + matching: .images, + photoLibrary: .shared()) { + EmptyView() + } + } + + Spacer() + } + } header: { + Text("Profile image") + } + + Section { + TextField("Enter a username", text: $user.data.username) + } header: { + Text("Username") + } + } + .navigationTitle("Edit profile") + .navigationBarTitleDisplayMode(.inline) + .toolbar { + ToolbarItem(placement: .navigationBarTrailing) { + Button("Done") { + dismiss() + } + } + } + } + } +} + +struct ProfileEditModalView_Previews: PreviewProvider { + static var previews: some View { + ProfileEditModalView(user: User()) + } +}