@@ -24,9 +24,6 @@ public struct MainView<VM: MainViewModelProtocol, Router: MainRouterProtocol, Ad
2424 @StateObject private var _adsService : AdsService = AdsService ( )
2525
2626 private let _surchargeStatusTip = SurchargeStatusTip ( )
27- private let _useLocationTip = UseLocationTip ( )
28- @State private var _showLocationDeniedAlert = false
29- @FocusState private var _isSearchTextFeildFocused : Bool
3027
3128 public init ( viewModel: VM , router: Router ) {
3229 __viewModel = StateObject ( wrappedValue: viewModel)
@@ -48,41 +45,24 @@ public struct MainView<VM: MainViewModelProtocol, Router: MainRouterProtocol, Ad
4845 . padding ( [ . top] , 10 )
4946 . padding ( [ . leading, . trailing] , 20 )
5047
51- /*
52- // Favourite Places is currently not available.
5348 Section {
5449
55- FavouritePlacesView()
56- .padding([.leading, .trailing], 20)
57-
58- } header: {
59- Text("Favourite Places")
60- .font(.title3)
61- .blurBackground()
62- }
63- */
64-
65- if _viewModel. isLoading {
66-
67- Spacer ( )
68-
69- CircleProgress ( )
70-
71- Spacer ( )
72-
73- } else {
74-
75- if _viewModel. noResults {
50+ if _viewModel. isLoading {
7651
77- NoResultView ( searchedText: _viewModel. searchedText)
78- . padding ( . top, 40 )
79- . padding ( [ . leading, . trailing] , 20 )
52+ CircleProgress ( )
8053
8154 } else {
8255
83- if !_viewModel. mainModel. places. isEmpty {
56+ if _viewModel. noResults {
57+
58+ NoResultView ( searchedText: _viewModel. searchedText)
59+ . padding ( . top, 40 )
60+ . padding ( [ . leading, . trailing] , 20 )
8461
85- Section {
62+ } else {
63+
64+ if !_viewModel. mainModel. places. isEmpty {
65+
8666 PlacesView (
8767 mainModel: $_viewModel. mainModel,
8868 selectedPlace: { placeId in
@@ -95,132 +75,72 @@ public struct MainView<VM: MainViewModelProtocol, Router: MainRouterProtocol, Ad
9575 }
9676 )
9777
98- } header : {
78+ } else {
9979
100- VStack ( spacing: 0 ) {
101-
102- if _adsService. isShowingAds {
103- ListAdsView ( unitId: _adsService. listBannerUnitId)
104- }
80+ WelcomeView ( )
81+ . padding ( . top, 40 )
82+ . padding ( [ . leading, . trailing] , 20 )
83+
84+ FixedAdsView ( isAdShowing: $_adsService. isShowingAds, unitId: _adsService. fixedBannerUnitId)
85+ . blurRoundedBackground ( cornerRadius: 20 )
86+ . padding ( [ . top, . bottom] , 10 )
87+ . padding ( [ . leading, . trailing] , 20 )
10588
106- Text ( " 🔎 \( R . string. localizable. searchFor ( _viewModel. searchedText) ) " )
107- . frame ( maxWidth: . infinity, alignment: . leading)
108- . padding ( [ . leading, . trailing] , 20 )
109- . padding ( . top, 10 )
110- . padding ( . bottom, 10 )
111-
112- }
113- . blurBackground ( )
114-
11589 }
90+ }
91+
92+ }
93+
94+ } header: {
95+
96+ if !_viewModel. showWelcome {
97+
98+ VStack ( spacing: 0 ) {
11699
117- } else {
100+ if _adsService. isShowingAds {
101+ ListAdsView ( unitId: _adsService. listBannerUnitId)
102+ }
118103
119- WelcomeView ( )
120- . padding ( . top , 40 )
104+ Text ( " 🔎 \( R . string . localizable . searchFor ( _viewModel . searchedText ) ) " )
105+ . frame ( maxWidth : . infinity , alignment : . leading )
121106 . padding ( [ . leading, . trailing] , 20 )
107+ . padding ( . top, 10 )
108+ . padding ( . bottom, 10 )
122109
123- FixedAdsView ( isAdShowing: $_adsService. isShowingAds, unitId: _adsService. fixedBannerUnitId)
124- . blurRoundedBackground ( cornerRadius: 20 )
125- . padding ( [ . top, . bottom] , 10 )
126- . padding ( [ . leading, . trailing] , 20 )
127-
128110 }
111+ . blurBackground ( )
112+
113+ } else {
114+
115+ Rectangle ( )
116+ . foregroundStyle ( R . color. clear. color)
117+ . frame ( height: 20 )
118+
129119 }
130- }
131- }
132- }
133- . scrollDismissesKeyboard ( . interactively)
134-
135- HStack ( spacing: 10 ) {
136-
137- Button {
138-
139- if _viewModel. isDeniedToUseUserLocation {
140- _showLocationDeniedAlert. toggle ( )
141- } else {
142-
143- withAnimation {
144- _viewModel. toggleUserLocation ( )
145- }
146-
147- _useLocationTip. invalidate ( reason: . actionPerformed)
148-
149- }
150-
151- } label: {
152-
153- if _viewModel. isDeniedToUseUserLocation {
154- Image ( systemName: " location.slash " )
155- . foregroundStyle ( R . color. blue600. color)
156- } else {
157- Image ( systemName: _viewModel. isUserLocationOn ? " location.fill " : " location " )
158- . foregroundStyle ( R . color. blue600. color)
159- }
160-
161- }
162- . buttonStyle ( . plain)
163- . contentTransition ( . symbolEffect( . replace) )
164- . alert (
165- R . string. localizable. alertUseLocationDeniedTitle ( ) ,
166- isPresented: $_showLocationDeniedAlert
167- ) {
168-
169- Button {
170-
171- UIApplication . shared. open ( URL ( string: UIApplication . openSettingsURLString) !, options: [ : ] , completionHandler: nil )
172120
173- } label: {
174- Text ( R . string. localizable. goToSettings ( ) )
175121 }
176122
177- Button ( role: . cancel) {
178- _showLocationDeniedAlert. toggle ( )
179- } label: {
180- Text ( R . string. localizable. close ( ) )
181- }
182-
183- } message: {
184- Text ( R . string. localizable. alertUseLocationDeniedMessage ( ) )
185- }
186- . popoverTip ( _useLocationTip, arrowEdge: . leading) { action in
187- withAnimation {
188- _viewModel. toggleUserLocation ( )
189- }
190- _useLocationTip. invalidate ( reason: . actionPerformed)
191- }
192-
193- TextField ( R . string. localizable. searchBoxPlaceholder ( ) , text: $_viewModel. searchText)
194- . textFieldStyle ( . roundedBorder)
195- . font ( . body)
196- . disabled ( _viewModel. isLoading)
197- . onSubmit {
198- Task {
199- await _viewModel. search ( )
200- }
201- }
202- . submitLabel ( . search)
203- . focused ( $_isSearchTextFeildFocused)
204- . onChange ( of: _isSearchTextFeildFocused, { _, newValue in
205- if newValue {
206- UseLocationTip . tryToSearch. toggle ( )
207- }
208- } )
209-
210- Button {
211- Task {
212- await _viewModel. search ( )
213- }
214- } label: {
215- Text ( R . string. localizable. searchButtonTitle ( ) )
216- . font ( . body)
217- . disabled ( !_viewModel. canSearch)
123+ /*
124+ // Favourite Places is currently not available.
125+ Section {
126+
127+ FavouritePlacesView()
128+ .padding([.leading, .trailing], 20)
129+
130+ } header: {
131+ Text("Favourite Places")
132+ .font(.title3)
133+ .blurBackground()
134+ }
135+ */
218136 }
219-
220137 }
221- . padding ( [ . top] , 10 )
222- . padding ( [ . leading, . trailing] , 30 )
223- . padding ( [ . bottom] , 10 )
138+ . scrollDismissesKeyboard ( . interactively)
139+
140+ SearchView ( viewModel: __viewModel)
141+ . padding ( [ . top] , 10 )
142+ . padding ( [ . leading, . trailing] , 30 )
143+ . padding ( [ . bottom] , 10 )
224144
225145 }
226146 . navigationTitle ( " Surcharges💸 " )
0 commit comments