Skip to content

Commit

Permalink
Minor cleanup (IOS-186)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitschlag committed Nov 10, 2023
1 parent 8956d79 commit 580c931
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
// Created by Marcus Kida on 22.11.22.
//

import os
import UIKit
import Combine
import MastodonAsset
import MastodonCore
import MastodonUI
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//

import UIKit
import Combine
import MastodonSDK
import MastodonCore

Expand Down
30 changes: 13 additions & 17 deletions Mastodon/Scene/Profile/FollowedTags/FollowedTagsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<AnyCancellable>()
private(set) var followedTags: [Mastodon.Entity.Tag]

private weak var tableView: UITableView?
Expand All @@ -21,10 +18,7 @@ final class FollowedTagsViewModel: NSObject {
// input
let context: AppContext
let authContext: AuthContext

// output
let presentHashtagTimeline = PassthroughSubject<HashtagTimelineViewModel, Never>()


init(context: AppContext, authContext: AuthContext) {
self.context = context
self.authContext = authContext
Expand All @@ -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<Section, Item>()
snapshot.appendSections([.main])
let items = followedTags.compactMap { Item.hashtag($0) }
snapshot.appendItems(items, toSection: .main)
var snapshot = NSDiffableDataSourceSnapshot<Section, Item>()
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?()
}
Expand Down

0 comments on commit 580c931

Please sign in to comment.