Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matrix ID Settings Bug Fixes & UI Tweaks #851

Merged
merged 5 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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