Fix issue where last RecentProfileItem can't be removed (#10441)
This commit is contained in:
@@ -94,12 +94,12 @@ export function SearchScreenShell({
|
|||||||
const [activeTab, setActiveTab] = useState(() => getTabIndex(tabParam))
|
const [activeTab, setActiveTab] = useState(() => getTabIndex(tabParam))
|
||||||
|
|
||||||
// Query terms
|
// Query terms
|
||||||
const [searchText, _setSearchText] = useState<string>(queryParam)
|
const [searchText, setSearchText] = useState<string>(queryParam)
|
||||||
const searchTextRef = useRef(searchText)
|
const searchTextRef = useRef(searchText)
|
||||||
const setSearchText = (text: string) => {
|
const updateSearchText = useCallback((text: string) => {
|
||||||
searchTextRef.current = text
|
searchTextRef.current = text
|
||||||
_setSearchText(text)
|
setSearchText(text)
|
||||||
}
|
}, [])
|
||||||
const {data: autocompleteData, isFetching: isAutocompleteFetching} =
|
const {data: autocompleteData, isFetching: isAutocompleteFetching} =
|
||||||
useActorAutocompleteQuery(searchText, true)
|
useActorAutocompleteQuery(searchText, true)
|
||||||
|
|
||||||
@@ -175,21 +175,24 @@ export function SearchScreenShell({
|
|||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useNonReactiveCallback(() => {
|
useNonReactiveCallback(() => {
|
||||||
if (IS_WEB) {
|
if (IS_WEB) {
|
||||||
setSearchText(queryParam)
|
updateSearchText(queryParam)
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
const onPressClearQuery = useCallback(() => {
|
const onPressClearQuery = useCallback(() => {
|
||||||
scrollToTopWeb()
|
scrollToTopWeb()
|
||||||
setSearchText('')
|
updateSearchText('')
|
||||||
textInput.current?.focus()
|
textInput.current?.focus()
|
||||||
}, [])
|
}, [updateSearchText])
|
||||||
|
|
||||||
const onChangeText = useCallback((text: string) => {
|
const onChangeText = useCallback(
|
||||||
scrollToTopWeb()
|
(text: string) => {
|
||||||
setSearchText(text)
|
scrollToTopWeb()
|
||||||
}, [])
|
updateSearchText(text)
|
||||||
|
},
|
||||||
|
[updateSearchText],
|
||||||
|
)
|
||||||
|
|
||||||
const navigateToItem = useCallback(
|
const navigateToItem = useCallback(
|
||||||
(item: string) => {
|
(item: string) => {
|
||||||
@@ -225,10 +228,16 @@ export function SearchScreenShell({
|
|||||||
// @ts-expect-error route is not typesafe
|
// @ts-expect-error route is not typesafe
|
||||||
navigation.replace(route.name, parameters)
|
navigation.replace(route.name, parameters)
|
||||||
} else {
|
} else {
|
||||||
setSearchText('')
|
updateSearchText('')
|
||||||
navigation.setParams({q: '', tab: undefined})
|
navigation.setParams({q: '', tab: undefined})
|
||||||
}
|
}
|
||||||
}, [setShowAutocomplete, setSearchText, navigation, route.params, route.name])
|
}, [
|
||||||
|
setShowAutocomplete,
|
||||||
|
updateSearchText,
|
||||||
|
navigation,
|
||||||
|
route.params,
|
||||||
|
route.name,
|
||||||
|
])
|
||||||
|
|
||||||
const onSubmit = (source: 'typed' | 'autocomplete') => () => {
|
const onSubmit = (source: 'typed' | 'autocomplete') => () => {
|
||||||
ax.metric('search:query', {
|
ax.metric('search:query', {
|
||||||
@@ -247,10 +256,10 @@ export function SearchScreenShell({
|
|||||||
|
|
||||||
const handleHistoryItemClick = useCallback(
|
const handleHistoryItemClick = useCallback(
|
||||||
(item: string) => {
|
(item: string) => {
|
||||||
setSearchText(item)
|
updateSearchText(item)
|
||||||
navigateToItem(item)
|
navigateToItem(item)
|
||||||
},
|
},
|
||||||
[navigateToItem],
|
[navigateToItem, updateSearchText],
|
||||||
)
|
)
|
||||||
|
|
||||||
const handleProfileClick = useCallback(
|
const handleProfileClick = useCallback(
|
||||||
@@ -278,11 +287,11 @@ export function SearchScreenShell({
|
|||||||
// @ts-expect-error route is not typesafe
|
// @ts-expect-error route is not typesafe
|
||||||
navigation.replace(route.name, parameters)
|
navigation.replace(route.name, parameters)
|
||||||
} else {
|
} else {
|
||||||
setSearchText('')
|
updateSearchText('')
|
||||||
navigation.setParams({q: '', tab: undefined})
|
navigation.setParams({q: '', tab: undefined})
|
||||||
textInput.current?.focus()
|
textInput.current?.focus()
|
||||||
}
|
}
|
||||||
}, [navigation, route])
|
}, [navigation, route.name, route.params, updateSearchText])
|
||||||
|
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
@@ -435,7 +444,11 @@ export function SearchScreenShell({
|
|||||||
) : (
|
) : (
|
||||||
<SearchHistory
|
<SearchHistory
|
||||||
searchHistory={termHistory}
|
searchHistory={termHistory}
|
||||||
selectedProfiles={accountHistoryProfiles?.profiles || []}
|
selectedProfiles={
|
||||||
|
accountHistoryProfiles?.profiles.filter(p =>
|
||||||
|
accountHistory.includes(p.did),
|
||||||
|
) ?? []
|
||||||
|
}
|
||||||
onItemClick={handleHistoryItemClick}
|
onItemClick={handleHistoryItemClick}
|
||||||
onProfileClick={handleProfileClick}
|
onProfileClick={handleProfileClick}
|
||||||
onRemoveItemClick={deleteSearchHistoryItem}
|
onRemoveItemClick={deleteSearchHistoryItem}
|
||||||
|
|||||||
Reference in New Issue
Block a user