mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-30 13:16:58 +02:00
Select All
This commit is contained in:
@@ -25,35 +25,9 @@ struct UserOtherSessions: View {
|
||||
ScrollView {
|
||||
SwiftUI.Section {
|
||||
if viewModel.viewState.items.isEmpty {
|
||||
VStack {
|
||||
Text(viewModel.viewState.emptyItemsTitle)
|
||||
.font(theme.fonts.footnote)
|
||||
.foregroundColor(theme.colors.primaryContent)
|
||||
.padding(.bottom, 20)
|
||||
Button {
|
||||
viewModel.send(viewAction: .clearFilter)
|
||||
} label: {
|
||||
VStack(spacing: 0) {
|
||||
SeparatorLine()
|
||||
Text(VectorL10n.userOtherSessionClearFilter)
|
||||
.font(theme.fonts.body)
|
||||
.foregroundColor(theme.colors.accent)
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
.padding(.vertical, 11)
|
||||
SeparatorLine()
|
||||
}
|
||||
.background(theme.colors.background)
|
||||
}
|
||||
}
|
||||
noItemsView()
|
||||
} else {
|
||||
LazyVStack(spacing: 0) {
|
||||
ForEach(viewModel.viewState.items) { viewData in
|
||||
UserSessionListItem(viewData: viewData, isEditModeEnabled: viewModel.isEditModeEnabled, onBackgroundTap: { sessionId in
|
||||
viewModel.send(viewAction: .userOtherSessionSelected(sessionId: sessionId))
|
||||
})
|
||||
}
|
||||
}
|
||||
.background(theme.colors.background)
|
||||
itemsView()
|
||||
}
|
||||
} header: {
|
||||
UserOtherSessionsHeaderView(viewData: viewModel.viewState.header)
|
||||
@@ -61,47 +35,60 @@ struct UserOtherSessions: View {
|
||||
.padding(.top, 24.0)
|
||||
}
|
||||
}
|
||||
.onChange(of: viewModel.isEditModeEnabled) { _ in
|
||||
viewModel.send(viewAction: .editModeWasToggled)
|
||||
}
|
||||
.onChange(of: viewModel.filter) { _ in
|
||||
viewModel.send(viewAction: .filterWasChanged)
|
||||
}
|
||||
.background(theme.colors.system.ignoresSafeArea())
|
||||
.frame(maxHeight: .infinity)
|
||||
.navigationTitle(viewModel.viewState.title)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
Menu {
|
||||
Picker("", selection: $viewModel.filter) {
|
||||
ForEach(UserOtherSessionsFilter.allCases) { filter in
|
||||
Text(filter.menuLocalizedName).tag(filter)
|
||||
}
|
||||
}
|
||||
.labelsHidden()
|
||||
.onChange(of: viewModel.filter) { _ in
|
||||
viewModel.send(viewAction: .filterWasChanged)
|
||||
}
|
||||
} label: {
|
||||
Image(viewModel.filter == .all ? Asset.Images.userOtherSessionsFilter.name : Asset.Images.userOtherSessionsFilterSelected.name)
|
||||
}
|
||||
.offset(x: 7)
|
||||
.accessibilityLabel(VectorL10n.userOtherSessionFilter)
|
||||
}
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
Menu {
|
||||
Button {
|
||||
viewModel.isEditModeEnabled.toggle()
|
||||
} label: {
|
||||
Label(VectorL10n.userOtherSessionMenuSelectSessions, systemImage: "checkmark.circle")
|
||||
}
|
||||
.onChange(of: viewModel.isEditModeEnabled) { _ in
|
||||
viewModel.send(viewAction: .editModeWasToggled)
|
||||
}
|
||||
} label: {
|
||||
Image(systemName: "ellipsis")
|
||||
.padding(.horizontal, 4)
|
||||
.padding(.vertical, 12)
|
||||
}
|
||||
.offset(x: 4)
|
||||
UserOtherSessionsToolbar(isEditModeEnabled: $viewModel.isEditModeEnabled,
|
||||
filter: $viewModel.filter,
|
||||
allItemsSelected: viewModel.viewState.allItemsSelected) {
|
||||
viewModel.send(viewAction: .toggleAllSelection)
|
||||
}
|
||||
}
|
||||
.navigationBarBackButtonHidden(viewModel.isEditModeEnabled)
|
||||
.accentColor(theme.colors.accent)
|
||||
}
|
||||
|
||||
private func noItemsView() -> some View {
|
||||
VStack {
|
||||
Text(viewModel.viewState.emptyItemsTitle)
|
||||
.font(theme.fonts.footnote)
|
||||
.foregroundColor(theme.colors.primaryContent)
|
||||
.padding(.bottom, 20)
|
||||
Button {
|
||||
viewModel.send(viewAction: .clearFilter)
|
||||
} label: {
|
||||
VStack(spacing: 0) {
|
||||
SeparatorLine()
|
||||
Text(VectorL10n.userOtherSessionClearFilter)
|
||||
.font(theme.fonts.body)
|
||||
.foregroundColor(theme.colors.accent)
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
.padding(.vertical, 11)
|
||||
SeparatorLine()
|
||||
}
|
||||
.background(theme.colors.background)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func itemsView() -> some View {
|
||||
LazyVStack(spacing: 0) {
|
||||
ForEach(viewModel.viewState.items) { viewData in
|
||||
UserSessionListItem(viewData: viewData,
|
||||
isEditModeEnabled: viewModel.isEditModeEnabled,
|
||||
onBackgroundTap: { sessionId in viewModel.send(viewAction: .userOtherSessionSelected(sessionId: sessionId)) },
|
||||
onBackgroundLongPress: { _ in viewModel.isEditModeEnabled = true })
|
||||
}
|
||||
}
|
||||
.background(theme.colors.background)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
//
|
||||
// Copyright 2022 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct UserOtherSessionsToolbar: ToolbarContent {
|
||||
@Environment(\.theme) private var theme
|
||||
|
||||
@Binding var isEditModeEnabled: Bool
|
||||
@Binding var filter: UserOtherSessionsFilter
|
||||
var allItemsSelected: Bool
|
||||
let onToggleSelection: () -> Void
|
||||
|
||||
var body: some ToolbarContent {
|
||||
navigationBarLeading()
|
||||
navigationBarTrailing()
|
||||
}
|
||||
|
||||
private func navigationBarLeading() -> some ToolbarContent {
|
||||
ToolbarItemGroup(placement: .navigationBarLeading) {
|
||||
if isEditModeEnabled {
|
||||
Button(allItemsSelected ? VectorL10n.deselectAll : VectorL10n.selectAll, action: {
|
||||
onToggleSelection()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func navigationBarTrailing() -> some ToolbarContent {
|
||||
ToolbarItemGroup(placement: .navigationBarTrailing) {
|
||||
if isEditModeEnabled {
|
||||
cancelButton()
|
||||
} else {
|
||||
filterMenuButton()
|
||||
.offset(x: 12)
|
||||
kebabMenu()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func cancelButton() -> some View {
|
||||
Button(VectorL10n.cancel) {
|
||||
isEditModeEnabled = false
|
||||
}
|
||||
.font(theme.fonts.bodySB)
|
||||
.foregroundColor(theme.colors.accent)
|
||||
}
|
||||
|
||||
private func filterMenuButton() -> some View {
|
||||
Button { } label: {
|
||||
Menu {
|
||||
Picker("", selection: $filter) {
|
||||
ForEach(UserOtherSessionsFilter.allCases) { filter in
|
||||
Text(filter.menuLocalizedName).tag(filter)
|
||||
}
|
||||
}
|
||||
.labelsHidden()
|
||||
} label: {
|
||||
Image(filter == .all ? Asset.Images.userOtherSessionsFilter.name : Asset.Images.userOtherSessionsFilterSelected.name)
|
||||
}
|
||||
|
||||
.accessibilityLabel(VectorL10n.userOtherSessionFilter)
|
||||
}
|
||||
}
|
||||
|
||||
private func kebabMenu() -> some View {
|
||||
Button { } label: {
|
||||
Menu {
|
||||
Button {
|
||||
isEditModeEnabled = true
|
||||
} label: {
|
||||
Label(VectorL10n.userOtherSessionMenuSelectSessions, systemImage: "checkmark.circle")
|
||||
}
|
||||
|
||||
} label: {
|
||||
Image(systemName: "ellipsis")
|
||||
.padding(.horizontal, 4)
|
||||
.padding(.vertical, 12)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user