Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3375125
D6055.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D6055.diff
View Options
diff --git a/web/chat/reaction-message-utils.js b/web/chat/reaction-message-utils.js
new file mode 100644
--- /dev/null
+++ b/web/chat/reaction-message-utils.js
@@ -0,0 +1,77 @@
+// @flow
+
+import * as React from 'react';
+
+import {
+ sendReactionMessage,
+ sendReactionMessageActionTypes,
+} from 'lib/actions/message-actions';
+import { useModalContext } from 'lib/components/modal-provider.react';
+import {
+ useDispatchActionPromise,
+ useServerCall,
+} from 'lib/utils/action-utils';
+
+import Alert from '../modals/alert.react';
+
+function useOnClickReact(
+ messageID: ?string,
+ threadID: string,
+ reaction: string,
+ action: 'add_reaction' | 'remove_reaction',
+): (event: SyntheticEvent<HTMLElement>) => void {
+ const { pushModal } = useModalContext();
+
+ const callSendReactionMessage = useServerCall(sendReactionMessage);
+ const dispatchActionPromise = useDispatchActionPromise();
+
+ return React.useCallback(
+ (event: SyntheticEvent<HTMLElement>) => {
+ event.preventDefault();
+
+ if (!messageID) {
+ return;
+ }
+
+ const reactionMessagePromise = (async () => {
+ try {
+ const result = await callSendReactionMessage({
+ threadID,
+ targetMessageID: messageID,
+ reaction,
+ action,
+ });
+ return {
+ serverID: result.id,
+ threadID,
+ time: result.newMessageInfo.time,
+ newMessageInfos: [result.newMessageInfo],
+ };
+ } catch (e) {
+ pushModal(
+ <Alert title="Couldn’t send the reaction">
+ Please try again later
+ </Alert>,
+ );
+ throw e;
+ }
+ })();
+
+ dispatchActionPromise(
+ sendReactionMessageActionTypes,
+ reactionMessagePromise,
+ );
+ },
+ [
+ action,
+ callSendReactionMessage,
+ dispatchActionPromise,
+ messageID,
+ pushModal,
+ reaction,
+ threadID,
+ ],
+ );
+}
+
+export { useOnClickReact };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 27, 6:27 PM (21 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2591326
Default Alt Text
D6055.diff (2 KB)
Attached To
Mode
D6055: [web] introduce useOnClickReact hook in reaction message utils
Attached
Detach File
Event Timeline
Log In to Comment