@@ -7,9 +7,6 @@ import { SearchBar } from './SearchBar.js';
7
7
import { ResultsContainer } from './ResultsContainer.js' ;
8
8
9
9
export function HomePage ( sources ) {
10
- const discoveryModePredicate =
11
- phrase => phrase . length === 0 ;
12
-
13
10
const {
14
11
DOM : searchBarVdom$ ,
15
12
HTTP : searchBarHttp$ ,
@@ -19,6 +16,10 @@ export function HomePage(sources) {
19
16
isError$ : searchIsError$
20
17
} = SearchBar ( sources ) ;
21
18
19
+ const isDiscoveryMode$ =
20
+ searchPhrase$
21
+ . map ( phrase => phrase . length === 0 ) ;
22
+
22
23
const discoveryRequest$ =
23
24
xs . of ( {
24
25
url : sources . SvcUrl ( `/movie/popular?language=en-US&page=1` ) ,
@@ -37,9 +38,9 @@ export function HomePage(sources) {
37
38
. startWith ( '' )
38
39
39
40
const content$ =
40
- xs . combine ( searchPhrase $, searchResponse$ , discoveryResponse$ )
41
- . map ( ( [ searchPhrase , searchResponse , discoveryResponse ] ) =>
42
- discoveryModePredicate ( searchPhrase )
41
+ xs . combine ( isDiscoveryMode $, searchResponse$ , discoveryResponse$ )
42
+ . map ( ( [ isDiscoveryMode , searchResponse , discoveryResponse ] ) =>
43
+ isDiscoveryMode
43
44
? discoveryResponse
44
45
: searchResponse
45
46
)
@@ -68,16 +69,16 @@ export function HomePage(sources) {
68
69
} ) ;
69
70
70
71
const vdom$ =
71
- xs . combine ( searchBarVdom$ , searchPhrase$ , resultsVdom$ )
72
- . map ( ( [ searchBarVdom , searchPhrase , resultsVdom ] ) =>
72
+ xs . combine ( searchBarVdom$ , isDiscoveryMode$ , searchPhrase$ , resultsVdom$ )
73
+ . map ( ( [ searchBarVdom , isDiscoveryMode , searchPhrase , resultsVdom ] ) =>
73
74
< div className = "HomePage" >
74
75
< h1 > TMDb UI – Home</ h1 >
75
76
< legend className = "uk-legend" > Search for a Title:</ legend >
76
77
77
78
{ searchBarVdom }
78
79
79
80
< h3 className = "uk-heading-bullet uk-margin-remove-top" >
80
- { discoveryModePredicate ( searchPhrase )
81
+ { isDiscoveryMode
81
82
? 'Popular Now'
82
83
: `Search Results for "${ searchPhrase } ":` }
83
84
</ h3 >
0 commit comments