Fix SideMenuAccountRow UI for failed connection state

This commit is contained in:
Benoit Martins 2025-07-08 14:07:37 +02:00
parent fe261f3127
commit c97e0045c8
2 changed files with 70 additions and 73 deletions

View file

@ -35,90 +35,87 @@ struct SideMenuAccountRow: View {
var body: some View {
HStack {
if accountProfileViewModel.accountModelIndex != nil && CoreContext.shared.accounts.count > accountProfileViewModel.accountModelIndex! {
AsyncImage(url: CoreContext.shared.accounts[accountProfileViewModel.accountModelIndex!].imagePathAvatar) { image in
switch image {
case .empty:
ProgressView()
.frame(width: avatarSize, height: avatarSize)
case .success(let image):
image
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: avatarSize, height: avatarSize)
.clipShape(Circle())
case .failure:
Image(uiImage: contactsManager.textToImage(
firstName: model.avatarModel?.name ?? "",
lastName: ""))
AsyncImage(url: model.imagePathAvatar) { image in
switch image {
case .empty:
ProgressView()
.frame(width: avatarSize, height: avatarSize)
case .success(let image):
image
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: avatarSize, height: avatarSize)
.clipShape(Circle())
@unknown default:
EmptyView()
}
case .failure:
Image(uiImage: contactsManager.textToImage(
firstName: model.avatarModel?.name ?? "",
lastName: ""))
.resizable()
.frame(width: avatarSize, height: avatarSize)
.clipShape(Circle())
@unknown default:
EmptyView()
}
.padding(.leading, 6)
}
.padding(.leading, 6)
VStack {
Text(model.displayName)
.default_text_style_grey_400(styleSize: 14)
.lineLimit(1)
.frame(maxWidth: .infinity, alignment: .leading)
VStack {
Text(model.displayName)
.default_text_style_grey_400(styleSize: 14)
.lineLimit(1)
.frame(maxWidth: .infinity, alignment: .leading)
VStack {
Text(model.humanReadableRegistrationState)
.default_text_style_uncolored(styleSize: 12)
.foregroundStyle(model.registrationStateAssociatedUIColor)
}
.padding(EdgeInsets(top: 4, leading: 8, bottom: 4, trailing: 8))
.background(Color.grayMain2c200)
.cornerRadius(12)
.frame(height: 20)
.frame(maxWidth: .infinity, alignment: .leading)
.onTapGesture {
model.refreshRegiter()
}
Text(model.humanReadableRegistrationState)
.default_text_style_uncolored(styleSize: 12)
.foregroundStyle(model.registrationStateAssociatedUIColor)
}
.padding(EdgeInsets(top: 4, leading: 8, bottom: 4, trailing: 8))
.background(Color.grayMain2c200)
.cornerRadius(12)
.frame(height: 20)
.frame(maxWidth: .infinity, alignment: .leading)
.onTapGesture {
model.refreshRegiter()
}
}
.padding(.leading, 4)
Spacer()
HStack {
if model.notificationsCount > 0 && !CorePreferences.disableChatFeature {
Text(String(model.notificationsCount))
.foregroundStyle(.white)
.default_text_style(styleSize: 12)
.lineLimit(1)
.frame(width: 20, height: 20)
.background(Color.redDanger500)
.cornerRadius(50)
.frame(maxWidth: .infinity, alignment: .leading)
}
.padding(.leading, 4)
Spacer()
HStack {
if model.notificationsCount > 0 {
Text(String(model.notificationsCount))
.foregroundStyle(.white)
.default_text_style(styleSize: 12)
.lineLimit(1)
.frame(width: 20, height: 20)
.background(Color.redDanger500)
.cornerRadius(50)
.frame(maxWidth: .infinity, alignment: .leading)
}
Menu {
Button {
withAnimation {
isOpen = false
isShowAccountProfileFragment = true
}
} label: {
Label("drawer_menu_manage_account", systemImage: "arrow.right.circle")
Menu {
Button {
withAnimation {
isOpen = false
isShowAccountProfileFragment = true
}
} label: {
Image("dots-three-vertical")
.renderingMode(.template)
.resizable()
.foregroundColor(Color.gray)
.scaledToFit()
.frame(height: 30)
Label("drawer_menu_manage_account", systemImage: "arrow.right.circle")
}
} label: {
Image("dots-three-vertical")
.renderingMode(.template)
.resizable()
.foregroundColor(Color.gray)
.scaledToFit()
.frame(height: 30)
}
.frame(width: 64, alignment: .trailing)
.padding(.top, 12)
.padding(.bottom, 12)
}
.frame(width: 64, alignment: .trailing)
.padding(.top, 12)
.padding(.bottom, 12)
}
.frame(height: 61)
.background(model.isDefaultAccount ? Color.grayMain2c100 : .clear)

View file

@ -92,8 +92,8 @@ class AccountModel: ObservableObject {
self.requestDevicesList()
let displayNameTmp = account.params?.identityAddress?.displayName ?? ""
let usernaneAvatarTmp = account.contactAddress?.username ?? ""
let displayNameTmp = account.params?.identityAddress?.displayName ?? displayName
let usernaneAvatarTmp = account.contactAddress?.username ?? displayName
var photoAvatarModelTmp = ""
let preferences = UserDefaults.standard