[Framework] Show top words for filtered items in the Feed List (#12)
This PR contains the work done to show the top 3 words belonging to the filtered reviews in the `FeedListViewController` view controller. Reviewed-on: rock-n-code/app-reviews#12 Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
This commit was merged in pull request #12.
This commit is contained in:
@@ -40,11 +40,12 @@ public class FeedListViewController: UITableViewController {
|
||||
image: UIImage.Icon.star,
|
||||
children: {
|
||||
FilterOption.allCases.map { option -> UIAction in
|
||||
.init(title: option.text,
|
||||
image: .init(systemName: option.icon)
|
||||
) { [weak self] _ in
|
||||
self?.viewModel.filter(by: option)
|
||||
}
|
||||
.init(
|
||||
title: option.text,
|
||||
image: .init(systemName: option.icon)
|
||||
) { [weak self] _ in
|
||||
self?.viewModel.filter(by: option)
|
||||
}
|
||||
}
|
||||
}()
|
||||
)
|
||||
@@ -83,30 +84,18 @@ public class FeedListViewController: UITableViewController {
|
||||
_ tableView: UITableView,
|
||||
numberOfRowsInSection section: Int
|
||||
) -> Int {
|
||||
viewModel.items.count
|
||||
viewModel.itemsCount
|
||||
}
|
||||
|
||||
public override func tableView(
|
||||
_ tableView: UITableView,
|
||||
cellForRowAt indexPath: IndexPath
|
||||
) -> UITableViewCell {
|
||||
guard let cell = tableView.dequeueReusableCell(withIdentifier: .Cell.feedItem) else {
|
||||
return .init()
|
||||
if viewModel.isWordsShowing && indexPath.row == 0 {
|
||||
makeTopWordsCell(tableView)
|
||||
} else {
|
||||
makeFeedItemCell(tableView, at: indexPath.row)
|
||||
}
|
||||
|
||||
cell.contentConfiguration = {
|
||||
if #available(iOS 16.0, *) {
|
||||
UIHostingConfiguration {
|
||||
FeedItemCell(items[indexPath.row])
|
||||
}
|
||||
} else {
|
||||
HostingConfiguration {
|
||||
FeedItemCell(items[indexPath.row])
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
return cell
|
||||
}
|
||||
|
||||
// MARK: UITableViewDelegate
|
||||
@@ -158,8 +147,57 @@ private extension FeedListViewController {
|
||||
.store(in: &cancellables)
|
||||
}
|
||||
|
||||
func makeFeedItemCell(
|
||||
_ tableView: UITableView,
|
||||
at row: Int
|
||||
) -> UITableViewCell {
|
||||
guard
|
||||
let cell = FeedItemCell.dequeue(from: tableView),
|
||||
let item = viewModel.item(for: row)
|
||||
else {
|
||||
return .init()
|
||||
}
|
||||
|
||||
cell.separatorInset = .init(width: tableView.bounds.size.width)
|
||||
cell.contentConfiguration = {
|
||||
if #available(iOS 16.0, *) {
|
||||
UIHostingConfiguration {
|
||||
FeedItemView(item)
|
||||
}
|
||||
} else {
|
||||
HostingConfiguration {
|
||||
FeedItemView(item)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
return cell
|
||||
}
|
||||
|
||||
func makeTopWordsCell(_ tableView: UITableView) -> UITableViewCell {
|
||||
guard let cell = TopWordsCell.dequeue(from: tableView) else {
|
||||
return .init()
|
||||
}
|
||||
|
||||
cell.separatorInset = .init(width: tableView.bounds.size.width)
|
||||
cell.contentConfiguration = {
|
||||
if #available(iOS 16.0, *) {
|
||||
UIHostingConfiguration {
|
||||
TopWordsView(viewModel.words)
|
||||
}
|
||||
} else {
|
||||
HostingConfiguration {
|
||||
TopWordsView(viewModel.words)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
return cell
|
||||
}
|
||||
|
||||
func registerTableCells() {
|
||||
tableView.register(UITableViewCell.self, forCellReuseIdentifier: .Cell.feedItem)
|
||||
FeedItemCell.register(in: tableView)
|
||||
TopWordsCell.register(in: tableView)
|
||||
}
|
||||
|
||||
func setNavigationBar() {
|
||||
@@ -232,6 +270,21 @@ private extension String {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - UIEdgeInsets+Inits
|
||||
private extension UIEdgeInsets {
|
||||
|
||||
// MARK: Initialisers
|
||||
init(width: CGFloat) {
|
||||
self = .init(
|
||||
top: 0,
|
||||
left: width,
|
||||
bottom: 0,
|
||||
right: 0
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
#if DEBUG
|
||||
import ReviewsiTunesKit
|
||||
|
||||
Reference in New Issue
Block a user