mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-02-26 15:13:05 +01:00
Improve search result counts (#2221)
* remove limit from emoji autocomplete * remove search limit from user mention * remove limit from room mention autocomplete * increase user search limit to 1000 * better search string selection for emoticons
This commit is contained in:
parent
3ada21a1df
commit
1b200eb676
6 changed files with 53 additions and 40 deletions
|
@ -6,11 +6,7 @@ import { Room } from 'matrix-js-sdk';
|
||||||
import { AutocompleteQuery } from './autocompleteQuery';
|
import { AutocompleteQuery } from './autocompleteQuery';
|
||||||
import { AutocompleteMenu } from './AutocompleteMenu';
|
import { AutocompleteMenu } from './AutocompleteMenu';
|
||||||
import { useMatrixClient } from '../../../hooks/useMatrixClient';
|
import { useMatrixClient } from '../../../hooks/useMatrixClient';
|
||||||
import {
|
import { UseAsyncSearchOptions, useAsyncSearch } from '../../../hooks/useAsyncSearch';
|
||||||
SearchItemStrGetter,
|
|
||||||
UseAsyncSearchOptions,
|
|
||||||
useAsyncSearch,
|
|
||||||
} from '../../../hooks/useAsyncSearch';
|
|
||||||
import { onTabPress } from '../../../utils/keyboard';
|
import { onTabPress } from '../../../utils/keyboard';
|
||||||
import { createEmoticonElement, moveCursor, replaceWithElement } from '../utils';
|
import { createEmoticonElement, moveCursor, replaceWithElement } from '../utils';
|
||||||
import { useRecentEmoji } from '../../../hooks/useRecentEmoji';
|
import { useRecentEmoji } from '../../../hooks/useRecentEmoji';
|
||||||
|
@ -20,6 +16,7 @@ import { useKeyDown } from '../../../hooks/useKeyDown';
|
||||||
import { mxcUrlToHttp } from '../../../utils/matrix';
|
import { mxcUrlToHttp } from '../../../utils/matrix';
|
||||||
import { useMediaAuthentication } from '../../../hooks/useMediaAuthentication';
|
import { useMediaAuthentication } from '../../../hooks/useMediaAuthentication';
|
||||||
import { ImageUsage, PackImageReader } from '../../../plugins/custom-emoji';
|
import { ImageUsage, PackImageReader } from '../../../plugins/custom-emoji';
|
||||||
|
import { getEmoticonSearchStr } from '../../../plugins/utils';
|
||||||
|
|
||||||
type EmoticonCompleteHandler = (key: string, shortcode: string) => void;
|
type EmoticonCompleteHandler = (key: string, shortcode: string) => void;
|
||||||
|
|
||||||
|
@ -33,16 +30,11 @@ type EmoticonAutocompleteProps = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const SEARCH_OPTIONS: UseAsyncSearchOptions = {
|
const SEARCH_OPTIONS: UseAsyncSearchOptions = {
|
||||||
limit: 20,
|
|
||||||
matchOptions: {
|
matchOptions: {
|
||||||
contain: true,
|
contain: true,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const getEmoticonStr: SearchItemStrGetter<EmoticonSearchItem> = (emoticon) => [
|
|
||||||
`:${emoticon.shortcode}:`,
|
|
||||||
];
|
|
||||||
|
|
||||||
export function EmoticonAutocomplete({
|
export function EmoticonAutocomplete({
|
||||||
imagePackRooms,
|
imagePackRooms,
|
||||||
editor,
|
editor,
|
||||||
|
@ -63,8 +55,12 @@ export function EmoticonAutocomplete({
|
||||||
);
|
);
|
||||||
}, [imagePacks]);
|
}, [imagePacks]);
|
||||||
|
|
||||||
const [result, search, resetSearch] = useAsyncSearch(searchList, getEmoticonStr, SEARCH_OPTIONS);
|
const [result, search, resetSearch] = useAsyncSearch(
|
||||||
const autoCompleteEmoticon = result ? result.items : recentEmoji;
|
searchList,
|
||||||
|
getEmoticonSearchStr,
|
||||||
|
SEARCH_OPTIONS
|
||||||
|
);
|
||||||
|
const autoCompleteEmoticon = result ? result.items.slice(0, 20) : recentEmoji;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (query.text) search(query.text);
|
if (query.text) search(query.text);
|
||||||
|
|
|
@ -65,7 +65,6 @@ type RoomMentionAutocompleteProps = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const SEARCH_OPTIONS: UseAsyncSearchOptions = {
|
const SEARCH_OPTIONS: UseAsyncSearchOptions = {
|
||||||
limit: 20,
|
|
||||||
matchOptions: {
|
matchOptions: {
|
||||||
contain: true,
|
contain: true,
|
||||||
},
|
},
|
||||||
|
@ -97,7 +96,7 @@ export function RoomMentionAutocomplete({
|
||||||
SEARCH_OPTIONS
|
SEARCH_OPTIONS
|
||||||
);
|
);
|
||||||
|
|
||||||
const autoCompleteRoomIds = result ? result.items : allRooms.slice(0, 20);
|
const autoCompleteRoomIds = result ? result.items.slice(0, 20) : allRooms.slice(0, 20);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (query.text) search(query.text);
|
if (query.text) search(query.text);
|
||||||
|
|
|
@ -74,7 +74,7 @@ const withAllowedMembership = (member: RoomMember): boolean =>
|
||||||
member.membership === Membership.Knock;
|
member.membership === Membership.Knock;
|
||||||
|
|
||||||
const SEARCH_OPTIONS: UseAsyncSearchOptions = {
|
const SEARCH_OPTIONS: UseAsyncSearchOptions = {
|
||||||
limit: 20,
|
limit: 1000,
|
||||||
matchOptions: {
|
matchOptions: {
|
||||||
contain: true,
|
contain: true,
|
||||||
},
|
},
|
||||||
|
@ -97,7 +97,7 @@ export function UserMentionAutocomplete({
|
||||||
const members = useRoomMembers(mx, roomId);
|
const members = useRoomMembers(mx, roomId);
|
||||||
|
|
||||||
const [result, search, resetSearch] = useAsyncSearch(members, getRoomMemberStr, SEARCH_OPTIONS);
|
const [result, search, resetSearch] = useAsyncSearch(members, getRoomMemberStr, SEARCH_OPTIONS);
|
||||||
const autoCompleteMembers = (result ? result.items : members.slice(0, 20)).filter(
|
const autoCompleteMembers = (result ? result.items.slice(0, 20) : members.slice(0, 20)).filter(
|
||||||
withAllowedMembership
|
withAllowedMembership
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@ import { addRecentEmoji } from '../../plugins/recent-emoji';
|
||||||
import { mobileOrTablet } from '../../utils/user-agent';
|
import { mobileOrTablet } from '../../utils/user-agent';
|
||||||
import { useMediaAuthentication } from '../../hooks/useMediaAuthentication';
|
import { useMediaAuthentication } from '../../hooks/useMediaAuthentication';
|
||||||
import { ImagePack, ImageUsage, PackImageReader } from '../../plugins/custom-emoji';
|
import { ImagePack, ImageUsage, PackImageReader } from '../../plugins/custom-emoji';
|
||||||
|
import { getEmoticonSearchStr } from '../../plugins/utils';
|
||||||
|
|
||||||
const RECENT_GROUP_ID = 'recent_group';
|
const RECENT_GROUP_ID = 'recent_group';
|
||||||
const SEARCH_GROUP_ID = 'search_group';
|
const SEARCH_GROUP_ID = 'search_group';
|
||||||
|
@ -636,15 +637,8 @@ export const NativeEmojiGroups = memo(
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
const getSearchListItemStr = (item: PackImageReader | IEmoji) => {
|
|
||||||
const shortcode = `:${item.shortcode}:`;
|
|
||||||
if ('body' in item) {
|
|
||||||
return [shortcode, item.body ?? ''];
|
|
||||||
}
|
|
||||||
return shortcode;
|
|
||||||
};
|
|
||||||
const SEARCH_OPTIONS: UseAsyncSearchOptions = {
|
const SEARCH_OPTIONS: UseAsyncSearchOptions = {
|
||||||
limit: 26,
|
limit: 1000,
|
||||||
matchOptions: {
|
matchOptions: {
|
||||||
contain: true,
|
contain: true,
|
||||||
},
|
},
|
||||||
|
@ -696,10 +690,12 @@ export function EmojiBoard({
|
||||||
|
|
||||||
const [result, search, resetSearch] = useAsyncSearch(
|
const [result, search, resetSearch] = useAsyncSearch(
|
||||||
searchList,
|
searchList,
|
||||||
getSearchListItemStr,
|
getEmoticonSearchStr,
|
||||||
SEARCH_OPTIONS
|
SEARCH_OPTIONS
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const searchedItems = result?.items.slice(0, 100);
|
||||||
|
|
||||||
const handleOnChange: ChangeEventHandler<HTMLInputElement> = useDebounce(
|
const handleOnChange: ChangeEventHandler<HTMLInputElement> = useDebounce(
|
||||||
useCallback(
|
useCallback(
|
||||||
(evt) => {
|
(evt) => {
|
||||||
|
@ -920,13 +916,13 @@ export function EmojiBoard({
|
||||||
direction="Column"
|
direction="Column"
|
||||||
gap="200"
|
gap="200"
|
||||||
>
|
>
|
||||||
{result && (
|
{searchedItems && (
|
||||||
<SearchEmojiGroup
|
<SearchEmojiGroup
|
||||||
mx={mx}
|
mx={mx}
|
||||||
tab={tab}
|
tab={tab}
|
||||||
id={SEARCH_GROUP_ID}
|
id={SEARCH_GROUP_ID}
|
||||||
label={result.items.length ? 'Search Results' : 'No Results found'}
|
label={searchedItems.length ? 'Search Results' : 'No Results found'}
|
||||||
emojis={result.items}
|
emojis={searchedItems}
|
||||||
useAuthentication={useAuthentication}
|
useAuthentication={useAuthentication}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -156,7 +156,7 @@ export type MembersFilterOptions = {
|
||||||
};
|
};
|
||||||
|
|
||||||
const SEARCH_OPTIONS: UseAsyncSearchOptions = {
|
const SEARCH_OPTIONS: UseAsyncSearchOptions = {
|
||||||
limit: 100,
|
limit: 1000,
|
||||||
matchOptions: {
|
matchOptions: {
|
||||||
contain: true,
|
contain: true,
|
||||||
},
|
},
|
||||||
|
@ -428,7 +428,8 @@ export function MembersDrawer({ room, members }: MembersDrawerProps) {
|
||||||
}}
|
}}
|
||||||
after={<Icon size="50" src={Icons.Cross} />}
|
after={<Icon size="50" src={Icons.Cross} />}
|
||||||
>
|
>
|
||||||
<Text size="B300">{`${result.items.length || 'No'} ${result.items.length === 1 ? 'Result' : 'Results'
|
<Text size="B300">{`${result.items.length || 'No'} ${
|
||||||
|
result.items.length === 1 ? 'Result' : 'Results'
|
||||||
}`}</Text>
|
}`}</Text>
|
||||||
</Chip>
|
</Chip>
|
||||||
)
|
)
|
||||||
|
@ -485,7 +486,8 @@ export function MembersDrawer({ room, members }: MembersDrawerProps) {
|
||||||
const member = tagOrMember;
|
const member = tagOrMember;
|
||||||
const name = getName(member);
|
const name = getName(member);
|
||||||
const avatarMxcUrl = member.getMxcAvatarUrl();
|
const avatarMxcUrl = member.getMxcAvatarUrl();
|
||||||
const avatarUrl = avatarMxcUrl ? mx.mxcUrlToHttp(
|
const avatarUrl = avatarMxcUrl
|
||||||
|
? mx.mxcUrlToHttp(
|
||||||
avatarMxcUrl,
|
avatarMxcUrl,
|
||||||
100,
|
100,
|
||||||
100,
|
100,
|
||||||
|
@ -493,7 +495,8 @@ export function MembersDrawer({ room, members }: MembersDrawerProps) {
|
||||||
undefined,
|
undefined,
|
||||||
false,
|
false,
|
||||||
useAuthentication
|
useAuthentication
|
||||||
) : undefined;
|
)
|
||||||
|
: undefined;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MenuItem
|
<MenuItem
|
||||||
|
|
19
src/app/plugins/utils.ts
Normal file
19
src/app/plugins/utils.ts
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import { SearchItemStrGetter } from '../hooks/useAsyncSearch';
|
||||||
|
import { PackImageReader } from './custom-emoji';
|
||||||
|
import { IEmoji } from './emoji';
|
||||||
|
|
||||||
|
export const getEmoticonSearchStr: SearchItemStrGetter<PackImageReader | IEmoji> = (item) => {
|
||||||
|
const shortcode = `:${item.shortcode}:`;
|
||||||
|
if (item instanceof PackImageReader) {
|
||||||
|
if (item.body) {
|
||||||
|
return [shortcode, item.body];
|
||||||
|
}
|
||||||
|
return shortcode;
|
||||||
|
}
|
||||||
|
|
||||||
|
const names = [shortcode, item.label];
|
||||||
|
if (Array.isArray(item.shortcodes)) {
|
||||||
|
return names.concat(item.shortcodes);
|
||||||
|
}
|
||||||
|
return names;
|
||||||
|
};
|
Loading…
Reference in a new issue