generated from element-hq/.github
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* created the basic navigation and files * updated the logic so that the buttons that do not have permissions won't show * added the empty state * progress in making the list UI * update tests * UI improvements * fixed an issue with media provider * update button style * fixed a navigation bug * pr suggestions * pr suggestions
- Loading branch information
Showing
85 changed files
with
701 additions
and
145 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
ElementX/Sources/Screens/KnockRequestsListScreen/KnockRequestsListScreenCoordinator.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// Copyright 2022-2024 New Vector Ltd. | ||
// | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
// Please see LICENSE in the repository root for full details. | ||
// | ||
|
||
// periphery:ignore:all - this is just a knockRequestsList remove this comment once generating the final file | ||
|
||
import Combine | ||
import SwiftUI | ||
|
||
struct KnockRequestsListScreenCoordinatorParameters { | ||
let roomProxy: JoinedRoomProxyProtocol | ||
let mediaProvider: MediaProviderProtocol | ||
} | ||
|
||
enum KnockRequestsListScreenCoordinatorAction { } | ||
|
||
final class KnockRequestsListScreenCoordinator: CoordinatorProtocol { | ||
private let viewModel: KnockRequestsListScreenViewModelProtocol | ||
|
||
private var cancellables = Set<AnyCancellable>() | ||
|
||
private let actionsSubject: PassthroughSubject<KnockRequestsListScreenCoordinatorAction, Never> = .init() | ||
var actionsPublisher: AnyPublisher<KnockRequestsListScreenCoordinatorAction, Never> { | ||
actionsSubject.eraseToAnyPublisher() | ||
} | ||
|
||
init(parameters: KnockRequestsListScreenCoordinatorParameters) { | ||
viewModel = KnockRequestsListScreenViewModel(roomProxy: parameters.roomProxy, | ||
mediaProvider: parameters.mediaProvider) | ||
} | ||
|
||
func start() { | ||
viewModel.actionsPublisher.sink { [weak self] action in | ||
MXLog.info("Coordinator: received view model action: \(action)") | ||
} | ||
.store(in: &cancellables) | ||
} | ||
|
||
func toPresentable() -> AnyView { | ||
AnyView(KnockRequestsListScreen(context: viewModel.context)) | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
ElementX/Sources/Screens/KnockRequestsListScreen/KnockRequestsListScreenModels.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// Copyright 2022-2024 New Vector Ltd. | ||
// | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
// Please see LICENSE in the repository root for full details. | ||
// | ||
|
||
import Foundation | ||
|
||
enum KnockRequestsListScreenViewModelAction { } | ||
|
||
struct KnockRequestsListScreenViewState: BindableState { | ||
var requests: [KnockRequestCellInfo] = [] | ||
var canAccept = false | ||
var canDecline = false | ||
var canBan = false | ||
} | ||
|
||
enum KnockRequestsListScreenViewAction { | ||
case acceptAllRequests | ||
case acceptRequest(userID: String) | ||
case declineRequest(userID: String) | ||
case ban(userID: String) | ||
} |
75 changes: 75 additions & 0 deletions
75
ElementX/Sources/Screens/KnockRequestsListScreen/KnockRequestsListScreenViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// | ||
// Copyright 2022-2024 New Vector Ltd. | ||
// | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
// Please see LICENSE in the repository root for full details. | ||
// | ||
|
||
import Combine | ||
import SwiftUI | ||
|
||
typealias KnockRequestsListScreenViewModelType = StateStoreViewModel<KnockRequestsListScreenViewState, KnockRequestsListScreenViewAction> | ||
|
||
class KnockRequestsListScreenViewModel: KnockRequestsListScreenViewModelType, KnockRequestsListScreenViewModelProtocol { | ||
private let roomProxy: JoinedRoomProxyProtocol | ||
|
||
private let actionsSubject: PassthroughSubject<KnockRequestsListScreenViewModelAction, Never> = .init() | ||
var actionsPublisher: AnyPublisher<KnockRequestsListScreenViewModelAction, Never> { | ||
actionsSubject.eraseToAnyPublisher() | ||
} | ||
|
||
init(roomProxy: JoinedRoomProxyProtocol, mediaProvider: MediaProviderProtocol) { | ||
self.roomProxy = roomProxy | ||
super.init(initialViewState: KnockRequestsListScreenViewState(), mediaProvider: mediaProvider) | ||
|
||
Task { | ||
await updatePermissions() | ||
} | ||
|
||
setupSubscriptions() | ||
} | ||
|
||
// MARK: - Public | ||
|
||
override func process(viewAction: KnockRequestsListScreenViewAction) { | ||
switch viewAction { | ||
case .acceptAllRequests: | ||
break | ||
case .acceptRequest(let userID): | ||
break | ||
case .declineRequest(let userID): | ||
break | ||
case .ban(let userID): | ||
break | ||
} | ||
} | ||
|
||
// MARK: - Private | ||
|
||
private func setupSubscriptions() { | ||
roomProxy.infoPublisher | ||
.throttle(for: .milliseconds(200), scheduler: DispatchQueue.main, latest: true) | ||
.sink { [weak self] _ in | ||
Task { await self?.updatePermissions() } | ||
} | ||
.store(in: &cancellables) | ||
} | ||
|
||
private func updatePermissions() async { | ||
state.canAccept = await (try? roomProxy.canUserInvite(userID: roomProxy.ownUserID).get()) == true | ||
state.canDecline = await (try? roomProxy.canUserKick(userID: roomProxy.ownUserID).get()) == true | ||
state.canBan = await (try? roomProxy.canUserBan(userID: roomProxy.ownUserID).get()) == true | ||
} | ||
|
||
// For testing purposes | ||
private init(initialViewState: KnockRequestsListScreenViewState) { | ||
roomProxy = JoinedRoomProxyMock(.init()) | ||
super.init(initialViewState: initialViewState) | ||
} | ||
} | ||
|
||
extension KnockRequestsListScreenViewModel { | ||
static func mockWithInitialState(_ initialViewState: KnockRequestsListScreenViewState) -> KnockRequestsListScreenViewModel { | ||
.init(initialViewState: initialViewState) | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...tX/Sources/Screens/KnockRequestsListScreen/KnockRequestsListScreenViewModelProtocol.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// Copyright 2022-2024 New Vector Ltd. | ||
// | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
// Please see LICENSE in the repository root for full details. | ||
// | ||
|
||
import Combine | ||
|
||
@MainActor | ||
protocol KnockRequestsListScreenViewModelProtocol { | ||
var actionsPublisher: AnyPublisher<KnockRequestsListScreenViewModelAction, Never> { get } | ||
var context: KnockRequestsListScreenViewModelType.Context { get } | ||
} |
Oops, something went wrong.