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: Refactor Composer Dropdown #27931

Merged
merged 10 commits into from
Feb 9, 2023
39 changes: 0 additions & 39 deletions apps/meteor/app/discussion/client/discussionFromMessageBox.js

This file was deleted.

1 change: 0 additions & 1 deletion apps/meteor/app/discussion/client/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Other UI extensions
import './lib/messageTypes/discussionMessage';
import './createDiscussionMessageAction';
import './discussionFromMessageBox';
import './tabBar';
6 changes: 2 additions & 4 deletions apps/meteor/app/ui-message/client/actionButtons/messageBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ import { Utilities } from '../../../apps/lib/misc/Utilities';

const getIdForActionButton = ({ appId, actionId }: IUIActionButton): string => `${appId}/${actionId}`;

const APP_GROUP = 'Create_new';

export const onAdded = (button: IUIActionButton): void =>
// eslint-disable-next-line no-void
void messageBox.actions.add(APP_GROUP, t(Utilities.getI18nKeyForApp(button.labelI18n, button.appId)) as TranslationKey, {
void messageBox.actions.add('Apps', t(Utilities.getI18nKeyForApp(button.labelI18n, button.appId)) as TranslationKey, {
id: getIdForActionButton(button),
// icon: button.icon || '',
condition() {
Expand All @@ -33,4 +31,4 @@ export const onAdded = (button: IUIActionButton): void =>

export const onRemoved = (button: IUIActionButton): void =>
// eslint-disable-next-line no-void
void messageBox.actions.remove(APP_GROUP, new RegExp(getIdForActionButton(button)));
void messageBox.actions.remove('Apps', new RegExp(getIdForActionButton(button)));
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import $ from 'jquery';

import { withDebouncing } from '../../../../lib/utils/highOrderFunctions';
import type { ComposerAPI } from '../../../../client/lib/chats/ChatAPI';
import './messageBoxActions';
import type { FormattingButton } from './messageBoxFormatting';
import { formattingButtons } from './messageBoxFormatting';

Expand Down
2 changes: 0 additions & 2 deletions apps/meteor/app/ui-message/client/messageBox/messageBox.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import './messageBoxActions';

const lastFocusedInput: HTMLTextAreaElement | undefined = undefined;

export const refocusComposer = () => {
Expand Down
92 changes: 0 additions & 92 deletions apps/meteor/app/ui-message/client/messageBox/messageBoxActions.ts

This file was deleted.

1 change: 0 additions & 1 deletion apps/meteor/app/webdav/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Meteor.startup(() => {
return;
}
c.stop();
import('./startup/messageBoxActions');
import('./startup/sync');
import('./actionButton');
});
Expand Down
55 changes: 0 additions & 55 deletions apps/meteor/app/webdav/client/startup/messageBoxActions.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type CreateDiscussionFormValues = {
};

type CreateDiscussionProps = {
parentMessageId: IMessage['_id'];
parentMessageId?: IMessage['_id'];
onClose: () => void;
defaultParentRoom?: IRoom['_id'];
nameSuggestion?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ const audioRecorder = new AudioRecorder();
type AudioMessageRecorderProps = {
rid: IRoom['_id'];
tmid?: IMessage['_id'];
isRecording?: boolean;
chatContext?: ChatAPI; // TODO: remove this when the composer is migrated to React
} & Omit<AllHTMLAttributes<HTMLDivElement>, 'is'>;

const AudioMessageRecorder = ({ rid, chatContext, ...props }: AudioMessageRecorderProps): ReactElement | null => {
const AudioMessageRecorder = ({ rid, chatContext, isRecording, ...props }: AudioMessageRecorderProps): ReactElement | null => {
const t = useTranslation();

const [state, setState] = useState<'idle' | 'loading' | 'recording'>('idle');
Expand Down Expand Up @@ -167,6 +168,7 @@ const AudioMessageRecorder = ({ rid, chatContext, ...props }: AudioMessageRecord
if (state === 'idle') {
return (
<MessageComposerAction
disabled={isRecording}
title={t('Audio_message')}
icon='mic'
className='rc-message-box__icon rc-message-box__audio-message-mic'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { EmojiPicker } from '../../../../../../../app/emoji/client';
import { createComposerAPI } from '../../../../../../../app/ui-message/client/messageBox/createComposerAPI';
import type { FormattingButton } from '../../../../../../../app/ui-message/client/messageBox/messageBoxFormatting';
import { formattingButtons } from '../../../../../../../app/ui-message/client/messageBox/messageBoxFormatting';
import { messageBox, popover } from '../../../../../../../app/ui-utils/client';
import { getImageExtensionFromMime } from '../../../../../../../lib/getImageExtensionFromMime';
import { useFormatDateAndTime } from '../../../../../../hooks/useFormatDateAndTime';
import { useReactiveValue } from '../../../../../../hooks/useReactiveValue';
Expand All @@ -42,8 +41,11 @@ import { useChat } from '../../../../contexts/ChatContext';
import BlazeTemplate from '../../../BlazeTemplate';
import ComposerUserActionIndicator from '../ComposerUserActionIndicator';
import { useAutoGrow } from '../RoomComposer/hooks/useAutoGrow';
import MessageBoxDropdown from './MessageBoxDropdown';
import MessageBoxFormattingToolbar from './MessageBoxFormattingToolbar';
import MessageBoxReplies from './MessageBoxReplies';
import FileUploadAction from './actions/FileUploadAction';
import VideoMessageAction from './actions/VideoMessageAction';

const reducer = (_: unknown, event: FormEvent<HTMLInputElement>): boolean => {
const target = event.target as HTMLInputElement;
Expand Down Expand Up @@ -108,7 +110,6 @@ const MessageBox = ({
onUploadFiles,
onEscape,
onTyping,
subscription,
readOnly,
tshow,
}: MessageBoxProps): ReactElement => {
Expand Down Expand Up @@ -255,7 +256,7 @@ const MessageBox = ({
subscribe: chat.composer?.editing.subscribe ?? emptySubscribe,
});

const isRecording = useSubscription({
const isRecordingAudio = useSubscription({
getCurrentValue: chat.composer?.recording.get ?? getEmptyFalse,
subscribe: chat.composer?.recording.subscribe ?? emptySubscribe,
});
Expand Down Expand Up @@ -320,6 +321,10 @@ const MessageBox = ({
}
});

const isRecording = isRecordingAudio || isRecordingVideo;

console.log(isRecordingVideo);

return (
<>
{chat?.composer?.quotedMessages && <MessageBoxReplies />}
Expand Down Expand Up @@ -358,48 +363,10 @@ const MessageBox = ({
/>
)}
<MessageComposerActionsDivider />
<AudioMessageRecorder rid={rid} tmid={tmid} disabled={!canSend || typing} />
<MessageComposerAction
disabled={isRecording}
onClick={(event): void => {
const groups = messageBox.actions.get();
const config = {
popoverClass: 'message-box',
columns: [
{
groups: Object.entries(groups).map(([name, group]) => {
const items = group.map((item) => ({
icon: item.icon,
name: t(item.label),
type: 'messagebox-action',
id: item.id,
action: item.action,
}));
return {
title: t.has(name) && t(name),
items,
};
}),
},
],
offsetVertical: 10,
direction: 'top-inverted',
currentTarget: event.currentTarget,
data: {
rid,
tmid,
prid: subscription?.prid,
messageBox: textareaRef.current,
chat,
},
activeElement: event.currentTarget,
};

popover.open(config);
}}
icon='plus'
data-qa-id='menu-more-actions'
/>
<VideoMessageAction isRecording={isRecordingAudio} />
<AudioMessageRecorder rid={rid} tmid={tmid} disabled={!canSend || typing || isRecordingVideo} />
<FileUploadAction isRecording={isRecording} />
<MessageBoxDropdown isRecording={isRecording} rid={rid} tmid={tmid} />
</MessageComposerToolbarActions>
<MessageComposerToolbarSubmit>
{!canSend && (
Expand Down
Loading