Optimized and set default background
This commit is contained in:
parent
7d378e76df
commit
897c0cb889
|
@ -3,7 +3,7 @@
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
|
|
||||||
struct ProfileView: View {
|
struct ProfileView: View {
|
||||||
@Environment(Client.self) private var client: Client
|
// @Environment(Client.self) private var client: Client
|
||||||
|
|
||||||
@Namespace var accountAnims
|
@Namespace var accountAnims
|
||||||
@Namespace var animPicture
|
@Namespace var animPicture
|
||||||
|
@ -13,12 +13,16 @@ struct ProfileView: View {
|
||||||
@State private var location: CGPoint = .zero
|
@State private var location: CGPoint = .zero
|
||||||
|
|
||||||
@State var account: Account
|
@State var account: Account
|
||||||
|
@State private var serverAccount: String = ""
|
||||||
private let isCurrent: Bool = true
|
private let isCurrent: Bool = true
|
||||||
private let animPicCurve = Animation.smooth(duration: 0.25, extraBounce: 0.0)
|
private let animPicCurve = Animation.smooth(duration: 0.25, extraBounce: 0.0)
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationStack(path: $navigator.path) {
|
NavigationStack(path: $navigator.path) {
|
||||||
ZStack (alignment: .center) {
|
ZStack (alignment: .center) {
|
||||||
|
Color.appBackground
|
||||||
|
.ignoresSafeArea()
|
||||||
|
|
||||||
if account != Account.placeholder() {
|
if account != Account.placeholder() {
|
||||||
if biggerPicture {
|
if biggerPicture {
|
||||||
big
|
big
|
||||||
|
@ -31,27 +35,31 @@ struct ProfileView: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.refreshable {
|
.refreshable {
|
||||||
|
await reloadProfile()
|
||||||
|
}
|
||||||
|
.task {
|
||||||
|
await reloadProfile()
|
||||||
|
}
|
||||||
|
.environment(navigator)
|
||||||
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
|
.toolbarBackground(Color.appBackground, for: .navigationBar)
|
||||||
|
.toolbarBackground(.automatic, for: .navigationBar)
|
||||||
|
}
|
||||||
|
|
||||||
|
func reloadProfile() async {
|
||||||
if isCurrent {
|
if isCurrent {
|
||||||
do {
|
do {
|
||||||
if let saved: AppAccount = try AppAccount.loadAsCurrent() {
|
if let saved: AppAccount = try AppAccount.loadAsCurrent() {
|
||||||
|
serverAccount = saved.server
|
||||||
let cli: Client = Client(server: saved.server, oauthToken: saved.oauthToken)
|
let cli: Client = Client(server: saved.server, oauthToken: saved.oauthToken)
|
||||||
let acc: Account? = try await client.get(endpoint: Accounts.verifyCredentials)
|
let acc: Account? = try await cli.get(endpoint: Accounts.verifyCredentials)
|
||||||
account = acc ?? Account.placeholder()
|
account = acc ?? Account.placeholder()
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
print(error)
|
print(error)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if let ref: Account = try? await client.get(endpoint: Accounts.accounts(id: account.id)) {
|
|
||||||
account = ref
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
.environment(navigator)
|
|
||||||
.navigationBarTitleDisplayMode(.inline)
|
|
||||||
.toolbarBackground(Color(uiColor: UIColor.systemBackground), for: .navigationBar)
|
|
||||||
.toolbarBackground(.automatic, for: .navigationBar)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Headers
|
// MARK: - Headers
|
||||||
|
|
||||||
|
@ -90,7 +98,7 @@ struct ProfileView: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.safeAreaPadding()
|
.safeAreaPadding()
|
||||||
.background(Color(uiColor: UIColor.systemBackground))
|
.background(Color.appBackground)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.withAppRouter()
|
.withAppRouter()
|
||||||
|
@ -135,7 +143,7 @@ struct ProfileView: View {
|
||||||
.disabled(true)
|
.disabled(true)
|
||||||
}
|
}
|
||||||
.safeAreaPadding()
|
.safeAreaPadding()
|
||||||
.background(Color(uiColor: UIColor.systemBackground))
|
.background(Color.appBackground)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.withAppRouter()
|
.withAppRouter()
|
||||||
|
@ -150,42 +158,16 @@ struct ProfileView: View {
|
||||||
.multilineTextAlignment(.leading)
|
.multilineTextAlignment(.leading)
|
||||||
.lineLimit(1)
|
.lineLimit(1)
|
||||||
|
|
||||||
let server = account.acct.split(separator: "@").last
|
|
||||||
|
|
||||||
HStack(alignment: .center) {
|
HStack(alignment: .center) {
|
||||||
if server != nil {
|
|
||||||
if server! != account.username {
|
|
||||||
Text("\(account.username)")
|
Text("\(account.username)")
|
||||||
.font(.body)
|
.font(.body)
|
||||||
.multilineTextAlignment(.leading)
|
.multilineTextAlignment(.leading)
|
||||||
|
|
||||||
Text("\(server!.description)")
|
Text("\(serverAccount)")
|
||||||
.font(.caption)
|
.font(.caption)
|
||||||
.foregroundStyle(Color.gray)
|
.foregroundStyle(Color.gray)
|
||||||
.multilineTextAlignment(.leading)
|
.multilineTextAlignment(.leading)
|
||||||
.pill()
|
.pill()
|
||||||
} else {
|
|
||||||
Text("\(account.username)")
|
|
||||||
.font(.body)
|
|
||||||
.multilineTextAlignment(.leading)
|
|
||||||
|
|
||||||
Text("\(client.server)")
|
|
||||||
.font(.caption)
|
|
||||||
.foregroundStyle(Color.gray)
|
|
||||||
.multilineTextAlignment(.leading)
|
|
||||||
.pill()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Text("\(account.username)")
|
|
||||||
.font(.body)
|
|
||||||
.multilineTextAlignment(.leading)
|
|
||||||
|
|
||||||
Text("\(client.server)")
|
|
||||||
.font(.caption)
|
|
||||||
.foregroundStyle(Color.gray)
|
|
||||||
.multilineTextAlignment(.leading)
|
|
||||||
.pill()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue