mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-20 00:24:43 +02:00
App Layout: added space invites in space bottom sheet
This commit is contained in:
+41
-10
@@ -31,21 +31,45 @@ class SpaceSelectorService: SpaceSelectorServiceProtocol {
|
||||
private var spaceList: [SpaceSelectorListItemData] {
|
||||
let notificationCounter = session.spaceService.notificationCounter
|
||||
|
||||
let childSpaces: [SpaceSelectorListItemData]
|
||||
var invitedSpaces: [SpaceSelectorListItemData] = []
|
||||
var joinedSpaces: [SpaceSelectorListItemData] = []
|
||||
if let parentSpaceId = parentSpaceId, let parentSpace = session.spaceService.getSpace(withId: parentSpaceId) {
|
||||
childSpaces = parentSpace.childSpaces.compactMap { space in
|
||||
SpaceSelectorListItemData.itemData(with: space, notificationCounter: notificationCounter)
|
||||
for space in parentSpace.childSpaces {
|
||||
guard let item = SpaceSelectorListItemData.itemData(with: space, notificationCounter: notificationCounter) else {
|
||||
continue
|
||||
}
|
||||
|
||||
if item.isJoined {
|
||||
joinedSpaces.append(item)
|
||||
} else {
|
||||
invitedSpaces.append(item)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
childSpaces = session.spaceService.rootSpaces.compactMap { space in
|
||||
SpaceSelectorListItemData.itemData(with: space, notificationCounter: notificationCounter)
|
||||
for space in session.spaceService.rootSpaces {
|
||||
guard let item = SpaceSelectorListItemData.itemData(with: space, notificationCounter: notificationCounter) else {
|
||||
continue
|
||||
}
|
||||
|
||||
if item.isJoined {
|
||||
joinedSpaces.append(item)
|
||||
} else {
|
||||
invitedSpaces.append(item)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
guard !invitedSpaces.isEmpty || !joinedSpaces.isEmpty else {
|
||||
return []
|
||||
}
|
||||
|
||||
var itemList: [SpaceSelectorListItemData] = []
|
||||
itemList.append(contentsOf: invitedSpaces)
|
||||
if showHomeSpace && parentSpaceId == nil {
|
||||
itemList.append(SpaceSelectorListItemData(id: SpaceSelectorConstants.homeSpaceId, icon: Asset.Images.sideMenuActionIconFeedback.image, displayName: VectorL10n.allChatsTitle, isJoined: true))
|
||||
}
|
||||
itemList.append(contentsOf: joinedSpaces)
|
||||
|
||||
var itemList = showHomeSpace && parentSpaceId == nil && !childSpaces.isEmpty ? [SpaceSelectorListItemData(id: SpaceSelectorConstants.homeSpaceId, icon: Asset.Images.sideMenuActionIconFeedback.image, displayName: VectorL10n.allChatsTitle)] : []
|
||||
|
||||
itemList.append(contentsOf: childSpaces)
|
||||
|
||||
return itemList
|
||||
}
|
||||
|
||||
@@ -75,6 +99,12 @@ class SpaceSelectorService: SpaceSelectorServiceProtocol {
|
||||
|
||||
spaceListSubject.send(spaceList)
|
||||
parentSpaceNameSubject.send(parentSpaceName)
|
||||
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(self.spaceServiceDidUpdate), name: MXSpaceService.didBuildSpaceGraph, object: nil)
|
||||
}
|
||||
|
||||
@objc private func spaceServiceDidUpdate() {
|
||||
spaceListSubject.send(spaceList)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,6 +121,7 @@ fileprivate extension SpaceSelectorListItemData {
|
||||
displayName: summary.displayname,
|
||||
notificationCount: notificationState?.groupMissedDiscussionsCount ?? 0,
|
||||
highlightedNotificationCount: notificationState?.groupMissedDiscussionsHighlightedCount ?? 0,
|
||||
hasSubItems: !space.childSpaces.isEmpty)
|
||||
hasSubItems: !space.childSpaces.isEmpty,
|
||||
isJoined: summary.isJoined)
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -54,6 +54,8 @@ struct SpaceSelectorListItemData {
|
||||
let highlightedNotificationCount: UInt
|
||||
/// Indicates if the space has sub spaces (condition the display of the disclosure button)
|
||||
let hasSubItems: Bool
|
||||
/// Indicates if the space has has already been joined
|
||||
let isJoined: Bool
|
||||
|
||||
init(id: String,
|
||||
avatar: AvatarInput? = nil,
|
||||
@@ -61,7 +63,8 @@ struct SpaceSelectorListItemData {
|
||||
displayName: String?,
|
||||
notificationCount: UInt = 0,
|
||||
highlightedNotificationCount: UInt = 0,
|
||||
hasSubItems: Bool = false) {
|
||||
hasSubItems: Bool = false,
|
||||
isJoined: Bool = false) {
|
||||
self.id = id
|
||||
self.avatar = avatar
|
||||
self.icon = icon
|
||||
@@ -69,6 +72,7 @@ struct SpaceSelectorListItemData {
|
||||
self.notificationCount = notificationCount
|
||||
self.highlightedNotificationCount = highlightedNotificationCount
|
||||
self.hasSubItems = hasSubItems
|
||||
self.isJoined = isJoined
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+8
@@ -42,6 +42,7 @@ class SpaceSelectorViewModel: SpaceSelectorViewModelType, SpaceSelectorViewModel
|
||||
private init(service: SpaceSelectorServiceProtocol, showCancel: Bool) {
|
||||
self.service = service
|
||||
super.init(initialViewState: Self.defaultState(service: service, showCancel: showCancel))
|
||||
setupObservers()
|
||||
}
|
||||
|
||||
private static func defaultState(service: SpaceSelectorServiceProtocol, showCancel: Bool) -> SpaceSelectorViewState {
|
||||
@@ -52,6 +53,13 @@ class SpaceSelectorViewModel: SpaceSelectorViewModelType, SpaceSelectorViewModel
|
||||
showCancel: showCancel)
|
||||
}
|
||||
|
||||
private func setupObservers() {
|
||||
service.spaceListSubject.sink { [weak self] spaceList in
|
||||
self?.state.items = spaceList
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
override func process(viewAction: SpaceSelectorViewAction) {
|
||||
|
||||
+1
@@ -48,6 +48,7 @@ struct SpaceSelector: View {
|
||||
icon: item.icon,
|
||||
displayName: item.displayName,
|
||||
hasSubItems: item.hasSubItems,
|
||||
isJoined: item.isJoined,
|
||||
isSelected: item.id == viewModel.viewState.selectedSpaceId,
|
||||
notificationCount: item.notificationCount,
|
||||
highlightedNotificationCount: item.highlightedNotificationCount,
|
||||
|
||||
+25
-15
@@ -29,6 +29,7 @@ struct SpaceSelectorListRow: View {
|
||||
let icon: UIImage?
|
||||
let displayName: String?
|
||||
let hasSubItems: Bool
|
||||
let isJoined: Bool
|
||||
let isSelected: Bool
|
||||
let notificationCount: UInt
|
||||
let highlightedNotificationCount: UInt
|
||||
@@ -61,17 +62,15 @@ struct SpaceSelectorListRow: View {
|
||||
.accessibility(identifier: "itemName")
|
||||
Spacer()
|
||||
if notificationCount > 0 {
|
||||
Text("\(notificationCount)")
|
||||
.multilineTextAlignment(.center)
|
||||
.foregroundColor(theme.colors.background)
|
||||
.font(theme.fonts.footnote)
|
||||
.padding(.vertical, 2)
|
||||
.padding(.horizontal, 6)
|
||||
.background(highlightedNotificationCount > 0 ? theme.colors.alert : theme.colors.secondaryContent)
|
||||
.clipShape(Capsule())
|
||||
.accessibility(identifier: "notificationBadge")
|
||||
badge(with: "\(notificationCount)", color: highlightedNotificationCount > 0 ? theme.colors.alert : theme.colors.secondaryContent)
|
||||
}
|
||||
if hasSubItems {
|
||||
if !isJoined {
|
||||
badge(with: "! ", color: theme.colors.alert)
|
||||
Image(systemName: "chevron.right")
|
||||
.renderingMode(.template)
|
||||
.foregroundColor(theme.colors.secondaryContent)
|
||||
}
|
||||
if hasSubItems && isJoined {
|
||||
Button {
|
||||
disclosureAction?()
|
||||
} label: {
|
||||
@@ -91,6 +90,17 @@ struct SpaceSelectorListRow: View {
|
||||
.background(theme.colors.background)
|
||||
}
|
||||
|
||||
private func badge(with text: String, color: Color) -> some View {
|
||||
return Text(text)
|
||||
.multilineTextAlignment(.center)
|
||||
.foregroundColor(theme.colors.background)
|
||||
.font(theme.fonts.footnote)
|
||||
.padding(.vertical, 2)
|
||||
.padding(.horizontal, 6)
|
||||
.background(color)
|
||||
.clipShape(Capsule())
|
||||
.accessibility(identifier: "notificationBadge")
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
@@ -104,11 +114,11 @@ struct SpaceSelectorListRow_Previews: PreviewProvider {
|
||||
|
||||
static var sampleView: some View {
|
||||
VStack(spacing: 8) {
|
||||
SpaceSelectorListRow(avatar: nil, icon: UIImage(systemName: "house"), displayName: "Space name", hasSubItems: false, isSelected: false, notificationCount: 0, highlightedNotificationCount: 0, disclosureAction: nil)
|
||||
SpaceSelectorListRow(avatar: nil, icon: UIImage(systemName: "house"), displayName: "Space name", hasSubItems: true, isSelected: false, notificationCount: 0, highlightedNotificationCount: 0, disclosureAction: nil)
|
||||
SpaceSelectorListRow(avatar: nil, icon: UIImage(systemName: "house"), displayName: "Space name", hasSubItems: true, isSelected: false, notificationCount: 99, highlightedNotificationCount: 0, disclosureAction: nil)
|
||||
SpaceSelectorListRow(avatar: nil, icon: UIImage(systemName: "house"), displayName: "Space name", hasSubItems: false, isSelected: false, notificationCount: 99, highlightedNotificationCount: 1, disclosureAction: nil)
|
||||
SpaceSelectorListRow(avatar: nil, icon: UIImage(systemName: "house"), displayName: "Space name", hasSubItems: true, isSelected: true, notificationCount: 99, highlightedNotificationCount: 1, disclosureAction: nil)
|
||||
SpaceSelectorListRow(avatar: nil, icon: UIImage(systemName: "house"), displayName: "Space name", hasSubItems: false, isJoined: true, isSelected: false, notificationCount: 0, highlightedNotificationCount: 0, disclosureAction: nil)
|
||||
SpaceSelectorListRow(avatar: nil, icon: UIImage(systemName: "house"), displayName: "Space name", hasSubItems: true, isJoined: true, isSelected: false, notificationCount: 0, highlightedNotificationCount: 0, disclosureAction: nil)
|
||||
SpaceSelectorListRow(avatar: nil, icon: UIImage(systemName: "house"), displayName: "Space name", hasSubItems: true, isJoined: true, isSelected: false, notificationCount: 99, highlightedNotificationCount: 0, disclosureAction: nil)
|
||||
SpaceSelectorListRow(avatar: nil, icon: UIImage(systemName: "house"), displayName: "Space name", hasSubItems: false, isJoined: true, isSelected: false, notificationCount: 99, highlightedNotificationCount: 1, disclosureAction: nil)
|
||||
SpaceSelectorListRow(avatar: nil, icon: UIImage(systemName: "house"), displayName: "Space name", hasSubItems: true, isJoined: true, isSelected: true, notificationCount: 99, highlightedNotificationCount: 1, disclosureAction: nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user