Use Event for emoji
parent
75be1f9954
commit
7fcc65a3fe
|
@ -22,8 +22,8 @@ import { PlainTextComposer } from './components/PlainTextComposer';
|
||||||
import { ComposerFunctions } from './types';
|
import { ComposerFunctions } from './types';
|
||||||
import { E2EStatus } from '../../../../utils/ShieldUtils';
|
import { E2EStatus } from '../../../../utils/ShieldUtils';
|
||||||
import E2EIcon from '../E2EIcon';
|
import E2EIcon from '../E2EIcon';
|
||||||
import { EmojiButton } from '../EmojiButton';
|
|
||||||
import { AboveLeftOf } from '../../../structures/ContextMenu';
|
import { AboveLeftOf } from '../../../structures/ContextMenu';
|
||||||
|
import { Emoji } from './components/Emoji';
|
||||||
|
|
||||||
interface ContentProps {
|
interface ContentProps {
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
|
@ -58,15 +58,8 @@ export function SendWysiwygComposer(
|
||||||
return <Composer
|
return <Composer
|
||||||
className="mx_SendWysiwygComposer"
|
className="mx_SendWysiwygComposer"
|
||||||
leftComponent={e2eStatus && <E2EIcon status={e2eStatus} />}
|
leftComponent={e2eStatus && <E2EIcon status={e2eStatus} />}
|
||||||
// TODO add emoji support
|
rightComponent={(selectPreviousSelection) =>
|
||||||
rightComponent={(composerFunctions, selectPreviousSelection) =>
|
<Emoji menuPosition={menuPosition} selectPreviousSelection={selectPreviousSelection} />}
|
||||||
<EmojiButton menuPosition={menuPosition}
|
|
||||||
addEmoji={(unicode) => {
|
|
||||||
selectPreviousSelection();
|
|
||||||
setTimeout(() => composerFunctions.insertText(unicode), 100);
|
|
||||||
return true;
|
|
||||||
}}
|
|
||||||
/>}
|
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
{ (ref, composerFunctions) => (
|
{ (ref, composerFunctions) => (
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
/*
|
||||||
|
Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import { AboveLeftOf } from "../../../../structures/ContextMenu";
|
||||||
|
import { EmojiButton } from "../../EmojiButton";
|
||||||
|
import dis from '../../../../../dispatcher/dispatcher';
|
||||||
|
import { ComposerInsertPayload } from "../../../../../dispatcher/payloads/ComposerInsertPayload";
|
||||||
|
import { Action } from "../../../../../dispatcher/actions";
|
||||||
|
import { useRoomContext } from "../../../../../contexts/RoomContext";
|
||||||
|
|
||||||
|
interface EmojiProps {
|
||||||
|
selectPreviousSelection: () => void;
|
||||||
|
menuPosition: AboveLeftOf;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Emoji({ selectPreviousSelection, menuPosition }: EmojiProps) {
|
||||||
|
const roomContext = useRoomContext();
|
||||||
|
|
||||||
|
return <EmojiButton menuPosition={menuPosition}
|
||||||
|
addEmoji={(emoji) => {
|
||||||
|
selectPreviousSelection();
|
||||||
|
dis.dispatch<ComposerInsertPayload>({
|
||||||
|
action: Action.ComposerInsert,
|
||||||
|
text: emoji,
|
||||||
|
timelineRenderingType: roomContext.timelineRenderingType,
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}}
|
||||||
|
/>;
|
||||||
|
}
|
|
@ -34,7 +34,6 @@ interface PlainTextComposerProps {
|
||||||
className?: string;
|
className?: string;
|
||||||
leftComponent?: ReactNode;
|
leftComponent?: ReactNode;
|
||||||
rightComponent?: (
|
rightComponent?: (
|
||||||
composerFunctions: ComposerFunctions,
|
|
||||||
selectPreviousSelection: () => void
|
selectPreviousSelection: () => void
|
||||||
) => ReactNode;
|
) => ReactNode;
|
||||||
children?: (
|
children?: (
|
||||||
|
@ -61,8 +60,6 @@ export function PlainTextComposer({
|
||||||
useSetCursorPosition(disabled, ref);
|
useSetCursorPosition(disabled, ref);
|
||||||
const { isFocused, onFocus } = useIsFocused();
|
const { isFocused, onFocus } = useIsFocused();
|
||||||
const computedPlaceholder = !content && placeholder || undefined;
|
const computedPlaceholder = !content && placeholder || undefined;
|
||||||
const rightComp =
|
|
||||||
(selectPreviousSelection: () => void) => rightComponent(composerFunctions, selectPreviousSelection);
|
|
||||||
|
|
||||||
return <div
|
return <div
|
||||||
data-testid="PlainTextComposer"
|
data-testid="PlainTextComposer"
|
||||||
|
@ -73,7 +70,7 @@ export function PlainTextComposer({
|
||||||
onPaste={onPaste}
|
onPaste={onPaste}
|
||||||
onKeyDown={onKeyDown}
|
onKeyDown={onKeyDown}
|
||||||
>
|
>
|
||||||
<Editor ref={ref} disabled={disabled} leftComponent={leftComponent} rightComponent={rightComp} placeholder={computedPlaceholder} />
|
<Editor ref={ref} disabled={disabled} leftComponent={leftComponent} rightComponent={rightComponent} placeholder={computedPlaceholder} />
|
||||||
{ children?.(ref, composerFunctions) }
|
{ children?.(ref, composerFunctions) }
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,6 @@ interface WysiwygComposerProps {
|
||||||
className?: string;
|
className?: string;
|
||||||
leftComponent?: ReactNode;
|
leftComponent?: ReactNode;
|
||||||
rightComponent?: (
|
rightComponent?: (
|
||||||
composerFunctions: FormattingFunctions,
|
|
||||||
selectPreviousSelection: () => void
|
selectPreviousSelection: () => void
|
||||||
) => ReactNode;
|
) => ReactNode;
|
||||||
children?: (
|
children?: (
|
||||||
|
@ -72,12 +71,10 @@ export const WysiwygComposer = memo(function WysiwygComposer(
|
||||||
const { isFocused, onFocus } = useIsFocused();
|
const { isFocused, onFocus } = useIsFocused();
|
||||||
const computedPlaceholder = !content && placeholder || undefined;
|
const computedPlaceholder = !content && placeholder || undefined;
|
||||||
|
|
||||||
const rightComp = (selectPreviousSelection: () => void) => rightComponent(wysiwyg, selectPreviousSelection);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div data-testid="WysiwygComposer" className={classNames(className, { [`${className}-focused`]: isFocused })} onFocus={onFocus} onBlur={onFocus}>
|
<div data-testid="WysiwygComposer" className={classNames(className, { [`${className}-focused`]: isFocused })} onFocus={onFocus} onBlur={onFocus}>
|
||||||
<FormattingButtons composer={wysiwyg} actionStates={actionStates} />
|
<FormattingButtons composer={wysiwyg} actionStates={actionStates} />
|
||||||
<Editor ref={ref} disabled={!isReady} leftComponent={leftComponent} rightComponent={rightComp} placeholder={computedPlaceholder} />
|
<Editor ref={ref} disabled={!isReady} leftComponent={leftComponent} rightComponent={rightComponent} placeholder={computedPlaceholder} />
|
||||||
{ children?.(ref, wysiwyg) }
|
{ children?.(ref, wysiwyg) }
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -23,6 +23,7 @@ import { TimelineRenderingType, useRoomContext } from "../../../../../contexts/R
|
||||||
import { useDispatcher } from "../../../../../hooks/useDispatcher";
|
import { useDispatcher } from "../../../../../hooks/useDispatcher";
|
||||||
import { focusComposer } from "./utils";
|
import { focusComposer } from "./utils";
|
||||||
import { ComposerFunctions } from "../types";
|
import { ComposerFunctions } from "../types";
|
||||||
|
import { ComposerType } from "../../../../../dispatcher/payloads/ComposerInsertPayload";
|
||||||
|
|
||||||
export function useWysiwygSendActionHandler(
|
export function useWysiwygSendActionHandler(
|
||||||
disabled: boolean,
|
disabled: boolean,
|
||||||
|
@ -48,7 +49,18 @@ export function useWysiwygSendActionHandler(
|
||||||
composerFunctions.clear();
|
composerFunctions.clear();
|
||||||
focusComposer(composerElement, context, roomContext, timeoutId);
|
focusComposer(composerElement, context, roomContext, timeoutId);
|
||||||
break;
|
break;
|
||||||
// TODO: case Action.ComposerInsert: - see SendMessageComposer
|
case Action.ComposerInsert:
|
||||||
|
if (payload.timelineRenderingType !== roomContext.timelineRenderingType) break;
|
||||||
|
if (payload.composerType !== ComposerType.Send) break;
|
||||||
|
|
||||||
|
if (payload.userId) {
|
||||||
|
// TODO insert mention - see SendMessageComposer
|
||||||
|
} else if (payload.event) {
|
||||||
|
// TODO insert quote message - see SendMessageComposer
|
||||||
|
} else if (payload.text) {
|
||||||
|
composerFunctions.insertText(payload.text);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}, [disabled, composerElement, composerFunctions, timeoutId, roomContext]);
|
}, [disabled, composerElement, composerFunctions, timeoutId, roomContext]);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue