mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2024-12-17 17:20:21 +01:00
ios: groups miscellaneous (#843)
Co-authored-by: Evgeny Poberezkin <2769109+epoberezkin@users.noreply.github.com>
This commit is contained in:
@@ -12,56 +12,53 @@ import SimpleXChat
|
||||
struct AddGroupMembersView: View {
|
||||
@EnvironmentObject var chatModel: ChatModel
|
||||
var chat: Chat
|
||||
var groupInfo: GroupInfo
|
||||
@Binding var showSheet: Bool
|
||||
@State private var contactsToAdd: [Contact] = []
|
||||
@State private var selectedContacts = Set<Int64>()
|
||||
@State private var selectedRole: GroupMemberRole = .admin
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 0) {
|
||||
ChatInfoToolbar(chat: chat, imageSize: 48)
|
||||
.padding()
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
.background(Color(uiColor: .quaternarySystemFill))
|
||||
if (contactsToAdd.isEmpty) {
|
||||
Text("No contacts to add")
|
||||
.foregroundColor(.secondary)
|
||||
.padding()
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
} else {
|
||||
HStack {
|
||||
let count = selectedContacts.count
|
||||
Button {
|
||||
Task {
|
||||
for contactId in selectedContacts {
|
||||
await addMember(groupId: chat.chatInfo.apiId, contactId: contactId)
|
||||
}
|
||||
showSheet = false
|
||||
}
|
||||
} label: {
|
||||
Label(
|
||||
count > 0 ? "Invite \(count) member(s)" : "Invite new members",
|
||||
systemImage: "plus")
|
||||
}
|
||||
.disabled(count < 1)
|
||||
Spacer()
|
||||
if count > 0 {
|
||||
Button {
|
||||
selectedContacts.removeAll()
|
||||
} label: {
|
||||
Label("Clear", systemImage: "multiply")
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.horizontal)
|
||||
.padding(.bottom, 12)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.background(Color(uiColor: .quaternarySystemFill))
|
||||
List(contactsToAdd) { contact in
|
||||
contactCheckView(contact)
|
||||
NavigationView {
|
||||
List {
|
||||
ChatInfoToolbar(chat: chat, imageSize: 48)
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
.listRowBackground(Color.clear)
|
||||
.listRowSeparator(.hidden)
|
||||
|
||||
if (contactsToAdd.isEmpty) {
|
||||
Text("No contacts to add")
|
||||
.foregroundColor(.secondary)
|
||||
.padding()
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
.listRowBackground(Color.clear)
|
||||
} else {
|
||||
let count = selectedContacts.count
|
||||
Section {
|
||||
rolePicker()
|
||||
inviteMembersButton()
|
||||
.disabled(count < 1)
|
||||
} footer: {
|
||||
if (count >= 1) {
|
||||
HStack {
|
||||
Button { selectedContacts.removeAll() } label: { Text("Clear") }
|
||||
Spacer()
|
||||
Text("\(count) contact(s) selected")
|
||||
}
|
||||
} else {
|
||||
Text("No contacts selected")
|
||||
.frame(maxWidth: .infinity, alignment: .trailing)
|
||||
}
|
||||
}
|
||||
|
||||
Section {
|
||||
ForEach(contactsToAdd) { contact in
|
||||
contactCheckView(contact)
|
||||
}
|
||||
}
|
||||
}
|
||||
.listStyle(.plain)
|
||||
}
|
||||
.navigationBarHidden(true)
|
||||
}
|
||||
.frame(maxHeight: .infinity, alignment: .top)
|
||||
.task {
|
||||
@@ -78,6 +75,33 @@ struct AddGroupMembersView: View {
|
||||
.sorted{ $0.displayName.lowercased() < $1.displayName.lowercased() }
|
||||
}
|
||||
|
||||
func inviteMembersButton() -> some View {
|
||||
Button {
|
||||
Task {
|
||||
for contactId in selectedContacts {
|
||||
await addMember(groupId: chat.chatInfo.apiId, contactId: contactId, memberRole: selectedRole)
|
||||
}
|
||||
showSheet = false
|
||||
}
|
||||
} label: {
|
||||
HStack {
|
||||
Text("Invite to group")
|
||||
Image(systemName: "checkmark")
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .trailing)
|
||||
}
|
||||
|
||||
func rolePicker() -> some View {
|
||||
Picker("New member role", selection: $selectedRole) {
|
||||
ForEach(GroupMemberRole.allCases) { role in
|
||||
if role <= groupInfo.membership.memberRole {
|
||||
Text(role.text)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func contactCheckView(_ contact: Contact) -> some View {
|
||||
let checked = selectedContacts.contains(contact.apiId)
|
||||
return Button {
|
||||
@@ -92,10 +116,11 @@ struct AddGroupMembersView: View {
|
||||
.frame(width: 30, height: 30)
|
||||
.padding(.trailing, 2)
|
||||
Text(ChatInfo.direct(contact: contact).chatViewName)
|
||||
.foregroundColor(.primary)
|
||||
.lineLimit(1)
|
||||
Spacer()
|
||||
Image(systemName: checked ? "checkmark.circle.fill": "circle")
|
||||
.foregroundColor(checked ? .accentColor : .secondary)
|
||||
.foregroundColor(checked ? .accentColor : Color(uiColor: .tertiaryLabel))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -104,6 +129,6 @@ struct AddGroupMembersView: View {
|
||||
struct AddGroupMembersView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
@State var showSheet = true
|
||||
return AddGroupMembersView(chat: Chat(chatInfo: ChatInfo.sampleData.group), showSheet: $showSheet)
|
||||
return AddGroupMembersView(chat: Chat(chatInfo: ChatInfo.sampleData.group), groupInfo: GroupInfo.sampleData, showSheet: $showSheet)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user