ios: improve UX for contact/group preferences (#1494)
* ios: improve UX for contact/group preferences * refactor
This commit is contained in:
committed by
GitHub
parent
e5969e197a
commit
75cad8a6bf
@@ -10,10 +10,12 @@ import SwiftUI
|
||||
import SimpleXChat
|
||||
|
||||
struct ContactPreferencesView: View {
|
||||
@Environment(\.dismiss) var dismiss: DismissAction
|
||||
@EnvironmentObject var chatModel: ChatModel
|
||||
@Binding var contact: Contact
|
||||
@State var featuresAllowed: ContactFeaturesAllowed
|
||||
@State var currentFeaturesAllowed: ContactFeaturesAllowed
|
||||
@State private var showSaveDialogue = false
|
||||
|
||||
var body: some View {
|
||||
let user: User = chatModel.currentUser!
|
||||
@@ -25,11 +27,25 @@ struct ContactPreferencesView: View {
|
||||
|
||||
Section {
|
||||
Button("Reset") { featuresAllowed = currentFeaturesAllowed }
|
||||
Button("Save (and notify contact)") { savePreferences() }
|
||||
Button("Save and notify contact") { savePreferences() }
|
||||
}
|
||||
.disabled(currentFeaturesAllowed == featuresAllowed)
|
||||
}
|
||||
}
|
||||
.modifier(BackButton {
|
||||
if currentFeaturesAllowed == featuresAllowed {
|
||||
dismiss()
|
||||
} else {
|
||||
showSaveDialogue = true
|
||||
}
|
||||
})
|
||||
.confirmationDialog("Save preferences?", isPresented: $showSaveDialogue) {
|
||||
Button("Save and notify contact") {
|
||||
savePreferences()
|
||||
dismiss()
|
||||
}
|
||||
Button("Exit without saving") { dismiss() }
|
||||
}
|
||||
}
|
||||
|
||||
private func featureSection(_ feature: ChatFeature, _ userDefault: FeatureAllowed, _ pref: ContactUserPreference, _ allowFeature: Binding<ContactFeatureAllowed>) -> some View {
|
||||
|
||||
@@ -13,8 +13,8 @@ struct AddGroupMembersView: View {
|
||||
@EnvironmentObject var chatModel: ChatModel
|
||||
@Environment(\.dismiss) var dismiss: DismissAction
|
||||
var chat: Chat
|
||||
var groupInfo: GroupInfo
|
||||
var showSkip: Bool = false
|
||||
@State var groupInfo: GroupInfo
|
||||
var creatingGroup: Bool = false
|
||||
var showFooterCounter: Bool = true
|
||||
var addedMembersCb: ((Set<Int64>) -> Void)? = nil
|
||||
@State private var selectedContacts = Set<Int64>()
|
||||
@@ -52,6 +52,9 @@ struct AddGroupMembersView: View {
|
||||
} else {
|
||||
let count = selectedContacts.count
|
||||
Section {
|
||||
if creatingGroup {
|
||||
groupPreferencesButton($groupInfo, true)
|
||||
}
|
||||
rolePicker()
|
||||
inviteMembersButton()
|
||||
.disabled(count < 1)
|
||||
@@ -78,14 +81,10 @@ struct AddGroupMembersView: View {
|
||||
}
|
||||
}
|
||||
|
||||
if (showSkip) {
|
||||
if creatingGroup {
|
||||
v.toolbar {
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
if showSkip {
|
||||
Button ("Skip") {
|
||||
if let cb = addedMembersCb { cb(selectedContacts) }
|
||||
}
|
||||
}
|
||||
Button ("Skip") { addedMembersCb?(selectedContacts) }
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -142,6 +141,7 @@ struct AddGroupMembersView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
.frame(height: 36)
|
||||
}
|
||||
|
||||
private func contactCheckView(_ contact: Contact) -> some View {
|
||||
|
||||
@@ -45,7 +45,7 @@ struct GroupChatInfoView: View {
|
||||
if groupInfo.canEdit {
|
||||
editGroupButton()
|
||||
}
|
||||
groupPreferencesButton()
|
||||
groupPreferencesButton($groupInfo)
|
||||
} header: {
|
||||
Text("")
|
||||
} footer: {
|
||||
@@ -200,20 +200,6 @@ struct GroupChatInfoView: View {
|
||||
}
|
||||
}
|
||||
|
||||
func groupPreferencesButton() -> some View {
|
||||
NavigationLink {
|
||||
GroupPreferencesView(
|
||||
groupInfo: $groupInfo,
|
||||
preferences: groupInfo.fullGroupPreferences,
|
||||
currentPreferences: groupInfo.fullGroupPreferences
|
||||
)
|
||||
.navigationBarTitle("Group preferences")
|
||||
.navigationBarTitleDisplayMode(.large)
|
||||
} label: {
|
||||
Label("Group preferences", systemImage: "switch.2")
|
||||
}
|
||||
}
|
||||
|
||||
func editGroupButton() -> some View {
|
||||
NavigationLink {
|
||||
GroupProfileView(
|
||||
@@ -310,6 +296,25 @@ struct GroupChatInfoView: View {
|
||||
}
|
||||
}
|
||||
|
||||
func groupPreferencesButton(_ groupInfo: Binding<GroupInfo>, _ creatingGroup: Bool = false) -> some View {
|
||||
NavigationLink {
|
||||
GroupPreferencesView(
|
||||
groupInfo: groupInfo,
|
||||
preferences: groupInfo.wrappedValue.fullGroupPreferences,
|
||||
currentPreferences: groupInfo.wrappedValue.fullGroupPreferences,
|
||||
creatingGroup: creatingGroup
|
||||
)
|
||||
.navigationBarTitle("Group preferences")
|
||||
.navigationBarTitleDisplayMode(.large)
|
||||
} label: {
|
||||
if creatingGroup {
|
||||
Text("Set group preferences")
|
||||
} else {
|
||||
Label("Group preferences", systemImage: "switch.2")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func cantInviteIncognitoAlert() -> Alert {
|
||||
Alert(
|
||||
title: Text("Can't invite contacts!"),
|
||||
|
||||
@@ -10,12 +10,16 @@ import SwiftUI
|
||||
import SimpleXChat
|
||||
|
||||
struct GroupPreferencesView: View {
|
||||
@Environment(\.dismiss) var dismiss: DismissAction
|
||||
@EnvironmentObject var chatModel: ChatModel
|
||||
@Binding var groupInfo: GroupInfo
|
||||
@State var preferences: FullGroupPreferences
|
||||
@State var currentPreferences: FullGroupPreferences
|
||||
let creatingGroup: Bool
|
||||
@State private var showSaveDialogue = false
|
||||
|
||||
var body: some View {
|
||||
let saveText: LocalizedStringKey = creatingGroup ? "Save" : "Save and notify group members"
|
||||
VStack {
|
||||
List {
|
||||
featureSection(.fullDelete, $preferences.fullDelete.enable)
|
||||
@@ -25,18 +29,34 @@ struct GroupPreferencesView: View {
|
||||
if groupInfo.canEdit {
|
||||
Section {
|
||||
Button("Reset") { preferences = currentPreferences }
|
||||
Button("Save (and notify group members)") { savePreferences() }
|
||||
Button(saveText) { savePreferences() }
|
||||
}
|
||||
.disabled(currentPreferences == preferences)
|
||||
}
|
||||
}
|
||||
}
|
||||
.modifier(BackButton {
|
||||
if currentPreferences == preferences {
|
||||
dismiss()
|
||||
} else {
|
||||
showSaveDialogue = true
|
||||
}
|
||||
})
|
||||
.confirmationDialog("Save preferences?", isPresented: $showSaveDialogue) {
|
||||
Button(saveText) {
|
||||
savePreferences()
|
||||
dismiss()
|
||||
}
|
||||
Button("Exit without saving") { dismiss() }
|
||||
}
|
||||
}
|
||||
|
||||
private func featureSection(_ feature: GroupFeature, _ enableFeature: Binding<GroupFeatureEnabled>) -> some View {
|
||||
Section {
|
||||
let color: Color = enableFeature.wrappedValue == .on ? .green : .secondary
|
||||
let icon = enableFeature.wrappedValue == .on ? feature.iconFilled : feature.icon
|
||||
if (groupInfo.canEdit) {
|
||||
settingsRow(feature.icon) {
|
||||
settingsRow(icon, color: color) {
|
||||
Picker(feature.text, selection: enableFeature) {
|
||||
ForEach(GroupFeatureEnabled.values) { enable in
|
||||
Text(enable.text)
|
||||
@@ -46,7 +66,7 @@ struct GroupPreferencesView: View {
|
||||
}
|
||||
}
|
||||
else {
|
||||
settingsRow(feature.icon) {
|
||||
settingsRow(icon, color: color) {
|
||||
infoRow(feature.text, enableFeature.wrappedValue.text)
|
||||
}
|
||||
}
|
||||
@@ -79,7 +99,8 @@ struct GroupPreferencesView_Previews: PreviewProvider {
|
||||
GroupPreferencesView(
|
||||
groupInfo: Binding.constant(GroupInfo.sampleData),
|
||||
preferences: FullGroupPreferences.sampleData,
|
||||
currentPreferences: FullGroupPreferences.sampleData
|
||||
currentPreferences: FullGroupPreferences.sampleData,
|
||||
creatingGroup: false
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user