11import { h } from 'preact'
2- import { useRef , useEffect , useState } from 'preact/hooks'
3- import { ListView , OfflinePanel , Consent , SearchLoading , Feed } from 'components'
2+ import { useRef , useEffect } from 'preact/hooks'
3+ import { ListView , OfflinePanel , Consent , SearchLoading } from 'components'
44import {
55 useNavigation , useSearch , useI18n , useSoftkey ,
6- useOnlineStatus , useTracking , usePopup , useHistoryState
6+ useOnlineStatus , useTracking , usePopup
77} from 'hooks'
88import {
99 articleHistory , goto , getAppLanguage ,
10- isRandomEnabled , confirmDialog , isConsentGranted ,
11- isTrendingArticlesGroup , skipIntroAnchor
10+ isRandomEnabled , confirmDialog , skipIntroAnchor ,
11+ isConsentGranted
1212} from 'utils'
1313import { getRandomArticleTitle } from 'api'
1414
@@ -17,9 +17,7 @@ export const Search = () => {
1717 const inputRef = useRef ( )
1818 const listRef = useRef ( )
1919 const i18n = useI18n ( )
20- const [ isFeedExpanded , setIsFeedExpanded ] = useState ( false )
21- const [ lastFeedIndex , setLastFeedIndex ] = useHistoryState ( 'lastFeedIndex' , null )
22- const [ current , setNavigation , getCurrent , getAllElements , navigateNext , navigatePrevious ] = useNavigation ( 'Search' , containerRef , listRef , 'y' )
20+ const [ current , setNavigation , getCurrent ] = useNavigation ( 'Search' , containerRef , listRef , 'y' )
2321 const lang = getAppLanguage ( )
2422 const [ query , setQuery , searchResults , loading ] = useSearch ( lang )
2523 const [ showConsentPopup , closeConsentPopup ] = usePopup ( Consent )
@@ -32,9 +30,6 @@ export const Search = () => {
3230 const onKeyCenter = ( ) => {
3331 if ( allowUsage ( ) ) {
3432 const { index, key } = getCurrent ( )
35- if ( index && isFeedExpanded ) {
36- setLastFeedIndex ( index )
37- }
3833 if ( index ) {
3934 goto . article ( lang , key )
4035 } else if ( isRandomEnabled ( ) && ! query ) {
@@ -43,41 +38,6 @@ export const Search = () => {
4338 }
4439 }
4540
46- const onKeyBackSpace = ( ) => {
47- if ( isFeedExpanded ) {
48- setIsFeedExpanded ( false )
49- listRef . current . scrollTop = 0
50- setNavigation ( 0 )
51- } else {
52- onExitConfirmDialog ( )
53- }
54- }
55-
56- const onKeyArrowDown = ( ) => {
57- const index = getCurrent ( ) . index
58- if ( ! isFeedExpanded && ! searchResults && index === 0 ) {
59- setIsFeedExpanded ( true )
60- navigateNext ( )
61- } else if ( isFeedExpanded && index + 1 > getAllElements ( ) . length - 1 ) {
62- setNavigation ( 1 )
63- } else {
64- navigateNext ( )
65- }
66- }
67-
68- const onKeyArrowUp = ( ) => {
69- const index = getCurrent ( ) . index
70- if ( isFeedExpanded && ! searchResults && index === 1 ) {
71- setIsFeedExpanded ( false )
72- setLastFeedIndex ( null )
73- navigatePrevious ( )
74- } else if ( ! isFeedExpanded && ! searchResults && index === 0 ) {
75- setNavigation ( 0 )
76- } else {
77- navigatePrevious ( )
78- }
79- }
80-
8141 const onInput = ( { target } ) => {
8242 if ( isOnline ) {
8343 setQuery ( target . value )
@@ -114,10 +74,8 @@ export const Search = () => {
11474 onKeyCenter,
11575 left : allowUsage ( ) ? i18n ( 'softkey-tips' ) : '' ,
11676 onKeyLeft : allowUsage ( ) ? goto . tips : null ,
117- onKeyBackspace : ! ( query && current . type === 'INPUT' ) && onKeyBackSpace ,
118- onKeyArrowDown : ! loading && onKeyArrowDown ,
119- onKeyArrowUp : ! loading && onKeyArrowUp
120- } , [ current . type , query , isOnline , searchResults , loading ] )
77+ onKeyBackspace : ! ( query && current . type === 'INPUT' ) && onExitConfirmDialog
78+ } , [ current . type , query , isOnline ] )
12179
12280 useTracking ( 'Search' , lang )
12381
@@ -131,12 +89,11 @@ export const Search = () => {
13189 }
13290 } , [ consentGranted , isOnline ] )
13391
134- const hideW = ( searchResults || ! isOnline || loading || ( isFeedExpanded && isTrendingArticlesGroup ( ) ) )
92+ const hideW = ( searchResults || ! isOnline || loading )
13593 const showSearchBar = allowUsage ( )
13694 const showResultsList = isOnline && searchResults && ! loading
13795 const showLoading = isOnline && loading
13896 const showOfflinePanel = ! isOnline
139- const showFeed = ( isOnline && ! searchResults && ! showLoading && ! showOfflinePanel && ( isTrendingArticlesGroup ( ) ) )
14097
14198 return (
14299 < div class = 'search' ref = { containerRef } >
@@ -145,7 +102,6 @@ export const Search = () => {
145102 { showResultsList && < ListView header = { i18n ( 'header-search' ) } items = { searchResults } containerRef = { listRef } empty = { i18n ( 'no-result-found' ) } /> }
146103 { showLoading && < SearchLoading /> }
147104 { showOfflinePanel && < OfflinePanel /> }
148- { showFeed && < Feed lang = { lang } isExpanded = { isFeedExpanded } setIsExpanded = { setIsFeedExpanded } lastIndex = { lastFeedIndex } setNavigation = { setNavigation } containerRef = { listRef } /> }
149105 </ div >
150106 )
151107}
0 commit comments