This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var body: some View { | |
List { | |
SearchField(searchText: $viewModel.searchText) | |
ForEach(currentItems) { item in | |
NavigationLink(destination: ItemDetailView(item: item)) { | |
ItemRowView(displayMode: self.itemRowsDisplayMode, item: item) | |
} | |
} | |
} | |
.id(viewModel.sort) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ItemsViewModel: ObservableObject { | |
@Published var items: [Item] = [] | |
@Published var sortedItems: [Item] = [] | |
@Published var searchItems: [Item] = [] | |
@Published var searchText = "" | |
private var itemCancellable: AnyCancellable? | |
private var searchCancellable: AnyCancellable? | |
enum Sort: String, CaseIterable { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct CategoryRowView: View { | |
let category: Backend.Category | |
var body: some View { | |
NavigationLink(destination: ItemsListView(viewModel: ItemsViewModel(category: category))) { | |
HStack { | |
Image(category.iconName()) | |
Text(category.label()) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct HomeView: View { | |
@EnvironmentObject private var items: Items | |
private var categories: [(Backend.Category, [Item])] { | |
items.categories | |
.map { $0 } | |
.sorted(by: \.key.rawValue) | |
.reversed() | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct TabbarView: View { | |
private enum Tab: Int { | |
case dashboard, items, villagers, collection, turnips | |
} | |
@State private var selectedTab = Tab.dashboard | |
func tabbarItem(text: String, image: String) -> some View { | |
VStack { | |
Image(image) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SceneDelegate: UIResponder, UIWindowSceneDelegate { | |
var window: UIWindow? | |
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { | |
let contentView = TabbarView() | |
.environmentObject(Items()) | |
if let windowScene = scene as? UIWindowScene { | |
let window = UIWindow(windowScene: windowScene) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public struct ItemResponse: Codable { | |
let total: Int | |
let results: [Item] | |
} | |
public struct Item: Codable, Equatable, Identifiable { | |
public var id: String { name } | |
public let name: String | |
public let image: String? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum Category: String, CaseIterable { | |
case housewares, miscellaneous | |
case wallMounted = "wall-mounted" | |
case wallpapers, floors, rugs, photos, posters, fencing, tools | |
case tops, bottoms, dresses, headwear, accessories, socks, shoes, bags | |
case umbrellas, music, recipes, construction, nookmiles, other | |
case art, bugs, fish, fossils | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Items: ObservableObject { | |
@Published public var categories: [Category: [Item]] = [:] | |
init() { | |
for category in Category.allCases { | |
_ = NookPlazaAPIService | |
.fetch(endpoint: category) | |
.replaceError(with: ItemResponse(total: 0, results: [])) | |
.eraseToAnyPublisher() | |
.map{ $0.results } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import Combine | |
public struct NookPlazaAPIService { | |
private static let decoder = JSONDecoder() | |
private static let apiQueue = DispatchQueue(label: "nookazon_api", | |
qos: .userInitiated, | |
attributes: .concurrent) | |