Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32218276
D6055.1765179246.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D6055.1765179246.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
Mon, Dec 8, 7:34 AM (10 h, 19 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5847465
Default Alt Text
D6055.1765179246.diff (2 KB)
Attached To
Mode
D6055: [web] introduce useOnClickReact hook in reaction message utils
Attached
Detach File
Event Timeline
Log In to Comment