ios: allow all group members to view welcome message (#2347)
* ios: allow all group members to view welcome message * remove diff * layout * ignore taps on preview * remove newline * show/hide keyboard * fix button flickering * remove space * remove unused function --------- Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
This commit is contained in:
@@ -45,8 +45,8 @@ struct GroupChatInfoView: View {
|
||||
Section {
|
||||
if groupInfo.canEdit {
|
||||
editGroupButton()
|
||||
addOrEditWelcomeMessage()
|
||||
}
|
||||
addOrEditWelcomeMessage()
|
||||
groupPreferencesButton($groupInfo)
|
||||
} header: {
|
||||
Text("")
|
||||
|
||||
@@ -15,43 +15,101 @@ struct GroupWelcomeView: View {
|
||||
var groupId: Int64
|
||||
@Binding var groupInfo: GroupInfo
|
||||
@State private var welcomeText: String = ""
|
||||
@State private var editMode = true
|
||||
@FocusState private var keyboardVisible: Bool
|
||||
@State private var showSaveDialog = false
|
||||
|
||||
var body: some View {
|
||||
List {
|
||||
Section {
|
||||
TextEditor(text: $welcomeText)
|
||||
.focused($keyboardVisible)
|
||||
.padding(.horizontal, -5)
|
||||
.padding(.top, -8)
|
||||
.frame(height: 90, alignment: .topLeading)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
Section {
|
||||
saveButton()
|
||||
VStack {
|
||||
if groupInfo.canEdit {
|
||||
editorView()
|
||||
.modifier(BackButton {
|
||||
if welcomeText == groupInfo.groupProfile.description || (welcomeText == "" && groupInfo.groupProfile.description == nil) {
|
||||
dismiss()
|
||||
} else {
|
||||
showSaveDialog = true
|
||||
}
|
||||
})
|
||||
.confirmationDialog("Save welcome message?", isPresented: $showSaveDialog) {
|
||||
Button("Save and update group profile") {
|
||||
save()
|
||||
dismiss()
|
||||
}
|
||||
Button("Exit without saving") { dismiss() }
|
||||
}
|
||||
} else {
|
||||
List {
|
||||
Section {
|
||||
textPreview()
|
||||
copyButton()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
welcomeText = groupInfo.groupProfile.description ?? ""
|
||||
}
|
||||
.modifier(BackButton {
|
||||
if welcomeText == groupInfo.groupProfile.description || (welcomeText == "" && groupInfo.groupProfile.description == nil) {
|
||||
dismiss()
|
||||
} else {
|
||||
showSaveDialog = true
|
||||
}
|
||||
})
|
||||
.confirmationDialog("Save welcome message?", isPresented: $showSaveDialog) {
|
||||
Button("Save and update group profile") {
|
||||
save()
|
||||
dismiss()
|
||||
}
|
||||
Button("Exit without saving") { dismiss() }
|
||||
keyboardVisible = true
|
||||
}
|
||||
}
|
||||
|
||||
@ViewBuilder private func saveButton() -> some View {
|
||||
private func textPreview() -> some View {
|
||||
messageText(welcomeText, parseSimpleXMarkdown(welcomeText), nil)
|
||||
.allowsHitTesting(false)
|
||||
}
|
||||
|
||||
private func editorView() -> some View {
|
||||
List {
|
||||
Section {
|
||||
if editMode {
|
||||
ZStack {
|
||||
Group {
|
||||
if welcomeText.isEmpty {
|
||||
TextEditor(text: Binding.constant(NSLocalizedString("Enter welcome message…", comment: "placeholder")))
|
||||
.foregroundColor(.secondary)
|
||||
.disabled(true)
|
||||
}
|
||||
TextEditor(text: $welcomeText)
|
||||
.focused($keyboardVisible)
|
||||
}
|
||||
.padding(.horizontal, -5)
|
||||
.padding(.top, -8)
|
||||
.frame(height: 90, alignment: .topLeading)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
} else {
|
||||
textPreview()
|
||||
.frame(height: 90, alignment: .topLeading)
|
||||
}
|
||||
|
||||
Button {
|
||||
editMode = !editMode
|
||||
keyboardVisible = editMode
|
||||
} label: {
|
||||
if editMode {
|
||||
Label ("Preview", systemImage: "character")
|
||||
} else {
|
||||
Label ("Edit", systemImage: "pencil")
|
||||
}
|
||||
}
|
||||
.disabled(welcomeText.isEmpty)
|
||||
copyButton()
|
||||
}
|
||||
|
||||
Section {
|
||||
saveButton()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func copyButton() -> some View {
|
||||
Button {
|
||||
UIPasteboard.general.string = welcomeText
|
||||
} label: {
|
||||
Label ("Copy", systemImage: "doc.on.doc")
|
||||
}
|
||||
}
|
||||
|
||||
private func saveButton() -> some View {
|
||||
Button("Save and update group profile") {
|
||||
save()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user