From e11f360376e3671749c066e767d50956e0ef7ff9 Mon Sep 17 00:00:00 2001 From: Michael Staub Date: Thu, 23 Feb 2023 16:32:46 -0800 Subject: feat: implement DesktopSearch component --- src/view/shell/web/DesktopSearch.tsx | 165 +++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 src/view/shell/web/DesktopSearch.tsx (limited to 'src/view/shell/web/DesktopSearch.tsx') diff --git a/src/view/shell/web/DesktopSearch.tsx b/src/view/shell/web/DesktopSearch.tsx new file mode 100644 index 000000000..8998219da --- /dev/null +++ b/src/view/shell/web/DesktopSearch.tsx @@ -0,0 +1,165 @@ +import React from 'react' +import {TextInput, View, StyleSheet, TouchableOpacity, Text} from 'react-native' +import {UserAutocompleteViewModel} from 'state/models/user-autocomplete-view' +import {observer} from 'mobx-react-lite' +import {useStores} from 'state/index' +import {usePalette} from 'lib/hooks/usePalette' +import {MagnifyingGlassIcon} from 'lib/icons' +import {ProfileCard} from '../../com/profile/ProfileCard' + +export const DesktopSearch = observer(function DesktopSearch() { + const store = useStores() + const pal = usePalette('default') + const textInput = React.useRef(null) + const [isInputFocused, setIsInputFocused] = React.useState(false) + const [query, setQuery] = React.useState('') + const autocompleteView = React.useMemo( + () => new UserAutocompleteViewModel(store), + [store], + ) + + const onChangeQuery = (text: string) => { + setQuery(text) + if (text.length > 0 && isInputFocused) { + autocompleteView.setActive(true) + autocompleteView.setPrefix(text) + } else { + autocompleteView.setActive(false) + } + } + + const onPressCancelSearch = () => { + setQuery('') + autocompleteView.setActive(false) + } + + 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 + + + ) : null} + + + ) +}) + +const styles = StyleSheet.create({ + container: { + flex: 1, + }, + search: { + maxWidth: 300, + borderRadius: 20, + borderWidth: 1, + }, + searchIconWrapper: { + flexDirection: 'row', + width: 30, + justifyContent: 'center', + marginRight: 2, + }, + searchInputWrapper: { + flexDirection: 'row', + }, + searchContainer: { + flexWrap: 'wrap', + position: 'relative', + paddingHorizontal: 12, + paddingTop: 6, + paddingBottom: 6, + }, + headerMenuBtn: { + width: 40, + height: 30, + marginLeft: 6, + }, + searchResultsContainer: { + position: 'fixed', + flex: 1, + flexDirection: 'column', + borderRadius: 30, + paddingHorizontal: 12, + paddingVertical: 8, + marginTop: 50, + }, + headerSearchIcon: { + marginRight: 6, + alignSelf: 'center', + }, + headerSearchInput: { + flex: 1, + fontSize: 17, + width: '100%', + }, + headerCancelBtn: { + width: 60, + paddingLeft: 10, + }, + searchPrompt: { + textAlign: 'center', + paddingTop: 10, + }, +}) -- cgit 1.4.1