getting there
This commit is contained in:
@@ -252,11 +252,11 @@ type SearchResultSlice =
|
|||||||
}
|
}
|
||||||
|
|
||||||
function SearchScreenPostResults({
|
function SearchScreenPostResults({
|
||||||
query,
|
queryTerm,
|
||||||
sort,
|
sort,
|
||||||
active,
|
active,
|
||||||
}: {
|
}: {
|
||||||
query: string
|
queryTerm: string
|
||||||
sort?: 'top' | 'latest'
|
sort?: 'top' | 'latest'
|
||||||
active: boolean
|
active: boolean
|
||||||
}) {
|
}) {
|
||||||
@@ -265,8 +265,8 @@ function SearchScreenPostResults({
|
|||||||
const [isPTR, setIsPTR] = React.useState(false)
|
const [isPTR, setIsPTR] = React.useState(false)
|
||||||
|
|
||||||
const augmentedQuery = React.useMemo(() => {
|
const augmentedQuery = React.useMemo(() => {
|
||||||
return augmentSearchQuery(query || '', {did: currentAccount?.did})
|
return augmentSearchQuery(queryTerm || '', {did: currentAccount?.did})
|
||||||
}, [query, currentAccount])
|
}, [queryTerm, currentAccount])
|
||||||
|
|
||||||
const {
|
const {
|
||||||
isFetched,
|
isFetched,
|
||||||
@@ -348,7 +348,7 @@ function SearchScreenPostResults({
|
|||||||
contentContainerStyle={{paddingBottom: 100}}
|
contentContainerStyle={{paddingBottom: 100}}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<EmptyState message={_(msg`No results found for ${query}`)} />
|
<EmptyState message={_(msg`No results found for ${queryTerm}`)} />
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
@@ -359,16 +359,16 @@ function SearchScreenPostResults({
|
|||||||
}
|
}
|
||||||
|
|
||||||
function SearchScreenUserResults({
|
function SearchScreenUserResults({
|
||||||
query,
|
queryTerm,
|
||||||
active,
|
active,
|
||||||
}: {
|
}: {
|
||||||
query: string
|
queryTerm: string
|
||||||
active: boolean
|
active: boolean
|
||||||
}) {
|
}) {
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
|
|
||||||
const {data: results, isFetched} = useActorSearch({
|
const {data: results, isFetched} = useActorSearch({
|
||||||
query,
|
query: queryTerm,
|
||||||
enabled: active,
|
enabled: active,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -386,7 +386,7 @@ function SearchScreenUserResults({
|
|||||||
contentContainerStyle={{paddingBottom: 100}}
|
contentContainerStyle={{paddingBottom: 100}}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<EmptyState message={_(msg`No results found for ${query}`)} />
|
<EmptyState message={_(msg`No results found for ${queryTerm}`)} />
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
@@ -394,7 +394,7 @@ function SearchScreenUserResults({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function SearchScreenInner({query}: {query?: string}) {
|
export function SearchScreenInner({queryTerm}: {queryTerm?: string}) {
|
||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
const setMinimalShellMode = useSetMinimalShellMode()
|
const setMinimalShellMode = useSetMinimalShellMode()
|
||||||
const setDrawerSwipeDisabled = useSetDrawerSwipeDisabled()
|
const setDrawerSwipeDisabled = useSetDrawerSwipeDisabled()
|
||||||
@@ -413,13 +413,13 @@ export function SearchScreenInner({query}: {query?: string}) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
const sections = React.useMemo(() => {
|
const sections = React.useMemo(() => {
|
||||||
if (!query) return []
|
if (!queryTerm) return []
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
title: _(msg`Top`),
|
title: _(msg`Top`),
|
||||||
component: (
|
component: (
|
||||||
<SearchScreenPostResults
|
<SearchScreenPostResults
|
||||||
query={query}
|
queryTerm={queryTerm}
|
||||||
sort="top"
|
sort="top"
|
||||||
active={activeTab === 0}
|
active={activeTab === 0}
|
||||||
/>
|
/>
|
||||||
@@ -429,7 +429,7 @@ export function SearchScreenInner({query}: {query?: string}) {
|
|||||||
title: _(msg`Latest`),
|
title: _(msg`Latest`),
|
||||||
component: (
|
component: (
|
||||||
<SearchScreenPostResults
|
<SearchScreenPostResults
|
||||||
query={query}
|
queryTerm={queryTerm}
|
||||||
sort="latest"
|
sort="latest"
|
||||||
active={activeTab === 1}
|
active={activeTab === 1}
|
||||||
/>
|
/>
|
||||||
@@ -438,13 +438,16 @@ export function SearchScreenInner({query}: {query?: string}) {
|
|||||||
{
|
{
|
||||||
title: _(msg`People`),
|
title: _(msg`People`),
|
||||||
component: (
|
component: (
|
||||||
<SearchScreenUserResults query={query} active={activeTab === 2} />
|
<SearchScreenUserResults
|
||||||
|
queryTerm={queryTerm}
|
||||||
|
active={activeTab === 2}
|
||||||
|
/>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}, [_, query, activeTab])
|
}, [_, queryTerm, activeTab])
|
||||||
|
|
||||||
return query ? (
|
return queryTerm ? (
|
||||||
<Pager
|
<Pager
|
||||||
onPageSelected={onPageSelected}
|
onPageSelected={onPageSelected}
|
||||||
renderTabBar={props => (
|
renderTabBar={props => (
|
||||||
@@ -543,7 +546,7 @@ export function SearchScreen(
|
|||||||
|
|
||||||
// Query terms
|
// Query terms
|
||||||
const q = props.route?.params?.q ?? ''
|
const q = props.route?.params?.q ?? ''
|
||||||
const [query, setQuery] = React.useState<string>(q)
|
const [queryTerm, setQueryTerm] = React.useState<string>(q)
|
||||||
const [searchText, setSearchText] = React.useState<string>(q)
|
const [searchText, setSearchText] = React.useState<string>(q)
|
||||||
const throttledInput = useThrottledValue(searchText, 300)
|
const throttledInput = useThrottledValue(searchText, 300)
|
||||||
|
|
||||||
@@ -555,6 +558,11 @@ export function SearchScreen(
|
|||||||
React.useState(false)
|
React.useState(false)
|
||||||
const [searchHistory, setSearchHistory] = React.useState<string[]>([])
|
const [searchHistory, setSearchHistory] = React.useState<string[]>([])
|
||||||
|
|
||||||
|
if (q !== queryTerm) {
|
||||||
|
setQueryTerm(q)
|
||||||
|
setSearchText(q)
|
||||||
|
}
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
const loadSearchHistory = async () => {
|
const loadSearchHistory = async () => {
|
||||||
try {
|
try {
|
||||||
@@ -575,18 +583,19 @@ export function SearchScreen(
|
|||||||
setDrawerOpen(true)
|
setDrawerOpen(true)
|
||||||
}, [track, setDrawerOpen])
|
}, [track, setDrawerOpen])
|
||||||
|
|
||||||
|
const onPressClearQuery = React.useCallback(() => {
|
||||||
|
scrollToTopWeb()
|
||||||
|
setSearchText('')
|
||||||
|
setShowAutocompleteResults(false)
|
||||||
|
textInput.current?.focus()
|
||||||
|
}, [])
|
||||||
|
|
||||||
const onPressCancelSearch = React.useCallback(() => {
|
const onPressCancelSearch = React.useCallback(() => {
|
||||||
scrollToTopWeb()
|
scrollToTopWeb()
|
||||||
textInput.current?.blur()
|
textInput.current?.blur()
|
||||||
setQuery('')
|
|
||||||
setShowAutocompleteResults(false)
|
setShowAutocompleteResults(false)
|
||||||
}, [textInput])
|
navigation.setParams({q: ''})
|
||||||
|
}, [navigation])
|
||||||
const onPressClearQuery = React.useCallback(() => {
|
|
||||||
scrollToTopWeb()
|
|
||||||
setQuery('')
|
|
||||||
setShowAutocompleteResults(false)
|
|
||||||
}, [setQuery])
|
|
||||||
|
|
||||||
const onChangeText = React.useCallback(async (text: string) => {
|
const onChangeText = React.useCallback(async (text: string) => {
|
||||||
scrollToTopWeb()
|
scrollToTopWeb()
|
||||||
@@ -623,9 +632,15 @@ export function SearchScreen(
|
|||||||
const onSubmit = React.useCallback(() => {
|
const onSubmit = React.useCallback(() => {
|
||||||
scrollToTopWeb()
|
scrollToTopWeb()
|
||||||
setShowAutocompleteResults(false)
|
setShowAutocompleteResults(false)
|
||||||
updateSearchHistory(query)
|
updateSearchHistory(searchText)
|
||||||
navigation.push('Search', {q: query})
|
setQueryTerm(searchText)
|
||||||
}, [navigation, query, updateSearchHistory])
|
|
||||||
|
if (isWeb) {
|
||||||
|
navigation.push('Search', {q: searchText})
|
||||||
|
} else {
|
||||||
|
navigation.setParams({q: searchText})
|
||||||
|
}
|
||||||
|
}, [navigation, searchText, updateSearchHistory])
|
||||||
|
|
||||||
const onSoftReset = React.useCallback(() => {
|
const onSoftReset = React.useCallback(() => {
|
||||||
scrollToTopWeb()
|
scrollToTopWeb()
|
||||||
@@ -633,9 +648,9 @@ export function SearchScreen(
|
|||||||
}, [onPressCancelSearch])
|
}, [onPressCancelSearch])
|
||||||
|
|
||||||
const queryMaybeHandle = React.useMemo(() => {
|
const queryMaybeHandle = React.useMemo(() => {
|
||||||
const match = MATCH_HANDLE.exec(query)
|
const match = MATCH_HANDLE.exec(queryTerm)
|
||||||
return match && match[1]
|
return match && match[1]
|
||||||
}, [query])
|
}, [queryTerm])
|
||||||
|
|
||||||
// TODO ???
|
// TODO ???
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
@@ -646,7 +661,7 @@ export function SearchScreen(
|
|||||||
)
|
)
|
||||||
|
|
||||||
const handleHistoryItemClick = (item: React.SetStateAction<string>) => {
|
const handleHistoryItemClick = (item: React.SetStateAction<string>) => {
|
||||||
setQuery(item)
|
setQueryTerm(item)
|
||||||
onSubmit()
|
onSubmit()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -708,10 +723,9 @@ export function SearchScreen(
|
|||||||
keyboardAppearance={theme.colorScheme}
|
keyboardAppearance={theme.colorScheme}
|
||||||
onFocus={() => setInputIsFocused(true)}
|
onFocus={() => setInputIsFocused(true)}
|
||||||
onBlur={() => {
|
onBlur={() => {
|
||||||
// HACK
|
setTimeout(() => {
|
||||||
// give 100ms to not stop click handlers in the search history
|
setInputIsFocused(Boolean(textInput.current?.isFocused()))
|
||||||
// -prf
|
}, 100)
|
||||||
setTimeout(() => setInputIsFocused(false), 100)
|
|
||||||
}}
|
}}
|
||||||
onChangeText={onChangeText}
|
onChangeText={onChangeText}
|
||||||
onSubmitEditing={onSubmit}
|
onSubmitEditing={onSubmit}
|
||||||
@@ -723,7 +737,7 @@ export function SearchScreen(
|
|||||||
autoComplete="off"
|
autoComplete="off"
|
||||||
autoCapitalize="none"
|
autoCapitalize="none"
|
||||||
/>
|
/>
|
||||||
{query ? (
|
{inputIsFocused ? (
|
||||||
<Pressable
|
<Pressable
|
||||||
testID="searchTextInputClearBtn"
|
testID="searchTextInputClearBtn"
|
||||||
onPress={onPressClearQuery}
|
onPress={onPressClearQuery}
|
||||||
@@ -740,7 +754,7 @@ export function SearchScreen(
|
|||||||
) : undefined}
|
) : undefined}
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
{query || inputIsFocused ? (
|
{(queryTerm || inputIsFocused) && (
|
||||||
<View style={styles.headerCancelBtn}>
|
<View style={styles.headerCancelBtn}>
|
||||||
<Pressable
|
<Pressable
|
||||||
onPress={onPressCancelSearch}
|
onPress={onPressCancelSearch}
|
||||||
@@ -751,7 +765,7 @@ export function SearchScreen(
|
|||||||
</Text>
|
</Text>
|
||||||
</Pressable>
|
</Pressable>
|
||||||
</View>
|
</View>
|
||||||
) : undefined}
|
)}
|
||||||
</CenteredView>
|
</CenteredView>
|
||||||
|
|
||||||
{showAutocompleteResults ? (
|
{showAutocompleteResults ? (
|
||||||
@@ -772,7 +786,7 @@ export function SearchScreen(
|
|||||||
to={
|
to={
|
||||||
isNative
|
isNative
|
||||||
? undefined
|
? undefined
|
||||||
: `/search?q=${encodeURIComponent(query)}`
|
: `/search?q=${encodeURIComponent(queryTerm)}`
|
||||||
}
|
}
|
||||||
style={{borderBottomWidth: 1}}
|
style={{borderBottomWidth: 1}}
|
||||||
/>
|
/>
|
||||||
@@ -796,7 +810,7 @@ export function SearchScreen(
|
|||||||
</ScrollView>
|
</ScrollView>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
) : !query && inputIsFocused ? (
|
) : !queryTerm && inputIsFocused ? (
|
||||||
<CenteredView
|
<CenteredView
|
||||||
sideBorders={isTabletOrDesktop}
|
sideBorders={isTabletOrDesktop}
|
||||||
// @ts-ignore web only -prf
|
// @ts-ignore web only -prf
|
||||||
@@ -841,7 +855,7 @@ export function SearchScreen(
|
|||||||
</View>
|
</View>
|
||||||
</CenteredView>
|
</CenteredView>
|
||||||
) : (
|
) : (
|
||||||
<SearchScreenInner query={query} />
|
<SearchScreenInner queryTerm={queryTerm} />
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user