From 9bda3b72d06c31fd8c2bf3dbaa0c3a1bad62747f Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Fri, 24 Feb 2023 11:49:25 -0600 Subject: [PATCH] Simplify the desktop search screen --- src/view/screens/Search.web.tsx | 144 +++----------------------------- 1 file changed, 13 insertions(+), 131 deletions(-) diff --git a/src/view/screens/Search.web.tsx b/src/view/screens/Search.web.tsx index b85ed946..886d49af 100644 --- a/src/view/screens/Search.web.tsx +++ b/src/view/screens/Search.web.tsx @@ -1,46 +1,23 @@ import React from 'react' -import { - Keyboard, - StyleSheet, - TextInput, - TouchableOpacity, - View, -} from 'react-native' +import {StyleSheet, View} from 'react-native' import {ScrollView} from '../com/util/Views' import {observer} from 'mobx-react-lite' -import {UserAvatar} from '../com/util/UserAvatar' -import {Text} from '../com/util/text/Text' import {ScreenParams} from '../routes' import {useStores} from 'state/index' -import {UserAutocompleteViewModel} from 'state/models/user-autocomplete-view' import {s} from 'lib/styles' -import {MagnifyingGlassIcon} from 'lib/icons' -import {ViewHeader} from '../com/util/ViewHeader' import {WhoToFollow} from '../com/discover/WhoToFollow' import {SuggestedPosts} from '../com/discover/SuggestedPosts' -import {ProfileCard} from '../com/profile/ProfileCard' import {usePalette} from 'lib/hooks/usePalette' import {useOnMainScroll} from 'lib/hooks/useOnMainScroll' -import {useAnalytics} from 'lib/analytics' -const MENU_HITSLOP = {left: 10, top: 10, right: 30, bottom: 10} const FIVE_MIN = 5 * 60 * 1e3 -export const Search = observer(({navIdx, visible, params}: ScreenParams) => { +export const Search = observer(({navIdx, visible}: ScreenParams) => { const pal = usePalette('default') const store = useStores() - const {track} = useAnalytics() const scrollElRef = React.useRef(null) const onMainScroll = useOnMainScroll(store) - const textInput = React.useRef(null) const [lastRenderTime, setRenderTime] = React.useState(Date.now()) // used to trigger reloads - const [isInputFocused, setIsInputFocused] = React.useState(false) - const [query, setQuery] = React.useState('') - const autocompleteView = React.useMemo( - () => new UserAutocompleteViewModel(store), - [store], - ) - const {name} = params const onSoftReset = () => { scrollElRef.current?.scrollTo({x: 0, y: 0}) @@ -58,117 +35,22 @@ export const Search = observer(({navIdx, visible, params}: ScreenParams) => { setRenderTime(Date.now()) // trigger reload of suggestions } store.shell.setMinimalShellMode(false) - autocompleteView.setup() store.nav.setTitle(navIdx, 'Search') } return cleanup - }, [store, visible, name, navIdx, autocompleteView, lastRenderTime]) - - const onPressMenu = () => { - track('ViewHeader:MenuButtonClicked') - store.shell.setMainMenuOpen(true) - } - - const onChangeQuery = (text: string) => { - setQuery(text) - if (text.length > 0) { - autocompleteView.setActive(true) - autocompleteView.setPrefix(text) - } else { - autocompleteView.setActive(false) - } - } - const onPressCancelSearch = () => { - setQuery('') - autocompleteView.setActive(false) - } + }, [store, visible, navIdx, lastRenderTime]) return ( - - - - - - - - - - setIsInputFocused(true)} - onBlur={() => setIsInputFocused(false)} - onChangeText={onChangeQuery} - /> - - {query ? ( - - - Cancel - - - ) : undefined} - - {query && autocompleteView.searchRes.length ? ( - <> - {autocompleteView.searchRes.map(item => ( - - ))} - - ) : query && !autocompleteView.searchRes.length ? ( - - - No results found for {autocompleteView.prefix} - - - ) : isInputFocused ? ( - - - Search for users on the network - - - ) : ( - - - - - - )} - - - + + + + + ) })