Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32188374
D4678.1765088698.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D4678.1765088698.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
@@ -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
Details
Attached
Mime Type
text/plain
Expires
Sun, Dec 7, 6:24 AM (16 h, 10 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5842852
Default Alt Text
D4678.1765088698.diff (3 KB)
Attached To
Mode
D4678: [lib] Introduce shared `getRelationshipActionText` function
Attached
Detach File
Event Timeline
Log In to Comment