Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3351370
D7143.id24275.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D7143.id24275.diff
View Options
diff --git a/lib/shared/edit-messages-utils.js b/lib/shared/edit-messages-utils.js
--- a/lib/shared/edit-messages-utils.js
+++ b/lib/shared/edit-messages-utils.js
@@ -1,14 +1,54 @@
// @flow
+import invariant from 'invariant';
+import * as React from 'react';
+
import { threadHasPermission } from './thread-utils.js';
-import { messageTypes } from '../types/message-types.js';
+import {
+ sendEditMessageActionTypes,
+ sendEditMessage,
+} from '../actions/message-actions.js';
import type {
+ SendEditMessageResult,
RobotextMessageInfo,
ComposableMessageInfo,
-} from '../types/message-types.js';
+} from '../types/message-types';
+import { messageTypes } from '../types/message-types.js';
import { threadPermissions, type ThreadInfo } from '../types/thread-types.js';
+import {
+ useDispatchActionPromise,
+ useServerCall,
+} from '../utils/action-utils.js';
import { useSelector } from '../utils/redux-utils.js';
+function useEditMessage(
+ messageID?: string,
+): (newText: string) => Promise<SendEditMessageResult> {
+ const callEditMessage = useServerCall(sendEditMessage);
+ const dispatchActionPromise = useDispatchActionPromise();
+
+ return React.useCallback(
+ newText => {
+ invariant(messageID, 'messageID should be set!');
+
+ const editMessagePromise = (async () => {
+ const result = await callEditMessage({
+ targetMessageID: messageID,
+ text: newText,
+ });
+ return {
+ newMessageInfos: result.newMessageInfos,
+ };
+ })();
+
+ dispatchActionPromise(sendEditMessageActionTypes, editMessagePromise);
+
+ return editMessagePromise;
+ },
+ [messageID, dispatchActionPromise, callEditMessage],
+ );
+}
+
function useCanEditMessage(
threadInfo: ThreadInfo,
targetMessageInfo: ComposableMessageInfo | RobotextMessageInfo,
@@ -36,4 +76,4 @@
return hasPermission;
}
-export { useCanEditMessage };
+export { useCanEditMessage, useEditMessage };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 1:16 AM (20 h, 24 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2572450
Default Alt Text
D7143.id24275.diff (1 KB)
Attached To
Mode
D7143: [lib] Function to dispatch edit message action
Attached
Detach File
Event Timeline
Log In to Comment