krz/hutch

an ios client for sourcehut

clone: git clone https://gitbay.org/krz/hutch.git

v2.8.1: Hutch/Views/Lookup/UserProfileView.swift · raw

 1import SwiftUI
 2
 3struct UserProfileView: View {
 4    let user: User
 5
 6    @Environment(AppState.self) private var appState
 7
 8    var body: some View {
 9        List {
10            if let avatarURL = user.avatar.flatMap(URL.init(string:)) {
11                Section {
12                    HStack {
13                        Spacer()
14                        AsyncImage(url: avatarURL) { phase in
15                            switch phase {
16                            case .success(let image):
17                                image
18                                    .resizable()
19                                    .scaledToFill()
20                            case .failure, .empty:
21                                Image(systemName: "person.crop.circle.fill")
22                                    .resizable()
23                                    .scaledToFit()
24                                    .foregroundStyle(.secondary)
25                                    .padding(20)
26                            @unknown default:
27                                EmptyView()
28                            }
29                        }
30                        .frame(width: 96, height: 96)
31                        .clipShape(Circle())
32                        .overlay {
33                            Circle()
34                                .stroke(Color.secondary.opacity(0.2), lineWidth: 1)
35                        }
36                        Spacer()
37                    }
38                    .listRowBackground(Color.clear)
39                }
40            }
41
42            Section {
43                LabeledContent("Username", value: user.username)
44                LabeledContent("Canonical Name", value: user.canonicalName)
45                LabeledContent("Email", value: user.email)
46            }
47        }
48        .listStyle(.insetGrouped)
49        .navigationTitle(user.canonicalName)
50        .navigationBarTitleDisplayMode(.inline)
51    }
52}