From 395da6f0c3786e52a6ecaf9ec473d54eec43abc6 Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Fri, 10 Nov 2023 13:52:49 +0100 Subject: [PATCH] Minor cleanup (IOS-186) --- .../FollowedTagsViewController.swift | 7 +---- ...owedTagsViewModel+DiffableDataSource.swift | 1 - .../FollowedTags/FollowedTagsViewModel.swift | 30 ++++++++----------- 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/Mastodon/Scene/Profile/FollowedTags/FollowedTagsViewController.swift b/Mastodon/Scene/Profile/FollowedTags/FollowedTagsViewController.swift index 231e91fa3..d92a4e977 100644 --- a/Mastodon/Scene/Profile/FollowedTags/FollowedTagsViewController.swift +++ b/Mastodon/Scene/Profile/FollowedTags/FollowedTagsViewController.swift @@ -5,9 +5,7 @@ // Created by Marcus Kida on 22.11.22. // -import os import UIKit -import Combine import MastodonAsset import MastodonCore import MastodonUI @@ -42,14 +40,11 @@ final class FollowedTagsViewController: UIViewController, NeedsDependency { super.init(nibName: nil, bundle: nil) - let title = L10n.Scene.FollowedTags.title - self.title = title + title = L10n.Scene.FollowedTags.title view.backgroundColor = .secondarySystemBackground - view.addSubview(tableView) tableView.pinToParent() - tableView.delegate = self refreshControl.addTarget(self, action: #selector(FollowedTagsViewController.refresh(_:)), for: .valueChanged) diff --git a/Mastodon/Scene/Profile/FollowedTags/FollowedTagsViewModel+DiffableDataSource.swift b/Mastodon/Scene/Profile/FollowedTags/FollowedTagsViewModel+DiffableDataSource.swift index 9518768dc..781bc353a 100644 --- a/Mastodon/Scene/Profile/FollowedTags/FollowedTagsViewModel+DiffableDataSource.swift +++ b/Mastodon/Scene/Profile/FollowedTags/FollowedTagsViewModel+DiffableDataSource.swift @@ -6,7 +6,6 @@ // import UIKit -import Combine import MastodonSDK import MastodonCore diff --git a/Mastodon/Scene/Profile/FollowedTags/FollowedTagsViewModel.swift b/Mastodon/Scene/Profile/FollowedTags/FollowedTagsViewModel.swift index 00c6a5a9e..0797f241f 100644 --- a/Mastodon/Scene/Profile/FollowedTags/FollowedTagsViewModel.swift +++ b/Mastodon/Scene/Profile/FollowedTags/FollowedTagsViewModel.swift @@ -5,14 +5,11 @@ // Created by Marcus Kida on 23.11.22. // -import os import UIKit -import Combine import MastodonSDK import MastodonCore final class FollowedTagsViewModel: NSObject { - var disposeBag = Set() private(set) var followedTags: [Mastodon.Entity.Tag] private weak var tableView: UITableView? @@ -21,10 +18,7 @@ final class FollowedTagsViewModel: NSObject { // input let context: AppContext let authContext: AuthContext - - // output - let presentHashtagTimeline = PassthroughSubject() - + init(context: AppContext, authContext: AuthContext) { self.context = context self.authContext = authContext @@ -43,18 +37,20 @@ extension FollowedTagsViewModel { func fetchFollowedTags(completion: (() -> Void)? = nil ) { Task { @MainActor in - followedTags = try await context.apiService.getFollowedTags( - domain: authContext.mastodonAuthenticationBox.domain, - query: Mastodon.API.Account.FollowedTagsQuery(limit: nil), - authenticationBox: authContext.mastodonAuthenticationBox - ).value + do { + followedTags = try await context.apiService.getFollowedTags( + domain: authContext.mastodonAuthenticationBox.domain, + query: Mastodon.API.Account.FollowedTagsQuery(limit: nil), + authenticationBox: authContext.mastodonAuthenticationBox + ).value - var snapshot = NSDiffableDataSourceSnapshot() - snapshot.appendSections([.main]) - let items = followedTags.compactMap { Item.hashtag($0) } - snapshot.appendItems(items, toSection: .main) + var snapshot = NSDiffableDataSourceSnapshot() + snapshot.appendSections([.main]) + let items = followedTags.compactMap { Item.hashtag($0) } + snapshot.appendItems(items, toSection: .main) - await diffableDataSource?.apply(snapshot) + await diffableDataSource?.apply(snapshot) + } catch {} completion?() }