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 = {
|
export type State = {
|
||||||
groupChatDids: string[]
|
groupChatDids: string[]
|
||||||
groupChatProfiles: bsky.profile.AnyProfileView[]
|
groupChatProfiles: bsky.profile.AnyProfileView[]
|
||||||
|
searchText: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Action =
|
export type Action =
|
||||||
@@ -80,6 +81,10 @@ export type Action =
|
|||||||
groupChatDids: string[]
|
groupChatDids: string[]
|
||||||
groupChatProfiles: bsky.profile.AnyProfileView[]
|
groupChatProfiles: bsky.profile.AnyProfileView[]
|
||||||
}
|
}
|
||||||
|
| {
|
||||||
|
type: 'setSearchText'
|
||||||
|
searchText: string
|
||||||
|
}
|
||||||
|
|
||||||
function reducer(state: State, action: Action): State {
|
function reducer(state: State, action: Action): State {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
@@ -88,6 +93,7 @@ function reducer(state: State, action: Action): State {
|
|||||||
...state,
|
...state,
|
||||||
groupChatDids: action.groupChatDids,
|
groupChatDids: action.groupChatDids,
|
||||||
groupChatProfiles: action.groupChatProfiles,
|
groupChatProfiles: action.groupChatProfiles,
|
||||||
|
searchText: '',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 'removeDids': {
|
case 'removeDids': {
|
||||||
@@ -97,6 +103,12 @@ function reducer(state: State, action: Action): State {
|
|||||||
groupChatProfiles: action.groupChatProfiles,
|
groupChatProfiles: action.groupChatProfiles,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case 'setSearchText': {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
searchText: action.searchText,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,11 +133,19 @@ export function AddMembersFlow({
|
|||||||
|
|
||||||
const [headerHeight, setHeaderHeight] = useState(0)
|
const [headerHeight, setHeaderHeight] = useState(0)
|
||||||
const [footerHeight, setFooterHeight] = useState(0)
|
const [footerHeight, setFooterHeight] = useState(0)
|
||||||
const [searchText, setSearchText] = useState('')
|
|
||||||
|
|
||||||
const listRef = useRef<ListMethods>(null)
|
const listRef = useRef<ListMethods>(null)
|
||||||
const inputRef = useRef<TextInput>(null)
|
const inputRef = useRef<TextInput>(null)
|
||||||
|
|
||||||
|
const [{groupChatDids, groupChatProfiles, searchText}, dispatch] = useReducer(
|
||||||
|
reducer,
|
||||||
|
{
|
||||||
|
groupChatDids: [],
|
||||||
|
groupChatProfiles: [],
|
||||||
|
searchText: '',
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: autocompleteResults,
|
data: autocompleteResults,
|
||||||
isError,
|
isError,
|
||||||
@@ -151,11 +171,6 @@ export function AddMembersFlow({
|
|||||||
? Math.max(0, groupMemberLimit - memberListData.length)
|
? Math.max(0, groupMemberLimit - memberListData.length)
|
||||||
: undefined
|
: undefined
|
||||||
|
|
||||||
const [{groupChatDids, groupChatProfiles}, dispatch] = useReducer(reducer, {
|
|
||||||
groupChatDids: [],
|
|
||||||
groupChatProfiles: [],
|
|
||||||
})
|
|
||||||
|
|
||||||
const onRemoveDid = useCallback(
|
const onRemoveDid = useCallback(
|
||||||
(did: string) => {
|
(did: string) => {
|
||||||
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)
|
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)
|
||||||
@@ -405,7 +420,7 @@ export function AddMembersFlow({
|
|||||||
inputRef={inputRef}
|
inputRef={inputRef}
|
||||||
value={searchText}
|
value={searchText}
|
||||||
onChangeText={text => {
|
onChangeText={text => {
|
||||||
setSearchText(text)
|
dispatch({type: 'setSearchText', searchText: text})
|
||||||
listRef.current?.scrollToOffset({offset: 0, animated: false})
|
listRef.current?.scrollToOffset({offset: 0, animated: false})
|
||||||
}}
|
}}
|
||||||
onEscape={control.close}
|
onEscape={control.close}
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ export type State = {
|
|||||||
groupChatDids: string[]
|
groupChatDids: string[]
|
||||||
groupChatProfiles: bsky.profile.AnyProfileView[]
|
groupChatProfiles: bsky.profile.AnyProfileView[]
|
||||||
groupName: string
|
groupName: string
|
||||||
|
searchText: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Action =
|
export type Action =
|
||||||
@@ -132,6 +133,10 @@ export type Action =
|
|||||||
type: 'goBackFromGroupName'
|
type: 'goBackFromGroupName'
|
||||||
screenTitle: string
|
screenTitle: string
|
||||||
}
|
}
|
||||||
|
| {
|
||||||
|
type: 'setSearchText'
|
||||||
|
searchText: string
|
||||||
|
}
|
||||||
|
|
||||||
function reducer(state: State, action: Action): State {
|
function reducer(state: State, action: Action): State {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
@@ -150,6 +155,7 @@ function reducer(state: State, action: Action): State {
|
|||||||
...state,
|
...state,
|
||||||
groupChatDids: action.groupChatDids,
|
groupChatDids: action.groupChatDids,
|
||||||
groupChatProfiles: action.groupChatProfiles,
|
groupChatProfiles: action.groupChatProfiles,
|
||||||
|
searchText: '',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 'removeDids': {
|
case 'removeDids': {
|
||||||
@@ -164,6 +170,7 @@ function reducer(state: State, action: Action): State {
|
|||||||
...state,
|
...state,
|
||||||
chatState: ChatState.GROUP_NAME,
|
chatState: ChatState.GROUP_NAME,
|
||||||
screenTitle: action.screenTitle,
|
screenTitle: action.screenTitle,
|
||||||
|
searchText: '',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 'nameGroup': {
|
case 'nameGroup': {
|
||||||
@@ -180,6 +187,7 @@ function reducer(state: State, action: Action): State {
|
|||||||
groupChatDids: [],
|
groupChatDids: [],
|
||||||
groupChatProfiles: [],
|
groupChatProfiles: [],
|
||||||
groupName: '',
|
groupName: '',
|
||||||
|
searchText: '',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 'goBackFromGroupName': {
|
case 'goBackFromGroupName': {
|
||||||
@@ -190,6 +198,12 @@ function reducer(state: State, action: Action): State {
|
|||||||
groupName: '',
|
groupName: '',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case 'setSearchText': {
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
searchText: action.searchText,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,17 +232,15 @@ export function InitiateChatFlow({
|
|||||||
const canCreateGroups = chatStatus?.canCreateGroups ?? true
|
const canCreateGroups = chatStatus?.canCreateGroups ?? true
|
||||||
const groupMemberLimit = chatStatus?.groupMemberLimit
|
const groupMemberLimit = chatStatus?.groupMemberLimit
|
||||||
|
|
||||||
const [searchText, setSearchText] = useState('')
|
|
||||||
|
|
||||||
const {
|
|
||||||
data: results,
|
|
||||||
isError,
|
|
||||||
isFetching,
|
|
||||||
} = useActorAutocompleteQuery(searchText, true, 12)
|
|
||||||
const {data: follows} = useProfileFollowsQuery(currentAccount?.did)
|
|
||||||
|
|
||||||
const [
|
const [
|
||||||
{chatState, screenTitle, groupChatDids, groupChatProfiles, groupName},
|
{
|
||||||
|
chatState,
|
||||||
|
screenTitle,
|
||||||
|
groupChatDids,
|
||||||
|
groupChatProfiles,
|
||||||
|
groupName,
|
||||||
|
searchText,
|
||||||
|
},
|
||||||
dispatch,
|
dispatch,
|
||||||
] = useReducer(reducer, {
|
] = useReducer(reducer, {
|
||||||
chatState: ChatState.NEW_CHAT,
|
chatState: ChatState.NEW_CHAT,
|
||||||
@@ -236,8 +248,16 @@ export function InitiateChatFlow({
|
|||||||
groupChatDids: [],
|
groupChatDids: [],
|
||||||
groupChatProfiles: [],
|
groupChatProfiles: [],
|
||||||
groupName: '',
|
groupName: '',
|
||||||
|
searchText: '',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: results,
|
||||||
|
isError,
|
||||||
|
isFetching,
|
||||||
|
} = useActorAutocompleteQuery(searchText, true, 12)
|
||||||
|
const {data: follows} = useProfileFollowsQuery(currentAccount?.did)
|
||||||
|
|
||||||
const newGroupChatTitle = l`New group chat`
|
const newGroupChatTitle = l`New group chat`
|
||||||
const groupNameTitle = l`Group name`
|
const groupNameTitle = l`Group name`
|
||||||
|
|
||||||
@@ -362,7 +382,6 @@ export function InitiateChatFlow({
|
|||||||
case ChatState.NEW_GROUP_CHAT:
|
case ChatState.NEW_GROUP_CHAT:
|
||||||
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)
|
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)
|
||||||
dispatch({type: 'goBackFromNewGroupChat', screenTitle: title})
|
dispatch({type: 'goBackFromNewGroupChat', screenTitle: title})
|
||||||
setSearchText('')
|
|
||||||
break
|
break
|
||||||
case ChatState.GROUP_NAME:
|
case ChatState.GROUP_NAME:
|
||||||
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)
|
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)
|
||||||
@@ -383,7 +402,6 @@ export function InitiateChatFlow({
|
|||||||
const handlePressNext = useCallback(() => {
|
const handlePressNext = useCallback(() => {
|
||||||
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)
|
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)
|
||||||
dispatch({type: 'startNameGroup', screenTitle: groupNameTitle})
|
dispatch({type: 'startNameGroup', screenTitle: groupNameTitle})
|
||||||
setSearchText('')
|
|
||||||
}, [groupNameTitle])
|
}, [groupNameTitle])
|
||||||
|
|
||||||
const handlePressConfirm = useCallback(() => {
|
const handlePressConfirm = useCallback(() => {
|
||||||
@@ -617,7 +635,7 @@ export function InitiateChatFlow({
|
|||||||
inputRef={inputRef}
|
inputRef={inputRef}
|
||||||
value={searchText}
|
value={searchText}
|
||||||
onChangeText={text => {
|
onChangeText={text => {
|
||||||
setSearchText(text)
|
dispatch({type: 'setSearchText', searchText: text})
|
||||||
listRef.current?.scrollToOffset({offset: 0, animated: false})
|
listRef.current?.scrollToOffset({offset: 0, animated: false})
|
||||||
}}
|
}}
|
||||||
onEscape={control.close}
|
onEscape={control.close}
|
||||||
|
|||||||
Reference in New Issue
Block a user