Skip to content

Commit 9f158d5

Browse files
committed
refactor: reduced duplication of code and applied meaningful func names
1 parent c2416a7 commit 9f158d5

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

package/src/components/Message/MessageSimple/MessageContent.tsx

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -234,19 +234,17 @@ const MessageContentWithContext = <
234234

235235
const isBorderColor = isMyMessage && !error;
236236

237-
const shouldApplyBorderRadius = (firstGroupStyle: string, secondGroupStyle: string): boolean =>
237+
const isLastMessageInMessageGroup = (firstGroupStyle: string, secondGroupStyle: string) =>
238238
(groupStyle === firstGroupStyle || groupStyle === secondGroupStyle) &&
239239
(!hasThreadReplies || threadList);
240240

241-
const applyBorderRadius = (
242-
firstGroupStyle: string,
243-
secondGroupStyle: string,
244-
): number | undefined => {
245-
if (shouldApplyBorderRadius(firstGroupStyle, secondGroupStyle)) {
246-
return borderRadiusS;
247-
}
248-
return borderRadiusL;
249-
};
241+
const calculateBorderRadius = (firstGroupStyle: string, secondGroupStyle: string) =>
242+
isLastMessageInMessageGroup(firstGroupStyle, secondGroupStyle) ? borderRadiusS : borderRadiusL;
243+
244+
const getRadiusFromTheme = (
245+
radius: number | undefined,
246+
defaultValue: number | undefined = borderRadiusL,
247+
) => (radius !== undefined ? radius : defaultValue);
250248

251249
return (
252250
<TouchableOpacity
@@ -322,20 +320,18 @@ const MessageContentWithContext = <
322320
styles.containerInner,
323321
{
324322
backgroundColor,
325-
borderBottomLeftRadius:
326-
borderBottomLeftRadius !== undefined
327-
? borderBottomLeftRadius
328-
: applyBorderRadius('left_bottom', 'left_single'),
329-
borderBottomRightRadius:
330-
borderBottomRightRadius !== undefined
331-
? borderBottomRightRadius
332-
: applyBorderRadius('right_bottom', 'right_single'),
323+
borderBottomLeftRadius: getRadiusFromTheme(
324+
borderBottomLeftRadius,
325+
calculateBorderRadius('left_bottom', 'left_single'),
326+
),
327+
borderBottomRightRadius: getRadiusFromTheme(
328+
borderBottomRightRadius,
329+
calculateBorderRadius('right_bottom', 'right_single'),
330+
),
333331
borderColor: isBorderColor ? backgroundColor : grey_whisper,
334332
borderRadius,
335-
borderTopLeftRadius:
336-
borderTopLeftRadius !== undefined ? borderTopLeftRadius : borderRadiusL,
337-
borderTopRightRadius:
338-
borderTopRightRadius !== undefined ? borderTopRightRadius : borderRadiusL,
333+
borderTopLeftRadius: getRadiusFromTheme(borderTopLeftRadius),
334+
borderTopRightRadius: getRadiusFromTheme(borderTopRightRadius),
339335
},
340336
noBorder ? { borderWidth: 0 } : {},
341337
containerInner,

0 commit comments

Comments
 (0)