// // TrendingHashtagTableViewCell.swift // Tusker // // Created by Shadowfacts on 1/24/21. // Copyright © 2021 Shadowfacts. All rights reserved. // import UIKit import Pachyderm class TrendingHashtagTableViewCell: UITableViewCell { @IBOutlet weak var hashtagLabel: UILabel! @IBOutlet weak var peopleTodayLabel: UILabel! @IBOutlet weak var historyView: HashtagHistoryView! override func awakeFromNib() { super.awakeFromNib() } func updateUI(hashtag: Hashtag) { hashtagLabel.text = "#\(hashtag.name)" historyView.setHistory(hashtag.history) historyView.isHidden = hashtag.history == nil || hashtag.history!.count < 2 if let history = hashtag.history { let sorted = history.sorted(by: { $0.day < $1.day }) let lastTwo = sorted[(sorted.count - 2)...] let accounts = lastTwo.map(\.accounts).reduce(0, +) let uses = lastTwo.map(\.uses).reduce(0, +) let format = NSLocalizedString("trending hashtag info", comment: "trending hashtag posts and people") peopleTodayLabel.text = String.localizedStringWithFormat(format, accounts, uses) peopleTodayLabel.isHidden = false } else { peopleTodayLabel.isHidden = true } } }