ios: fix welcome view (#3743)
* welcome view (still doesn't keep change on re-open) * fix * remove debug log * rename
This commit is contained in:
parent
fbe3353434
commit
6ef3a9e668
@ -370,7 +370,11 @@ struct GroupChatInfoView: View {
|
|||||||
|
|
||||||
private func addOrEditWelcomeMessage() -> some View {
|
private func addOrEditWelcomeMessage() -> some View {
|
||||||
NavigationLink {
|
NavigationLink {
|
||||||
GroupWelcomeView(groupId: groupInfo.groupId, groupInfo: $groupInfo)
|
GroupWelcomeView(
|
||||||
|
groupInfo: $groupInfo,
|
||||||
|
groupProfile: groupInfo.groupProfile,
|
||||||
|
welcomeText: groupInfo.groupProfile.description ?? ""
|
||||||
|
)
|
||||||
.navigationTitle("Welcome message")
|
.navigationTitle("Welcome message")
|
||||||
.navigationBarTitleDisplayMode(.large)
|
.navigationBarTitleDisplayMode(.large)
|
||||||
} label: {
|
} label: {
|
||||||
|
@ -11,10 +11,9 @@ import SimpleXChat
|
|||||||
|
|
||||||
struct GroupWelcomeView: View {
|
struct GroupWelcomeView: View {
|
||||||
@Environment(\.dismiss) var dismiss: DismissAction
|
@Environment(\.dismiss) var dismiss: DismissAction
|
||||||
@EnvironmentObject private var m: ChatModel
|
|
||||||
var groupId: Int64
|
|
||||||
@Binding var groupInfo: GroupInfo
|
@Binding var groupInfo: GroupInfo
|
||||||
@State private var welcomeText: String = ""
|
@State var groupProfile: GroupProfile
|
||||||
|
@State var welcomeText: String
|
||||||
@State private var editMode = true
|
@State private var editMode = true
|
||||||
@FocusState private var keyboardVisible: Bool
|
@FocusState private var keyboardVisible: Bool
|
||||||
@State private var showSaveDialog = false
|
@State private var showSaveDialog = false
|
||||||
@ -24,7 +23,7 @@ struct GroupWelcomeView: View {
|
|||||||
if groupInfo.canEdit {
|
if groupInfo.canEdit {
|
||||||
editorView()
|
editorView()
|
||||||
.modifier(BackButton {
|
.modifier(BackButton {
|
||||||
if welcomeText == groupInfo.groupProfile.description || (welcomeText == "" && groupInfo.groupProfile.description == nil) {
|
if welcomeTextUnchanged() {
|
||||||
dismiss()
|
dismiss()
|
||||||
} else {
|
} else {
|
||||||
showSaveDialog = true
|
showSaveDialog = true
|
||||||
@ -33,7 +32,6 @@ struct GroupWelcomeView: View {
|
|||||||
.confirmationDialog("Save welcome message?", isPresented: $showSaveDialog) {
|
.confirmationDialog("Save welcome message?", isPresented: $showSaveDialog) {
|
||||||
Button("Save and update group profile") {
|
Button("Save and update group profile") {
|
||||||
save()
|
save()
|
||||||
dismiss()
|
|
||||||
}
|
}
|
||||||
Button("Exit without saving") { dismiss() }
|
Button("Exit without saving") { dismiss() }
|
||||||
}
|
}
|
||||||
@ -47,8 +45,9 @@ struct GroupWelcomeView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onAppear {
|
.onAppear {
|
||||||
welcomeText = groupInfo.groupProfile.description ?? ""
|
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
|
||||||
keyboardVisible = true
|
keyboardVisible = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +112,11 @@ struct GroupWelcomeView: View {
|
|||||||
Button("Save and update group profile") {
|
Button("Save and update group profile") {
|
||||||
save()
|
save()
|
||||||
}
|
}
|
||||||
.disabled(welcomeText == groupInfo.groupProfile.description || (welcomeText == "" && groupInfo.groupProfile.description == nil))
|
.disabled(welcomeTextUnchanged())
|
||||||
|
}
|
||||||
|
|
||||||
|
private func welcomeTextUnchanged() -> Bool {
|
||||||
|
welcomeText == groupInfo.groupProfile.description || (welcomeText == "" && groupInfo.groupProfile.description == nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func save() {
|
private func save() {
|
||||||
@ -123,11 +126,13 @@ struct GroupWelcomeView: View {
|
|||||||
if welcome?.count == 0 {
|
if welcome?.count == 0 {
|
||||||
welcome = nil
|
welcome = nil
|
||||||
}
|
}
|
||||||
var groupProfileUpdated = groupInfo.groupProfile
|
groupProfile.description = welcome
|
||||||
groupProfileUpdated.description = welcome
|
let gInfo = try await apiUpdateGroup(groupInfo.groupId, groupProfile)
|
||||||
groupInfo = try await apiUpdateGroup(groupId, groupProfileUpdated)
|
await MainActor.run {
|
||||||
m.updateGroup(groupInfo)
|
groupInfo = gInfo
|
||||||
welcomeText = welcome ?? ""
|
ChatModel.shared.updateGroup(gInfo)
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
} catch let error {
|
} catch let error {
|
||||||
logger.error("apiUpdateGroup error: \(responseError(error))")
|
logger.error("apiUpdateGroup error: \(responseError(error))")
|
||||||
}
|
}
|
||||||
@ -137,6 +142,6 @@ struct GroupWelcomeView: View {
|
|||||||
|
|
||||||
struct GroupWelcomeView_Previews: PreviewProvider {
|
struct GroupWelcomeView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
GroupWelcomeView(groupId: 1, groupInfo: Binding.constant(GroupInfo.sampleData))
|
GroupProfileView(groupInfo: Binding.constant(GroupInfo.sampleData), groupProfile: GroupProfile.sampleData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user