chore: add navigation to ThreadScene

This commit is contained in:
sunxiaojian 2021-04-18 22:00:19 +08:00
parent 780025a3ce
commit 462fafe706
2 changed files with 20 additions and 19 deletions

View File

@ -119,7 +119,7 @@ extension NotificationViewController {
} else { } else {
viewModel.notificationPredicate.value = MastodonNotification.predicate(domain: domain, userID: userID, typeRaw: Mastodon.Entity.Notification.NotificationType.mention.rawValue) viewModel.notificationPredicate.value = MastodonNotification.predicate(domain: domain, userID: userID, typeRaw: Mastodon.Entity.Notification.NotificationType.mention.rawValue)
} }
viewModel.selectedIndex.value = NotificationViewModel.NotificationSegment.init(rawValue: sender.selectedSegmentIndex)! viewModel.selectedIndex.value = NotificationViewModel.NotificationSegment(rawValue: sender.selectedSegmentIndex)!
} }
@objc private func refreshControlValueChanged(_ sender: UIRefreshControl) { @objc private func refreshControlValueChanged(_ sender: UIRefreshControl) {
@ -134,18 +134,18 @@ extension NotificationViewController {
extension NotificationViewController: UITableViewDelegate { extension NotificationViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
guard let diffableDataSource = viewModel.diffableDataSource else { return } guard let diffableDataSource = viewModel.diffableDataSource else { return }
guard let item = diffableDataSource.itemIdentifier(for: indexPath) else { return } guard let item = diffableDataSource.itemIdentifier(for: indexPath) else { return }
switch item { switch item {
case .notification(let objectID): case .notification(let objectID):
let notification = context.managedObjectContext.object(with: objectID) as! MastodonNotification let notification = context.managedObjectContext.object(with: objectID) as! MastodonNotification
if notification.status != nil { if let status = notification.status {
// TODO: goto status detail vc let viewModel = ThreadViewModel(context: context, optionalStatus: status)
coordinator.present(scene: .thread(viewModel: viewModel), from: self, transition: .show)
} else { } else {
let viewModel = ProfileViewModel(context: context, optionalMastodonUser: notification.account) let viewModel = ProfileViewModel(context: context, optionalMastodonUser: notification.account)
DispatchQueue.main.async { coordinator.present(scene: .profile(viewModel: viewModel), from: self, transition: .show)
self.coordinator.present(scene: .profile(viewModel: viewModel), from: self, transition: .show)
}
} }
default: default:
break break

View File

@ -76,6 +76,7 @@ extension NotificationViewModel: NSFetchedResultsControllerDelegate {
guard let difference = self.calculateReloadSnapshotDifference(navigationBar: navigationBar, tableView: tableView, oldSnapshot: oldSnapshot, newSnapshot: newSnapshot) else { guard let difference = self.calculateReloadSnapshotDifference(navigationBar: navigationBar, tableView: tableView, oldSnapshot: oldSnapshot, newSnapshot: newSnapshot) else {
diffableDataSource.apply(newSnapshot, animatingDifferences: false) diffableDataSource.apply(newSnapshot, animatingDifferences: false)
self.isFetchingLatestNotification.value = false self.isFetchingLatestNotification.value = false
tableView.reloadData()
return return
} }