Clear search term after adding chat member (#10831)
This commit is contained in:
@@ -67,6 +67,7 @@ type Item = LabelItem | ProfileItem | EmptyItem | PlaceholderItem | LoadingItem
|
||||
export type State = {
|
||||
groupChatDids: string[]
|
||||
groupChatProfiles: bsky.profile.AnyProfileView[]
|
||||
searchText: string
|
||||
}
|
||||
|
||||
export type Action =
|
||||
@@ -80,6 +81,10 @@ export type Action =
|
||||
groupChatDids: string[]
|
||||
groupChatProfiles: bsky.profile.AnyProfileView[]
|
||||
}
|
||||
| {
|
||||
type: 'setSearchText'
|
||||
searchText: string
|
||||
}
|
||||
|
||||
function reducer(state: State, action: Action): State {
|
||||
switch (action.type) {
|
||||
@@ -88,6 +93,7 @@ function reducer(state: State, action: Action): State {
|
||||
...state,
|
||||
groupChatDids: action.groupChatDids,
|
||||
groupChatProfiles: action.groupChatProfiles,
|
||||
searchText: '',
|
||||
}
|
||||
}
|
||||
case 'removeDids': {
|
||||
@@ -97,6 +103,12 @@ function reducer(state: State, action: Action): State {
|
||||
groupChatProfiles: action.groupChatProfiles,
|
||||
}
|
||||
}
|
||||
case 'setSearchText': {
|
||||
return {
|
||||
...state,
|
||||
searchText: action.searchText,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,11 +133,19 @@ export function AddMembersFlow({
|
||||
|
||||
const [headerHeight, setHeaderHeight] = useState(0)
|
||||
const [footerHeight, setFooterHeight] = useState(0)
|
||||
const [searchText, setSearchText] = useState('')
|
||||
|
||||
const listRef = useRef<ListMethods>(null)
|
||||
const inputRef = useRef<TextInput>(null)
|
||||
|
||||
const [{groupChatDids, groupChatProfiles, searchText}, dispatch] = useReducer(
|
||||
reducer,
|
||||
{
|
||||
groupChatDids: [],
|
||||
groupChatProfiles: [],
|
||||
searchText: '',
|
||||
},
|
||||
)
|
||||
|
||||
const {
|
||||
data: autocompleteResults,
|
||||
isError,
|
||||
@@ -151,11 +171,6 @@ export function AddMembersFlow({
|
||||
? Math.max(0, groupMemberLimit - memberListData.length)
|
||||
: undefined
|
||||
|
||||
const [{groupChatDids, groupChatProfiles}, dispatch] = useReducer(reducer, {
|
||||
groupChatDids: [],
|
||||
groupChatProfiles: [],
|
||||
})
|
||||
|
||||
const onRemoveDid = useCallback(
|
||||
(did: string) => {
|
||||
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)
|
||||
@@ -405,7 +420,7 @@ export function AddMembersFlow({
|
||||
inputRef={inputRef}
|
||||
value={searchText}
|
||||
onChangeText={text => {
|
||||
setSearchText(text)
|
||||
dispatch({type: 'setSearchText', searchText: text})
|
||||
listRef.current?.scrollToOffset({offset: 0, animated: false})
|
||||
}}
|
||||
onEscape={control.close}
|
||||
|
||||
Reference in New Issue
Block a user