Page MenuHomePhabricator

D4678.diff
No OneTemporary

D4678.diff

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
@@ -77,9 +77,34 @@
invariant(false, 'relationshipButton conditions should be exhaustive');
}
+function getRelationshipActionText(
+ relationshipButton: RelationshipButton,
+ username: string,
+): string {
+ switch (relationshipButton) {
+ case relationshipButtons.BLOCK:
+ return `Block ${username}`;
+ case relationshipButtons.FRIEND:
+ return `Add ${username} to friends`;
+ case relationshipButtons.UNFRIEND:
+ return `Unfriend ${username}`;
+ case relationshipButtons.UNBLOCK:
+ return `Unblock ${username}`;
+ case relationshipButtons.ACCEPT:
+ return `Accept friend request from ${username}`;
+ case relationshipButtons.REJECT:
+ return `Reject friend request from ${username}`;
+ case relationshipButtons.WITHDRAW:
+ return `Withdraw request to friend ${username}`;
+ default:
+ invariant(false, 'invalid relationshipButton value');
+ }
+}
+
export {
sortIDs,
getAvailableRelationshipButtons,
relationshipBlockedInEitherDirection,
getRelationshipDispatchAction,
+ getRelationshipActionText,
};
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,14 @@
updateRelationships as serverUpdateRelationships,
updateRelationshipsActionTypes,
} from 'lib/actions/relationship-actions';
-import { getRelationshipDispatchAction } from 'lib/shared/relationship-utils';
+import {
+ getRelationshipActionText,
+ getRelationshipDispatchAction,
+} from 'lib/shared/relationship-utils';
import { getSingleOtherUser } from 'lib/shared/thread-utils';
import {
type RelationshipAction,
type RelationshipButton,
- relationshipButtons,
} from 'lib/types/relationship-types';
import type { ThreadInfo } from 'lib/types/thread-types';
import {
@@ -83,22 +85,11 @@
const otherUserInfoUsername = otherUserInfo.username;
invariant(otherUserInfoUsername, 'Other user username should be specified');
- let relationshipButtonText;
- if (relationshipButton === relationshipButtons.BLOCK) {
- relationshipButtonText = `Block ${otherUserInfoUsername}`;
- } else if (relationshipButton === relationshipButtons.FRIEND) {
- relationshipButtonText = `Add ${otherUserInfoUsername} to friends`;
- } else if (relationshipButton === relationshipButtons.UNFRIEND) {
- relationshipButtonText = `Unfriend ${otherUserInfoUsername}`;
- } else if (relationshipButton === relationshipButtons.UNBLOCK) {
- relationshipButtonText = `Unblock ${otherUserInfoUsername}`;
- } else if (relationshipButton === relationshipButtons.ACCEPT) {
- relationshipButtonText = `Accept friend request from ${otherUserInfoUsername}`;
- } else if (relationshipButton === relationshipButtons.REJECT) {
- relationshipButtonText = `Reject friend request from ${otherUserInfoUsername}`;
- } else if (relationshipButton === relationshipButtons.WITHDRAW) {
- relationshipButtonText = `Withdraw request to friend ${otherUserInfoUsername}`;
- }
+ const relationshipButtonText = React.useMemo(
+ () =>
+ getRelationshipActionText(relationshipButton, otherUserInfoUsername),
+ [otherUserInfoUsername, relationshipButton],
+ );
return (
<View style={styles.container}>

File Metadata

Mime Type
text/plain
Expires
Mon, Dec 2, 1:06 PM (20 h, 24 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2607663
Default Alt Text
D4678.diff (3 KB)

Event Timeline