summaryrefslogtreecommitdiff
path: root/Hutch/Views/Lookup/UserProfileView.swift
blob: 3fcbb2f0d16cf3d4621e130159ce7221f50c69ac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import SwiftUI

struct UserProfileView: View {
    let user: User

    @Environment(AppState.self) private var appState

    var body: some View {
        List {
            if let avatarURL = user.avatar.flatMap(URL.init(string:)) {
                Section {
                    HStack {
                        Spacer()
                        AsyncImage(url: avatarURL) { phase in
                            switch phase {
                            case .success(let image):
                                image
                                    .resizable()
                                    .scaledToFill()
                            case .failure, .empty:
                                Image(systemName: "person.crop.circle.fill")
                                    .resizable()
                                    .scaledToFit()
                                    .foregroundStyle(.secondary)
                                    .padding(20)
                            @unknown default:
                                EmptyView()
                            }
                        }
                        .frame(width: 96, height: 96)
                        .clipShape(Circle())
                        .overlay {
                            Circle()
                                .stroke(Color.secondary.opacity(0.2), lineWidth: 1)
                        }
                        Spacer()
                    }
                    .listRowBackground(Color.clear)
                }
            }

            Section {
                LabeledContent("Username", value: user.username)
                LabeledContent("Canonical Name", value: user.canonicalName)
                LabeledContent("Email", value: user.email)
            }
        }
        .listStyle(.insetGrouped)
        .navigationTitle(user.canonicalName)
        .navigationBarTitleDisplayMode(.inline)
    }
}