Report Content v2 (#659)

* created the empty files

* set up the view content

* connected the Room Coordinator to the ReportContent Coordinator

* added the loading indicators and the dismiss behaviour

* almost completed but I need to display the success indicator when the report is sent succesfully

* completed

* added an untranslated string

* tests

* Update ElementX/Sources/Screens/RoomScreen/RoomScreenCoordinator.swift

Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com>

* Update ElementX/Sources/Screens/ReportContent/View/ReportContentScreen.swift

Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com>

* pr comment

* pr suggestion

* removing unused identifiers

* fixing compilation error

* added a form text editor view

* changelog

---------

Co-authored-by: Doug <6060466+pixlwave@users.noreply.github.com>
This commit is contained in:
Mauro
2023-03-02 19:24:10 +01:00
committed by GitHub
parent 1c09a7eace
commit eed031c9cc
27 changed files with 472 additions and 85 deletions
@@ -54,6 +54,8 @@ final class RoomScreenCoordinator: CoordinatorProtocol {
self.displayFile(for: fileURL, with: title)
case .displayEmojiPicker(let itemId):
self.displayEmojiPickerScreen(for: itemId)
case .displayReportContent(let itemId):
self.displayReportContent(for: itemId)
}
}
}
@@ -115,4 +117,27 @@ final class RoomScreenCoordinator: CoordinatorProtocol {
navigationStackCoordinator.push(coordinator)
}
private func displayReportContent(for itemId: String) {
let navigationCoordinator = NavigationStackCoordinator()
let userIndicatorController = UserIndicatorController(rootCoordinator: NavigationStackCoordinator())
let parameters = ReportContentCoordinatorParameters(itemID: itemId,
roomProxy: parameters.roomProxy,
userIndicatorController: userIndicatorController)
let coordinator = ReportContentCoordinator(parameters: parameters)
coordinator.callback = { [weak self] completion in
self?.navigationStackCoordinator.setSheetCoordinator(nil)
switch completion {
case .cancel: break
case .finish:
self?.showSuccess(label: ElementL10n.reportContentSubmitted)
}
}
navigationCoordinator.setRootCoordinator(coordinator)
navigationStackCoordinator.setSheetCoordinator(userIndicatorController)
}
private func showSuccess(label: String) {
ServiceLocator.shared.userIndicatorController.submitIndicator(UserIndicator(title: label, iconName: "checkmark"))
}
}
@@ -23,6 +23,7 @@ enum RoomScreenViewModelAction {
case displayVideo(videoURL: URL, title: String?)
case displayFile(fileURL: URL, title: String?)
case displayEmojiPicker(itemId: String)
case displayReportContent(itemId: String)
}
enum RoomScreenComposerMode: Equatable {
@@ -55,7 +56,6 @@ enum RoomScreenViewAction {
/// Mark the entire room as read - this is heavy handed as a starting point for now.
case markRoomAsRead
case contextMenuAction(itemID: String, action: TimelineItemContextMenuAction)
case report(itemID: String, reason: String)
}
struct RoomScreenViewState: BindableState {
@@ -91,25 +91,6 @@ struct RoomScreenViewStateBindings {
var alertInfo: AlertInfo<RoomScreenErrorType>?
var debugInfo: TimelineItemDebugView.DebugInfo?
// Report
var report: ReportAlertItem?
}
final class ReportAlertItem: AlertItem {
init(itemID: String) {
self.itemID = itemID
}
let title = ElementL10n.reportContentCustomHint
let itemID: String
private(set) var reason = ""
lazy var reasonBinding = Binding<String>(get: { [unowned self] in
self.reason
}, set: { [unowned self] newValue in
self.reason = newValue
})
}
enum RoomScreenErrorType: Hashable {
@@ -111,8 +111,6 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
await markRoomAsRead()
case .contextMenuAction(let itemID, let action):
processContentMenuAction(action, itemID: itemID)
case let .report(itemID, reason):
await timelineController.reportContent(itemID, reason: reason)
}
}
@@ -320,7 +318,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
await timelineController.retryDecryption(for: sessionID)
}
case .report:
state.bindings.report = ReportAlertItem(itemID: itemID)
callback?(.displayReportContent(itemId: itemID))
}
if action.switchToDefaultComposer {
@@ -30,8 +30,6 @@ struct RoomScreen: View {
.toolbarBackground(.visible, for: .navigationBar) // Fix the toolbar's background.
.overlay { loadingIndicator }
.alert(item: $context.alertInfo) { $0.alert }
.alert(item: $context.report,
actions: { reportAlertActions($0) })
.sheet(item: $context.debugInfo) { TimelineItemDebugView(info: $0) }
.task(id: context.viewState.roomId) {
// Give a couple of seconds for items to load and to see them.
@@ -41,15 +39,6 @@ struct RoomScreen: View {
context.send(viewAction: .markRoomAsRead)
}
}
@ViewBuilder
func reportAlertActions(_ report: ReportAlertItem) -> some View {
TextField("", text: report.reasonBinding)
Button(ElementL10n.actionSend, action: {
context.send(viewAction: .report(itemID: report.itemID, reason: report.reason))
})
Button(ElementL10n.actionCancel, role: .cancel, action: { })
}
var timeline: some View {
TimelineView()