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,28 +35,32 @@ struct ProfileView: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.refreshable {
|
.refreshable {
|
||||||
if isCurrent {
|
await reloadProfile()
|
||||||
do {
|
}
|
||||||
if let saved: AppAccount = try AppAccount.loadAsCurrent() {
|
.task {
|
||||||
let cli: Client = Client(server: saved.server, oauthToken: saved.oauthToken)
|
await reloadProfile()
|
||||||
let acc: Account? = try await client.get(endpoint: Accounts.verifyCredentials)
|
|
||||||
account = acc ?? Account.placeholder()
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
print(error)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if let ref: Account = try? await client.get(endpoint: Accounts.accounts(id: account.id)) {
|
|
||||||
account = ref
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.environment(navigator)
|
.environment(navigator)
|
||||||
.navigationBarTitleDisplayMode(.inline)
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
.toolbarBackground(Color(uiColor: UIColor.systemBackground), for: .navigationBar)
|
.toolbarBackground(Color.appBackground, for: .navigationBar)
|
||||||
.toolbarBackground(.automatic, for: .navigationBar)
|
.toolbarBackground(.automatic, for: .navigationBar)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func reloadProfile() async {
|
||||||
|
if isCurrent {
|
||||||
|
do {
|
||||||
|
if let saved: AppAccount = try AppAccount.loadAsCurrent() {
|
||||||
|
serverAccount = saved.server
|
||||||
|
let cli: Client = Client(server: saved.server, oauthToken: saved.oauthToken)
|
||||||
|
let acc: Account? = try await cli.get(endpoint: Accounts.verifyCredentials)
|
||||||
|
account = acc ?? Account.placeholder()
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
print(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Headers
|
// MARK: - Headers
|
||||||
|
|
||||||
var wholeSmall: some View {
|
var wholeSmall: some View {
|
||||||
|
@ -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 {
|
Text("\(account.username)")
|
||||||
if server! != account.username {
|
.font(.body)
|
||||||
Text("\(account.username)")
|
.multilineTextAlignment(.leading)
|
||||||
.font(.body)
|
|
||||||
.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