Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjmarf committed Jan 11, 2024
1 parent 938db61 commit a59c047
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 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 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 a59c047

Please sign in to comment.