[Framework] Feed Item coordinator (#17)
This PR contains the work done to implement the `FeedItemCoordinator` coordinator in the `Feed` framework. Reviewed-on: rock-n-code/app-reviews#17 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 #17.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
struct Review {
|
||||
public struct Review {
|
||||
|
||||
// MARK: Constants
|
||||
let author: String
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// FeedListConfiguration.swift
|
||||
// ReviewsFeed
|
||||
//
|
||||
// Created by Javier Cicchelli on 21/03/2024.
|
||||
// Copyright © 2024 Röck+Cöde. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public struct FeedListConfiguration {
|
||||
|
||||
// MARK: Constants
|
||||
let appID: String
|
||||
let countryCode: String
|
||||
let session: URLSessionConfiguration
|
||||
|
||||
// MARK: Initialisers
|
||||
public init(
|
||||
appID: String = "474495017",
|
||||
countryCode: String = "nl",
|
||||
session: URLSessionConfiguration = .ephemeral
|
||||
) {
|
||||
self.appID = appID
|
||||
self.countryCode = countryCode
|
||||
self.session = session
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,11 +13,8 @@ import ReviewsiTunesKit
|
||||
extension FeedListViewController {
|
||||
final class ViewModel: ObservableObject {
|
||||
|
||||
// MARK: Type aliases
|
||||
typealias Configuration = FeedListViewController.Configuration
|
||||
|
||||
// MARK: Constants
|
||||
private let configuration: Configuration
|
||||
private let configuration: FeedListConfiguration
|
||||
|
||||
private let filterWords: FilterWordsUseCase = .init()
|
||||
private let topWords: TopWordsUseCase = .init()
|
||||
@@ -30,18 +27,24 @@ extension FeedListViewController {
|
||||
|
||||
var items: [Review] = []
|
||||
var words: [TopWord] = []
|
||||
|
||||
|
||||
private var reviewsAll: [Review] = []
|
||||
private var reviewsFiltered: FilteredReviews = [:]
|
||||
private var reviewsTopWords: TopWordsReviews = [:]
|
||||
|
||||
private weak var coordination: FeedListCoordination?
|
||||
|
||||
lazy private var iTunesService: iTunesService = {
|
||||
.init(configuration: .init(session: configuration.session))
|
||||
}()
|
||||
|
||||
// MARK: Initialisers
|
||||
init(configuration: Configuration = .init()) {
|
||||
init(
|
||||
configuration: FeedListConfiguration = .init(),
|
||||
coordination: FeedListCoordination? = nil
|
||||
) {
|
||||
self.configuration = configuration
|
||||
self.coordination = coordination
|
||||
}
|
||||
|
||||
// MARK: Computed
|
||||
@@ -114,6 +117,12 @@ extension FeedListViewController {
|
||||
? items[index - 1]
|
||||
: items[index]
|
||||
}
|
||||
|
||||
func openItem(at index: Int) {
|
||||
guard let item = item(for: index) else { return }
|
||||
|
||||
coordination?.open(item)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user