Fix stale data, hide/show
This commit is contained in:
@@ -67,6 +67,7 @@ import * as TextField from '#/components/forms/TextField'
|
|||||||
import {ChevronBottom_Stroke2_Corner0_Rounded as ChevronDown} from '#/components/icons/Chevron'
|
import {ChevronBottom_Stroke2_Corner0_Rounded as ChevronDown} from '#/components/icons/Chevron'
|
||||||
import {MagnifyingGlass2_Stroke2_Corner0_Rounded as MagnifyingGlass} from '#/components/icons/MagnifyingGlass2'
|
import {MagnifyingGlass2_Stroke2_Corner0_Rounded as MagnifyingGlass} from '#/components/icons/MagnifyingGlass2'
|
||||||
import {Menu_Stroke2_Corner0_Rounded as Menu} from '#/components/icons/Menu'
|
import {Menu_Stroke2_Corner0_Rounded as Menu} from '#/components/icons/Menu'
|
||||||
|
import {SettingsGear2_Stroke2_Corner0_Rounded as Gear} from '#/components/icons/SettingsGear2'
|
||||||
import {TimesLarge_Stroke2_Corner0_Rounded as X} from '#/components/icons/Times'
|
import {TimesLarge_Stroke2_Corner0_Rounded as X} from '#/components/icons/Times'
|
||||||
|
|
||||||
const HEADER_HEIGHT = 56
|
const HEADER_HEIGHT = 56
|
||||||
@@ -415,15 +416,20 @@ function SearchLanguageDropdown({
|
|||||||
|
|
||||||
function useQueryManager({initialQuery}: {initialQuery: string}) {
|
function useQueryManager({initialQuery}: {initialQuery: string}) {
|
||||||
const {contentLanguages} = useLanguagePrefs()
|
const {contentLanguages} = useLanguagePrefs()
|
||||||
const {query, params: initialParams} = React.useMemo(
|
const {query, params: initialParams} = React.useMemo(() => {
|
||||||
() => parseSearchQuery(initialQuery || ''),
|
return parseSearchQuery(initialQuery || '')
|
||||||
[initialQuery],
|
}, [initialQuery])
|
||||||
)
|
const prevInitialQuery = React.useRef(initialQuery)
|
||||||
|
|
||||||
const [lang, setLang] = React.useState(
|
const [lang, setLang] = React.useState(
|
||||||
initialParams.lang || contentLanguages[0],
|
initialParams.lang || contentLanguages[0],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (initialQuery !== prevInitialQuery.current) {
|
||||||
|
prevInitialQuery.current = initialQuery
|
||||||
|
setLang(initialParams.lang || contentLanguages[0])
|
||||||
|
}
|
||||||
|
|
||||||
const params = React.useMemo(
|
const params = React.useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
// default stuff
|
// default stuff
|
||||||
@@ -609,6 +615,13 @@ export function SearchScreen(
|
|||||||
AppBskyActorDefs.ProfileViewBasic[]
|
AppBskyActorDefs.ProfileViewBasic[]
|
||||||
>([])
|
>([])
|
||||||
|
|
||||||
|
const {params, query, queryWithParams} = useQueryManager({
|
||||||
|
initialQuery: queryParam,
|
||||||
|
})
|
||||||
|
const showFiltersButton = Boolean(query && !showAutocomplete)
|
||||||
|
const [showFilters, setShowFilters] = React.useState(false)
|
||||||
|
const headerHeight = HEADER_HEIGHT + (showFilters ? 40 : 0)
|
||||||
|
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useNonReactiveCallback(() => {
|
useNonReactiveCallback(() => {
|
||||||
if (isWeb) {
|
if (isWeb) {
|
||||||
@@ -765,6 +778,7 @@ export function SearchScreen(
|
|||||||
setSearchText('')
|
setSearchText('')
|
||||||
navigation.setParams({q: ''})
|
navigation.setParams({q: ''})
|
||||||
}
|
}
|
||||||
|
setShowFilters(false)
|
||||||
}, [navigation])
|
}, [navigation])
|
||||||
|
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
@@ -804,11 +818,18 @@ export function SearchScreen(
|
|||||||
[selectedProfiles],
|
[selectedProfiles],
|
||||||
)
|
)
|
||||||
|
|
||||||
const {params, query, queryWithParams} = useQueryManager({
|
const onSearchInputFocus = React.useCallback(() => {
|
||||||
initialQuery: queryParam,
|
if (isWeb) {
|
||||||
})
|
// Prevent a jump on iPad by ensuring that
|
||||||
const showFilters = Boolean(query && !showAutocomplete)
|
// the initial focused render has no result list.
|
||||||
const headerHeight = HEADER_HEIGHT + (showFilters ? 40 : 0)
|
requestAnimationFrame(() => {
|
||||||
|
setShowAutocomplete(true)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
setShowAutocomplete(true)
|
||||||
|
}
|
||||||
|
setShowFilters(false)
|
||||||
|
}, [setShowAutocomplete])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={isWeb ? null : {flex: 1}}>
|
<View style={isWeb ? null : {flex: 1}}>
|
||||||
@@ -845,11 +866,30 @@ export function SearchScreen(
|
|||||||
textInput={textInput}
|
textInput={textInput}
|
||||||
searchText={searchText}
|
searchText={searchText}
|
||||||
showAutocomplete={showAutocomplete}
|
showAutocomplete={showAutocomplete}
|
||||||
setShowAutocomplete={setShowAutocomplete}
|
onFocus={onSearchInputFocus}
|
||||||
onChangeText={onChangeText}
|
onChangeText={onChangeText}
|
||||||
onSubmit={onSubmit}
|
onSubmit={onSubmit}
|
||||||
onPressClearQuery={onPressClearQuery}
|
onPressClearQuery={onPressClearQuery}
|
||||||
/>
|
/>
|
||||||
|
{showFiltersButton && (
|
||||||
|
<Button
|
||||||
|
onPress={() => setShowFilters(!showFilters)}
|
||||||
|
hitSlop={HITSLOP_10}
|
||||||
|
label={_(msg`Show advanced filters`)}
|
||||||
|
size="large"
|
||||||
|
variant="solid"
|
||||||
|
color="secondary"
|
||||||
|
shape="square">
|
||||||
|
<Gear
|
||||||
|
size="md"
|
||||||
|
fill={
|
||||||
|
showFilters
|
||||||
|
? t.palette.primary_500
|
||||||
|
: t.atoms.text_contrast_low.color
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
{showAutocomplete && (
|
{showAutocomplete && (
|
||||||
<Button
|
<Button
|
||||||
label={_(msg`Cancel search`)}
|
label={_(msg`Cancel search`)}
|
||||||
@@ -866,7 +906,7 @@ export function SearchScreen(
|
|||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
{query && !showAutocomplete && (
|
{showFilters && (
|
||||||
<View
|
<View
|
||||||
style={[a.flex_row, a.align_center, a.justify_between, a.gap_sm]}>
|
style={[a.flex_row, a.align_center, a.justify_between, a.gap_sm]}>
|
||||||
<View style={[{width: 140}]}>
|
<View style={[{width: 140}]}>
|
||||||
@@ -924,7 +964,7 @@ let SearchInputBox = ({
|
|||||||
textInput,
|
textInput,
|
||||||
searchText,
|
searchText,
|
||||||
showAutocomplete,
|
showAutocomplete,
|
||||||
setShowAutocomplete,
|
onFocus,
|
||||||
onChangeText,
|
onChangeText,
|
||||||
onSubmit,
|
onSubmit,
|
||||||
onPressClearQuery,
|
onPressClearQuery,
|
||||||
@@ -932,7 +972,7 @@ let SearchInputBox = ({
|
|||||||
textInput: React.RefObject<TextInput>
|
textInput: React.RefObject<TextInput>
|
||||||
searchText: string
|
searchText: string
|
||||||
showAutocomplete: boolean
|
showAutocomplete: boolean
|
||||||
setShowAutocomplete: (show: boolean) => void
|
onFocus: () => void
|
||||||
onChangeText: (text: string) => void
|
onChangeText: (text: string) => void
|
||||||
onSubmit: () => void
|
onSubmit: () => void
|
||||||
onPressClearQuery: () => void
|
onPressClearQuery: () => void
|
||||||
@@ -952,17 +992,7 @@ let SearchInputBox = ({
|
|||||||
returnKeyType="search"
|
returnKeyType="search"
|
||||||
onChangeText={onChangeText}
|
onChangeText={onChangeText}
|
||||||
onSubmitEditing={onSubmit}
|
onSubmitEditing={onSubmit}
|
||||||
onFocus={() => {
|
onFocus={onFocus}
|
||||||
if (isWeb) {
|
|
||||||
// Prevent a jump on iPad by ensuring that
|
|
||||||
// the initial focused render has no result list.
|
|
||||||
requestAnimationFrame(() => {
|
|
||||||
setShowAutocomplete(true)
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
setShowAutocomplete(true)
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
keyboardAppearance={t.scheme}
|
keyboardAppearance={t.scheme}
|
||||||
selectTextOnFocus={isNative}
|
selectTextOnFocus={isNative}
|
||||||
autoFocus={false}
|
autoFocus={false}
|
||||||
|
|||||||
Reference in New Issue
Block a user