Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: emoji popup trigger length #29282

Merged
merged 11 commits into from
Jun 7, 2023
5 changes: 5 additions & 0 deletions .changeset/soft-kings-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': minor
---

Added emoji popup trigger length of 3 characters.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type ComposerBoxPopupResult<T extends { _id: string; sort?: number }> =
callbackRef: (node: HTMLElement) => void;
commandsRef: ComposerBoxPopupImperativeCommands<T>;
suspended: boolean;
filter: unknown;
}
| {
popup: undefined;
Expand All @@ -37,6 +38,7 @@ type ComposerBoxPopupResult<T extends { _id: string; sort?: number }> =
select: undefined;
commandsRef: ComposerBoxPopupImperativeCommands<T>;
suspended: boolean;
filter: unknown;
};

const keys = {
Expand Down Expand Up @@ -110,7 +112,6 @@ export const useComposerBoxPopup = <T extends { _id: string; sort?: number }>({
end: chat?.composer?.selection.start,
});
}

setPopup(undefined);
setFocused(undefined);
});
Expand All @@ -124,13 +125,16 @@ export const useComposerBoxPopup = <T extends { _id: string; sort?: number }>({
return;
}

const configuration = configurations.find(({ trigger, matchSelectorRegex, triggerAnywhere }) => {
const configuration = configurations.find(({ trigger, matchSelectorRegex, triggerAnywhere, triggerLength }) => {
const selector =
matchSelectorRegex ?? (triggerAnywhere ? new RegExp(`(?:^| |\n)(${trigger})[^\\s]*$`) : new RegExp(`(?:^)(${trigger})[^\\s]*$`));
const result = selector.test(value);
return result;
if (!triggerLength || !result) {
return result;
}
const filter = value.match(selector);
return filter && triggerLength < filter[0].length;
});

setPopup(configuration);
if (!configuration) {
setFocused(undefined);
Expand Down Expand Up @@ -251,6 +255,7 @@ export const useComposerBoxPopup = <T extends { _id: string; sort?: number }>({
select: undefined,
suspended: true,
commandsRef,
filter: undefined,
};
}

Expand All @@ -260,6 +265,7 @@ export const useComposerBoxPopup = <T extends { _id: string; sort?: number }>({
ariaActiveDescendant,
popup,
select,
filter,
suspended,
commandsRef,
callbackRef,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useEffect, useState } from 'react';

import type { ComposerPopupOption } from '../../../../../client/views/room/contexts/ComposerPopupContext';
import { slashCommands } from '../../../../utils/client';
import { useEnablePopupPreview } from './useEnablePopupPreview';

export const useComposerBoxPopupQueries = <T extends { _id: string; sort?: number }>(filter: unknown, popup?: ComposerPopupOption<T>) => {
const [counter, setCounter] = useState(0);
Expand All @@ -12,11 +13,14 @@ export const useComposerBoxPopupQueries = <T extends { _id: string; sort?: numbe
setCounter(0);
}, [popup, filter]);

const shouldPopupPreview = useEnablePopupPreview(filter, popup);

const enableQuery =
!popup ||
(popup.preview &&
Boolean(slashCommands.commands[(filter as any)?.cmd]) &&
slashCommands.commands[(filter as any)?.cmd].providesPreview);
slashCommands.commands[(filter as any)?.cmd].providesPreview) ||
shouldPopupPreview;

return {
queries: useQueries({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import type { ComposerPopupOption } from '../../../../../client/views/room/contexts/ComposerPopupContext';

export const useEnablePopupPreview = <T extends { _id: string; sort?: number }>(filter: unknown, popup?: ComposerPopupOption<T>) =>
popup && !popup.preview && popup?.triggerLength ? typeof filter === 'string' && popup.triggerLength - 1 < filter.length : true;
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { formattingButtons } from '../../../../../../../app/ui-message/client/me
import ComposerBoxPopup from '../../../../../../../app/ui-message/client/popup/ComposerBoxPopup';
import ComposerBoxPopupPreview from '../../../../../../../app/ui-message/client/popup/components/composerBoxPopupPreview/ComposerBoxPopupPreview';
import { useComposerBoxPopup } from '../../../../../../../app/ui-message/client/popup/hooks/useComposerBoxPopup';
import { useEnablePopupPreview } from '../../../../../../../app/ui-message/client/popup/hooks/useEnablePopupPreview';
import { getImageExtensionFromMime } from '../../../../../../../lib/getImageExtensionFromMime';
import { useFormatDateAndTime } from '../../../../../../hooks/useFormatDateAndTime';
import { useReactiveValue } from '../../../../../../hooks/useReactiveValue';
Expand Down Expand Up @@ -332,17 +333,20 @@ const MessageBox = ({
select,
commandsRef,
callbackRef: c,
filter,
} = useComposerBoxPopup<{ _id: string; sort?: number }>({
configurations: composerPopupConfig,
});

const mergedRefs = useMessageComposerMergedRefs(c, textareaRef, callbackRef, autofocusRef);

const shouldPopupPreview = useEnablePopupPreview(filter, popup);

return (
<>
{chat.composer?.quotedMessages && <MessageBoxReplies />}

{popup && !popup.preview && (
{shouldPopupPreview && popup && (
<ComposerBoxPopup select={select} items={items} focused={focused} title={popup.title} renderItem={popup.renderItem} />
)}
{/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type ComposerPopupOption<T extends { _id: string; sort?: number } = { _id

trigger?: string;
triggerAnywhere?: boolean;
triggerLength?: number;

suffix?: string;
prefix?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ const ComposerPopupProvider = ({ children, room }: { children: ReactNode; room:
createMessageBoxPopupConfig<ComposerBoxPopupEmojiProps>({
trigger: ':',
title: t('Emoji'),
triggerLength: 2,
getItemsFromLocal: async (filter: string) => {
const exactFinalTone = new RegExp('^tone[1-5]:*$');
const colorBlind = new RegExp('tone[1-5]:*$');
Expand Down