Skip to content

Commit 3f5e62c

Browse files
authored
Merge pull request #88944 from callstack-internal/decompose/composer-pr6-suggestions-and-memo
ReportActionCompose 6/6: compound API + strip memo from Suggestions
2 parents 313ac27 + d95699b commit 3f5e62c

2 files changed

Lines changed: 45 additions & 33 deletions

File tree

src/pages/inbox/report/ReportActionCompose/ReportActionCompose.tsx

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type ReportActionComposeProps = {
2626
reportID: string;
2727
};
2828

29-
function ReportActionComposeInner({reportID}: ReportActionComposeProps) {
29+
function ComposerInner({reportID}: ReportActionComposeProps) {
3030
const styles = useThemeStyles();
3131
const {shouldUseNarrowLayout} = useResponsiveLayout();
3232
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`);
@@ -39,41 +39,53 @@ function ReportActionComposeInner({reportID}: ReportActionComposeProps) {
3939

4040
return (
4141
<View style={[isComposerFullSize && styles.chatItemFullComposeRow]}>
42-
<ComposerLocalTime reportID={reportID} />
42+
<Composer.LocalTime reportID={reportID} />
4343
<View style={isComposerFullSize ? styles.flex1 : {}}>
4444
<OfflineWithFeedback
4545
shouldDisableOpacity
4646
pendingAction={pendingAction}
4747
style={isComposerFullSize ? styles.chatItemFullComposeRow : {}}
4848
contentContainerStyle={isComposerFullSize ? styles.flex1 : {}}
4949
>
50-
<ComposerDropZone reportID={reportID}>
51-
<ComposerBox reportID={reportID}>
52-
<ComposerActionMenu reportID={reportID} />
53-
<ComposerInput reportID={reportID} />
54-
<ComposerEmojiPicker reportID={reportID} />
55-
<ComposerSendButton />
56-
</ComposerBox>
57-
</ComposerDropZone>
58-
<ComposerFooter>
50+
<Composer.DropZone reportID={reportID}>
51+
<Composer.Box reportID={reportID}>
52+
<Composer.ActionMenu reportID={reportID} />
53+
<Composer.Input reportID={reportID} />
54+
<Composer.EmojiPicker reportID={reportID} />
55+
<Composer.SendButton />
56+
</Composer.Box>
57+
</Composer.DropZone>
58+
<Composer.Footer>
5959
{!shouldUseNarrowLayout && <OfflineIndicator containerStyles={[styles.chatItemComposeSecondaryRow]} />}
60-
<AgentZeroAwareTypingIndicator reportID={reportID} />
61-
<ComposerExceededLength />
62-
</ComposerFooter>
60+
<Composer.TypingIndicator reportID={reportID} />
61+
<Composer.ExceededLength />
62+
</Composer.Footer>
6363
</OfflineWithFeedback>
64-
<ComposerImportedState />
64+
<Composer.ImportedState />
6565
</View>
6666
</View>
6767
);
6868
}
6969

70-
function ReportActionCompose({reportID}: ReportActionComposeProps) {
70+
function Composer({reportID}: ReportActionComposeProps) {
7171
return (
7272
<ComposerProvider reportID={reportID}>
73-
<ReportActionComposeInner reportID={reportID} />
73+
<ComposerInner reportID={reportID} />
7474
</ComposerProvider>
7575
);
7676
}
7777

78-
export default ReportActionCompose;
78+
Composer.LocalTime = ComposerLocalTime;
79+
Composer.DropZone = ComposerDropZone;
80+
Composer.Box = ComposerBox;
81+
Composer.ActionMenu = ComposerActionMenu;
82+
Composer.Input = ComposerInput;
83+
Composer.EmojiPicker = ComposerEmojiPicker;
84+
Composer.SendButton = ComposerSendButton;
85+
Composer.Footer = ComposerFooter;
86+
Composer.TypingIndicator = AgentZeroAwareTypingIndicator;
87+
Composer.ExceededLength = ComposerExceededLength;
88+
Composer.ImportedState = ComposerImportedState;
89+
90+
export default Composer;
7991
export type {SuggestionsRef, ComposerRef, ReportActionComposeProps};

src/pages/inbox/report/ReportActionCompose/Suggestions.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type {ForwardedRef} from 'react';
2-
import React, {useCallback, useEffect, useImperativeHandle, useRef} from 'react';
2+
import React, {useEffect, useImperativeHandle, useRef} from 'react';
33
import type {TextInputSelectionChangeEvent} from 'react-native';
44
import {View} from 'react-native';
55
import type {MeasureParentContainerAndCursorCallback} from '@components/AutoCompleteSuggestions/types';
@@ -71,7 +71,7 @@ function Suggestions({
7171
const {isDraggingOver} = useDragAndDropState();
7272
const prevIsDraggingOver = usePrevious(isDraggingOver);
7373

74-
const getSuggestions = useCallback(() => {
74+
const getSuggestions = () => {
7575
if (suggestionEmojiRef.current?.getSuggestions) {
7676
const emojiSuggestions = suggestionEmojiRef.current.getSuggestions();
7777
if (emojiSuggestions.length > 0) {
@@ -87,45 +87,45 @@ function Suggestions({
8787
}
8888

8989
return [];
90-
}, []);
90+
};
9191

9292
/**
9393
* Clean data related to EmojiSuggestions
9494
*/
95-
const resetSuggestions = useCallback(() => {
95+
const resetSuggestions = () => {
9696
suggestionEmojiRef.current?.resetSuggestions();
9797
suggestionMentionRef.current?.resetSuggestions();
98-
}, []);
98+
};
9999

100100
/**
101101
* Listens for keyboard shortcuts and applies the action
102102
*/
103-
const triggerHotkeyActions = useCallback((e: KeyboardEvent) => {
103+
const triggerHotkeyActions = (e: KeyboardEvent) => {
104104
const emojiHandler = suggestionEmojiRef.current?.triggerHotkeyActions(e);
105105
const mentionHandler = suggestionMentionRef.current?.triggerHotkeyActions(e);
106106
return emojiHandler ?? mentionHandler;
107-
}, []);
107+
};
108108

109-
const onSelectionChange = useCallback((e: TextInputSelectionChangeEvent) => {
109+
const onSelectionChange = (e: TextInputSelectionChangeEvent) => {
110110
const emojiHandler = suggestionEmojiRef.current?.onSelectionChange?.(e);
111111
suggestionMentionRef.current?.onSelectionChange?.(e);
112112
return emojiHandler;
113-
}, []);
113+
};
114114

115-
const updateShouldShowSuggestionMenuToFalse = useCallback(() => {
115+
const updateShouldShowSuggestionMenuToFalse = () => {
116116
suggestionEmojiRef.current?.updateShouldShowSuggestionMenuToFalse();
117117
suggestionMentionRef.current?.updateShouldShowSuggestionMenuToFalse();
118-
}, []);
118+
};
119119

120-
const setShouldBlockSuggestionCalc = useCallback((shouldBlock: boolean) => {
120+
const setShouldBlockSuggestionCalc = (shouldBlock: boolean) => {
121121
suggestionEmojiRef.current?.setShouldBlockSuggestionCalc(shouldBlock);
122122
suggestionMentionRef.current?.setShouldBlockSuggestionCalc(shouldBlock);
123-
}, []);
124-
const getIsSuggestionsMenuVisible = useCallback((): boolean => {
123+
};
124+
const getIsSuggestionsMenuVisible = (): boolean => {
125125
const isEmojiVisible = suggestionEmojiRef.current?.getIsSuggestionsMenuVisible() ?? false;
126126
const isSuggestionVisible = suggestionMentionRef.current?.getIsSuggestionsMenuVisible() ?? false;
127127
return isEmojiVisible || isSuggestionVisible;
128-
}, []);
128+
};
129129

130130
useImperativeHandle(
131131
ref,

0 commit comments

Comments
 (0)