Skip to content

Commit

Permalink
Matrix ID Settings Bug Fixes & UI Tweaks (#851)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjmarf authored Jan 16, 2024
1 parent 308e5ab commit 74ee409
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@ struct MatrixLinkView: View {
@Dependency(\.apiClient) var apiClient: APIClient
@Dependency(\.errorHandler) var errorHandler: ErrorHandler

@State var matrixUserId: String = ""
@State var matrixUserId: String

@State var hasEdited: UserSettingsEditState = .unedited

let matrixIdRegex = /@.+\:.+\..+/

init() {
@Dependency(\.siteInformation) var siteInformation: SiteInformationTracker
let user = siteInformation.myUserInfo?.localUserView
_matrixUserId = State(wrappedValue: user?.person.matrixUserId ?? "")
}

var matrixIdValid: Bool {
if matrixUserId.isEmpty {
return true
Expand Down Expand Up @@ -51,7 +57,7 @@ struct MatrixLinkView: View {
.autocorrectionDisabled()
.textInputAutocapitalization(.never)
.onChange(of: matrixUserId) { newValue in
if newValue != siteInformation.myUserInfo?.localUserView.person.matrixUserId {
if newValue != siteInformation.myUserInfo?.localUserView.person.matrixUserId ?? "" {
hasEdited = .edited
}
}
Expand All @@ -67,8 +73,7 @@ struct MatrixLinkView: View {
}
}
} footer: {
// swiftlint:disable:next line_length
Text("Everyone will be able to see your matrix ID, and will be able to send you messages through Lemmy or another matrix client.")
Text("Everyone will be able to see your Matrix ID.")
}
Link("What is matrix?", destination: URL(string: "https://matrix.org/")!)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ struct ProfileSettingsView: View {
@Dependency(\.apiClient) var apiClient: APIClient
@Dependency(\.errorHandler) var errorHandler: ErrorHandler

@State var displayName: String = ""
@State var bio: String = ""
@State var displayName: String
@State var bio: String

@StateObject var avatarAttachmentModel: LinkAttachmentModel
@StateObject var bannerAttachmentModel: LinkAttachmentModel
Expand Down Expand Up @@ -155,9 +155,19 @@ struct ProfileSettingsView: View {
}
}
NavigationLink(.settings(.linkMatrixAccount)) {
Label("Link Matrix Account", image: "logo.matrix").labelStyle(SquircleLabelStyle(color: .black))
.disabled(hasEdited != .unedited)
let user = siteInformation.myUserInfo?.localUserView
if let user, let matrixId = user.person.matrixUserId {
HStack {
Label("Matrix ID", image: "logo.matrix").labelStyle(SquircleLabelStyle(color: .black))
Spacer()
Text(matrixId)
.foregroundStyle(.secondary)
}
} else {
Label("Link Matrix Account", image: "logo.matrix").labelStyle(SquircleLabelStyle(color: .black))
}
}
.disabled(hasEdited != .unedited)
}
.scrollDismissesKeyboard(.interactively)
.navigationTitle("My Profile")
Expand Down

0 comments on commit 74ee409

Please sign in to comment.