mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 20:24:06 +00:00
Popular videos tab
This commit is contained in:
11
Model/TrendingCategory.swift
Normal file
11
Model/TrendingCategory.swift
Normal file
@@ -0,0 +1,11 @@
|
||||
enum TrendingCategory: String, CaseIterable, Identifiable {
|
||||
case `default`, music, gaming, movies
|
||||
|
||||
var id: TrendingCategory.RawValue {
|
||||
rawValue
|
||||
}
|
||||
|
||||
var name: String {
|
||||
rawValue.capitalized
|
||||
}
|
||||
}
|
18
Model/TrendingCountriesProvider.swift
Normal file
18
Model/TrendingCountriesProvider.swift
Normal file
@@ -0,0 +1,18 @@
|
||||
import Alamofire
|
||||
import Foundation
|
||||
import SwiftyJSON
|
||||
|
||||
final class TrendingCountriesProvider: DataProvider {
|
||||
@Published var countries = [Country]()
|
||||
|
||||
private var query: String = ""
|
||||
|
||||
func load(_ query: String) {
|
||||
guard query != self.query else {
|
||||
return
|
||||
}
|
||||
|
||||
self.query = query
|
||||
countries = Country.searchByName(query)
|
||||
}
|
||||
}
|
6
Model/TrendingState.swift
Normal file
6
Model/TrendingState.swift
Normal file
@@ -0,0 +1,6 @@
|
||||
import Foundation
|
||||
|
||||
final class TrendingState: ObservableObject {
|
||||
@Published var category: TrendingCategory = .default
|
||||
@Published var country: Country = .pl
|
||||
}
|
31
Model/TrendingVideosProvider.swift
Normal file
31
Model/TrendingVideosProvider.swift
Normal file
@@ -0,0 +1,31 @@
|
||||
import Alamofire
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
import SwiftyJSON
|
||||
|
||||
final class TrendingVideosProvider: DataProvider {
|
||||
@Published var videos = [Video]()
|
||||
|
||||
var currentCategory: TrendingCategory?
|
||||
var currentCountry: Country?
|
||||
|
||||
func load(category: TrendingCategory, country: Country) {
|
||||
if category == currentCategory, country == currentCountry {
|
||||
return
|
||||
}
|
||||
|
||||
DataProvider.request("trending?type=\(category.name)®ion=\(country.rawValue)").responseJSON { response in
|
||||
switch response.result {
|
||||
case let .success(value):
|
||||
self.videos = JSON(value).arrayValue.map { Video($0) }
|
||||
case let .failure(error):
|
||||
print(error)
|
||||
}
|
||||
}
|
||||
|
||||
currentCategory = category
|
||||
currentCountry = country
|
||||
|
||||
videos = []
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user