-
Notifications
You must be signed in to change notification settings - Fork 0
/
MarketView.swift
112 lines (102 loc) · 2.63 KB
/
MarketView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import SwiftUI
import PromiseKit
import LoadingState
struct MarketView: View {
static let deckCellWidth: CGFloat = 165
static let numberOfColumns =
Int(SCREEN_SIZE.width) / Int(deckCellWidth)
static let horizontalCellSpacing: CGFloat = 13
static let verticalCellSpacing: CGFloat = 20
static let horizontalPadding: CGFloat = 23
enum FilterPopUpSideBarSelection {
case topics
case rating
case downloads
}
@EnvironmentObject var currentStore: CurrentStore
@State var selectedDeck: Deck! = nil
@State var isDeckSelected = false
@Binding var isSortPopUpShowing: Bool
@Binding var isFilterPopUpShowing: Bool
let searchText: String
let setSearchText: (String) -> Void
let searchResults: [Deck]
let searchResultsLoadingState: LoadingState
let loadSearchResults: (Bool) -> Void
var content: some View {
ForEach(searchResults) { deck in
DeckCellWithGetButton(
deck: deck,
user: self.currentStore.user,
width: SCREEN_SIZE.width - Self.horizontalPadding * 2,
imageHeight: IS_IPAD ? 300 : 200,
titleFontSize: 17
)
.onTapGesture {
self.selectedDeck = deck
self.isDeckSelected = true
}
}
}
var scrollView: some View {
ScrollView(showsIndicators: false) {
TryLazyVStack(spacing: Self.verticalCellSpacing) { self.content }
.padding(.bottom, Self.horizontalPadding)
}
}
var body: some View {
GeometryReader { geometry in
ZStack(alignment: .top) {
HomeViewTopGradient(
addedHeight: geometry.safeAreaInsets.top
)
.edgesIgnoringSafeArea(.all)
VStack(spacing: 20) {
Group {
MarketViewTopControls(
searchText: self.searchText,
setSearchText: self.setSearchText
)
MarketViewTopButtons(
isSortPopUpShowing: self.$isSortPopUpShowing,
isFilterPopUpShowing: self.$isFilterPopUpShowing
)
}
.padding(.horizontal, Self.horizontalPadding)
if self.searchResultsLoadingState.isLoading && self.searchText.isEmpty {
ActivityIndicator(color: .white)
Spacer()
} else {
self.scrollView
}
}
if self.isDeckSelected {
NavigateTo(
MarketDeckView()
.environmentObject(self.selectedDeck!),
when: self.$isDeckSelected
)
}
}
}
.onAppear {
self.loadSearchResults(false)
}
}
}
#if DEBUG
struct MarketView_Previews: PreviewProvider {
static var previews: some View {
MarketView(
isSortPopUpShowing: .constant(false),
isFilterPopUpShowing: .constant(true),
searchText: "",
setSearchText: { _ in },
searchResults: [],
searchResultsLoadingState: .none,
loadSearchResults: { _ in }
)
.environmentObject(PREVIEW_CURRENT_STORE)
}
}
#endif