Skip to content

Commit

Permalink
Proposed, but breaking solution
Browse files Browse the repository at this point in the history
  • Loading branch information
arnautov-anton committed Dec 1, 2023
1 parent 25a7fe5 commit a160976
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions src/components/MessageInput/hooks/useUserTrigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,20 @@ export const useUserTrigger = <
async (query: string, onReady: (users: UserResponse<StreamChatGenerics>[]) => void) => {
if (!query) return;

const {
filters = { name: { $autocomplete: query } },
sort = { name: 1 },
options = { limit: 10 },
} = mentionQueryParams;

try {
const { users } = await client.queryUsers(
// @ts-expect-error
{
$or: [{ id: { $autocomplete: query } }, { name: { $autocomplete: query } }],
id: { $ne: client.userID },
...(typeof mentionQueryParams.filters === 'function'
? mentionQueryParams.filters(query)
: mentionQueryParams.filters),
},
Array.isArray(mentionQueryParams.sort)
? [{ id: 1 }, ...mentionQueryParams.sort]
: { id: 1, ...mentionQueryParams.sort },
// TODO: adjust limit
{ limit: 10, ...mentionQueryParams.options },
typeof filters === 'function' ? filters(query) : filters,
sort,
options,
);

onReady?.(users);
} catch (error) {
console.log({ error });
Expand Down Expand Up @@ -140,9 +138,9 @@ export const useUserTrigger = <
if (disableMentions) return;

if (mentionAllAppUsers) {
return queryUsersDebounced(query, (data: UserResponse<StreamChatGenerics>[]) => {
onReady?.(filterMutes(data, text), query);
});
return queryUsersDebounced(query, (data: UserResponse<StreamChatGenerics>[]) =>
onReady?.(filterMutes(data, text), query),
);
}

/**
Expand Down Expand Up @@ -170,9 +168,9 @@ export const useUserTrigger = <
return onReady?.(filterMutes(data, text), query);
}

queryMembersDebounced(query, (data: UserResponse<StreamChatGenerics>[]) => {
onReady?.(filterMutes(data, text), query);
});
queryMembersDebounced(query, (data: UserResponse<StreamChatGenerics>[]) =>
onReady?.(filterMutes(data, text), query),
);
},
output: (entity) => ({
caretPosition: 'next',
Expand Down

0 comments on commit a160976

Please sign in to comment.