82 lines
3.1 KiB
Swift
82 lines
3.1 KiB
Swift
//
|
|
// UserDetailView.swift
|
|
// meterios
|
|
//
|
|
// (c) 2025 Martin "maride" Dessauer
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct UserDetailView: View {
|
|
@AppStorage("meteHostAddr") private var meteHostAddr = ""
|
|
@AppStorage("meteUserID") private var meteUserID = -1
|
|
|
|
var user: User
|
|
|
|
@Environment(\.dismiss) private var dismiss
|
|
|
|
var body: some View {
|
|
List() {
|
|
Section {
|
|
HStack(alignment: .center) {
|
|
Spacer()
|
|
VStack(alignment: .center) {
|
|
// User image
|
|
AsyncImage(
|
|
url: URL(string: user.displayImageURL),
|
|
content: { image in image.resizable().aspectRatio(contentMode: .fill).frame(width: 256, height: 256).clipShape(Circle()) },
|
|
placeholder: {
|
|
ZStack {
|
|
Circle().fill(.gray).frame(width: 256, height: 256)
|
|
ProgressView()
|
|
}
|
|
}
|
|
).fixedSize()
|
|
|
|
// Basic info about user
|
|
VStack(alignment: .center) {
|
|
// User name
|
|
Text("\(user.displayName)").font(.largeTitle).fontWeight(.bold)
|
|
// Balance and Mete backend address
|
|
HStack {
|
|
VStack {
|
|
Text(user.balance.formatted(.currency(code: "EUR"))).fontWeight(.bold)
|
|
.foregroundStyle(user.balance > 0 ? .green : .red)
|
|
Text(String(localized: "BALANCE")).fontWeight(Font.Weight.thin)
|
|
}.fixedSize()
|
|
Divider()
|
|
VStack {
|
|
Text(String(meteHostAddr))
|
|
Text(String(localized: "METE_SERVER")).fontWeight(Font.Weight.thin)
|
|
}
|
|
}
|
|
}.fixedSize()
|
|
}
|
|
Spacer()
|
|
}
|
|
}
|
|
|
|
// Open profile in browser
|
|
Section() {
|
|
Button(action: {
|
|
UIApplication.shared.open(URL(string: "https://\(meteHostAddr)/users/\(meteUserID)")!)
|
|
}) {
|
|
Text(String(localized: "OPEN_PROFILE_IN_BROWSER")).frame(maxWidth: .infinity)
|
|
}
|
|
}
|
|
|
|
// Logout button
|
|
Section() {
|
|
Button(action: {
|
|
// Log out. Save the User ID as -1, which is forbidden by the backend.
|
|
// This forces Meterios to display the setup screen.
|
|
meteUserID = -1
|
|
dismiss()
|
|
}) {
|
|
Text(String(localized: "LOGOUT")).frame(maxWidth: .infinity)
|
|
}.tint(.red)
|
|
}
|
|
}
|
|
}
|
|
}
|