Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3396433
D4677.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D4677.diff
View Options
diff --git a/lib/shared/relationship-utils.js b/lib/shared/relationship-utils.js
--- a/lib/shared/relationship-utils.js
+++ b/lib/shared/relationship-utils.js
@@ -1,10 +1,14 @@
// @flow
+import invariant from 'invariant';
+
import {
type RelationshipButton,
type UserRelationshipStatus,
userRelationshipStatus,
relationshipButtons,
+ relationshipActions,
+ type RelationshipAction,
} from '../types/relationship-types';
import type { UserInfo } from '../types/user-types';
@@ -51,8 +55,31 @@
);
}
+function getRelationshipDispatchAction(
+ relationshipButton: RelationshipButton,
+): RelationshipAction {
+ if (relationshipButton === relationshipButtons.BLOCK) {
+ return relationshipActions.BLOCK;
+ } else if (
+ relationshipButton === relationshipButtons.FRIEND ||
+ relationshipButton === relationshipButtons.ACCEPT
+ ) {
+ return relationshipActions.FRIEND;
+ } else if (
+ relationshipButton === relationshipButtons.UNFRIEND ||
+ relationshipButton === relationshipButtons.REJECT ||
+ relationshipButton === relationshipButtons.WITHDRAW
+ ) {
+ return relationshipActions.UNFRIEND;
+ } else if (relationshipButton === relationshipButtons.UNBLOCK) {
+ return relationshipActions.UNBLOCK;
+ }
+ invariant(false, 'relationshipButton conditions should be exhaustive');
+}
+
export {
sortIDs,
getAvailableRelationshipButtons,
relationshipBlockedInEitherDirection,
+ getRelationshipDispatchAction,
};
diff --git a/native/chat/settings/thread-settings-edit-relationship.react.js b/native/chat/settings/thread-settings-edit-relationship.react.js
--- a/native/chat/settings/thread-settings-edit-relationship.react.js
+++ b/native/chat/settings/thread-settings-edit-relationship.react.js
@@ -8,12 +8,12 @@
updateRelationships as serverUpdateRelationships,
updateRelationshipsActionTypes,
} from 'lib/actions/relationship-actions';
+import { getRelationshipDispatchAction } from 'lib/shared/relationship-utils';
import { getSingleOtherUser } from 'lib/shared/thread-utils';
import {
type RelationshipAction,
type RelationshipButton,
relationshipButtons,
- relationshipActions,
} from 'lib/types/relationship-types';
import type { ThreadInfo } from 'lib/types/thread-types';
import {
@@ -63,25 +63,10 @@
);
const { relationshipButton } = props;
- const relationshipAction = React.useMemo(() => {
- if (relationshipButton === relationshipButtons.BLOCK) {
- return relationshipActions.BLOCK;
- } else if (
- relationshipButton === relationshipButtons.FRIEND ||
- relationshipButton === relationshipButtons.ACCEPT
- ) {
- return relationshipActions.FRIEND;
- } else if (
- relationshipButton === relationshipButtons.UNFRIEND ||
- relationshipButton === relationshipButtons.REJECT ||
- relationshipButton === relationshipButtons.WITHDRAW
- ) {
- return relationshipActions.UNFRIEND;
- } else if (relationshipButton === relationshipButtons.UNBLOCK) {
- return relationshipActions.UNBLOCK;
- }
- invariant(false, 'relationshipButton conditions should be exhaustive');
- }, [relationshipButton]);
+ const relationshipAction = React.useMemo(
+ () => getRelationshipDispatchAction(relationshipButton),
+ [relationshipButton],
+ );
const dispatchActionPromise = useDispatchActionPromise();
const onButtonPress = React.useCallback(() => {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 2, 12:19 PM (19 h, 36 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2607574
Default Alt Text
D4677.diff (3 KB)
Attached To
Mode
D4677: [lib] Introduce shared `getRelationshipDispatchAction` function
Attached
Detach File
Event Timeline
Log In to Comment