[iOS] Select all Users When Editing (#1373)
This commit is contained in:
parent
af602d3d98
commit
2f13093cc0
|
@ -17,4 +17,10 @@ extension Set {
|
||||||
insert(value)
|
insert(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mutating func insert(contentsOf elements: [Element]) {
|
||||||
|
for element in elements {
|
||||||
|
insert(element)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,9 @@ import SwiftUI
|
||||||
// TODO: user ordering
|
// TODO: user ordering
|
||||||
// - name
|
// - name
|
||||||
// - last signed in date
|
// - last signed in date
|
||||||
|
// TODO: between the server selection menu and delete toolbar,
|
||||||
|
// figure out a way to make the grid/list and splash screen
|
||||||
|
// not jump when size is changed
|
||||||
|
|
||||||
struct SelectUserView: View {
|
struct SelectUserView: View {
|
||||||
|
|
||||||
|
@ -85,6 +88,17 @@ struct SelectUserView: View {
|
||||||
@State
|
@State
|
||||||
private var error: Error? = nil
|
private var error: Error? = nil
|
||||||
|
|
||||||
|
private var users: [UserState] {
|
||||||
|
gridItems.compactMap { item in
|
||||||
|
switch item {
|
||||||
|
case let .user(user, _):
|
||||||
|
return user
|
||||||
|
default:
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Select Server
|
// MARK: - Select Server
|
||||||
|
|
||||||
private var selectedServer: ServerState? {
|
private var selectedServer: ServerState? {
|
||||||
|
@ -380,33 +394,6 @@ struct SelectUserView: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Delete Users Button
|
|
||||||
|
|
||||||
@ViewBuilder
|
|
||||||
private var deleteUsersButton: some View {
|
|
||||||
Button {
|
|
||||||
isPresentingConfirmDeleteUsers = true
|
|
||||||
} label: {
|
|
||||||
ZStack {
|
|
||||||
Color.red
|
|
||||||
|
|
||||||
Text(L10n.delete)
|
|
||||||
.font(.body.weight(.semibold))
|
|
||||||
.foregroundStyle(selectedUsers.isNotEmpty ? .primary : .secondary)
|
|
||||||
|
|
||||||
if selectedUsers.isEmpty {
|
|
||||||
Color.black
|
|
||||||
.opacity(0.5)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.clipShape(RoundedRectangle(cornerRadius: 10))
|
|
||||||
.frame(height: 50)
|
|
||||||
.frame(maxWidth: 400)
|
|
||||||
}
|
|
||||||
.disabled(selectedUsers.isEmpty)
|
|
||||||
.buttonStyle(.plain)
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - User View
|
// MARK: - User View
|
||||||
|
|
||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
|
@ -453,11 +440,6 @@ struct SelectUserView: View {
|
||||||
)
|
)
|
||||||
.edgePadding([.bottom, .horizontal])
|
.edgePadding([.bottom, .horizontal])
|
||||||
}
|
}
|
||||||
|
|
||||||
if isEditingUsers {
|
|
||||||
deleteUsersButton
|
|
||||||
.edgePadding([.bottom, .horizontal])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.background {
|
.background {
|
||||||
if selectUserUseSplashscreen, splashScreenImageSources.isNotEmpty {
|
if selectUserUseSplashscreen, splashScreenImageSources.isNotEmpty {
|
||||||
|
@ -516,28 +498,49 @@ struct SelectUserView: View {
|
||||||
.aspectRatio(contentMode: .fit)
|
.aspectRatio(contentMode: .fit)
|
||||||
.frame(width: 30)
|
.frame(width: 30)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
.topBarTrailing {
|
ToolbarItem(placement: .topBarLeading) {
|
||||||
if isEditingUsers {
|
if isEditingUsers {
|
||||||
Button {
|
if selectedUsers.count == users.count {
|
||||||
isEditingUsers = false
|
Button(L10n.removeAll) {
|
||||||
} label: {
|
selectedUsers.removeAll()
|
||||||
L10n.cancel.text
|
|
||||||
.font(.headline)
|
|
||||||
.padding(.vertical, 5)
|
|
||||||
.padding(.horizontal, 10)
|
|
||||||
.background {
|
|
||||||
if colorScheme == .light {
|
|
||||||
Color.secondarySystemFill
|
|
||||||
} else {
|
|
||||||
Color.tertiarySystemBackground
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
.clipShape(RoundedRectangle(cornerRadius: 10))
|
.buttonStyle(.toolbarPill)
|
||||||
|
} else {
|
||||||
|
Button(L10n.selectAll) {
|
||||||
|
selectedUsers.insert(contentsOf: users)
|
||||||
|
}
|
||||||
|
.buttonStyle(.toolbarPill)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ToolbarItemGroup(placement: .topBarTrailing) {
|
||||||
|
if isEditingUsers {
|
||||||
|
Button(isEditingUsers ? L10n.cancel : L10n.edit) {
|
||||||
|
isEditingUsers.toggle()
|
||||||
|
|
||||||
|
UIDevice.impact(.light)
|
||||||
|
|
||||||
|
if !isEditingUsers {
|
||||||
|
selectedUsers.removeAll()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.buttonStyle(.toolbarPill)
|
||||||
|
} else {
|
||||||
|
advancedMenu
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ToolbarItem(placement: .bottomBar) {
|
||||||
|
if isEditingUsers {
|
||||||
|
Button(L10n.delete) {
|
||||||
|
isPresentingConfirmDeleteUsers = true
|
||||||
|
}
|
||||||
|
.buttonStyle(.toolbarPill(.red))
|
||||||
|
.disabled(selectedUsers.isEmpty)
|
||||||
|
.frame(maxWidth: .infinity, alignment: .trailing)
|
||||||
}
|
}
|
||||||
.buttonStyle(.plain)
|
|
||||||
} else {
|
|
||||||
advancedMenu
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.onAppear {
|
.onAppear {
|
||||||
|
|
Loading…
Reference in New Issue