Skip to content

Commit 3885636

Browse files
gnpricechrisbobbe
authored andcommitted
StreamItem [nfc]: Extract ancillary buttons' JSX as locals
1 parent 99a07cb commit 3885636

File tree

1 file changed

+45
-44
lines changed

1 file changed

+45
-44
lines changed

src/streams/StreamItem.js

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,49 @@ export default function StreamItem(props: Props): Node {
159159
[backgroundColor, handleExpandCollapse, isMuted, textColor],
160160
);
161161

162+
const collapseButton = handleExpandCollapse && (
163+
<Pressable style={styles.collapsePressable} onPress={() => handleExpandCollapse(streamId)}>
164+
{isCollapsed === false ? (
165+
<IconCaretUp style={styles.collapseIcon} size={20} color={iconColor} />
166+
) : (
167+
<IconCaretDown style={styles.collapseIcon} size={20} color={iconColor} />
168+
)}
169+
</Pressable>
170+
);
171+
172+
let subscribeButton = null;
173+
if (offersSubscribeButton) {
174+
const disabled = !isSubscribed && isPrivate;
175+
subscribeButton = (
176+
<Pressable
177+
onPress={() => {
178+
if (onSubscribeButtonPressed) {
179+
if (disabled) {
180+
showErrorAlert(
181+
_('Cannot subscribe to stream'),
182+
_('Stream #{name} is private.', { name }),
183+
{ url: new URL('/help/stream-permissions', realmUrl), globalSettings },
184+
);
185+
return;
186+
}
187+
188+
onSubscribeButtonPressed({ stream_id: streamId, name }, !isSubscribed);
189+
}
190+
}}
191+
hitSlop={12}
192+
style={{ opacity: disabled ? 0.1 : 1 }}
193+
>
194+
{({ pressed }) =>
195+
isSubscribed ? (
196+
<IconDone size={24} color={pressed ? HIGHLIGHT_COLOR : BRAND_COLOR} />
197+
) : (
198+
<IconPlus size={24} color={pressed ? HALF_COLOR : iconColor} />
199+
)
200+
}
201+
</Pressable>
202+
);
203+
}
204+
162205
return (
163206
<Touchable
164207
onPress={() => onPress({ stream_id: streamId, name })}
@@ -172,18 +215,7 @@ export default function StreamItem(props: Props): Node {
172215
}}
173216
>
174217
<View style={styles.wrapper}>
175-
{handleExpandCollapse && (
176-
<Pressable
177-
style={styles.collapsePressable}
178-
onPress={() => handleExpandCollapse(streamId)}
179-
>
180-
{isCollapsed === false ? (
181-
<IconCaretUp style={styles.collapseIcon} size={20} color={iconColor} />
182-
) : (
183-
<IconCaretDown style={styles.collapseIcon} size={20} color={iconColor} />
184-
)}
185-
</Pressable>
186-
)}
218+
{collapseButton}
187219
<StreamIcon
188220
size={iconSize}
189221
color={iconColor}
@@ -203,38 +235,7 @@ export default function StreamItem(props: Props): Node {
203235
)}
204236
</View>
205237
<UnreadCount color={iconColor} count={unreadCount} />
206-
{offersSubscribeButton
207-
&& (() => {
208-
const disabled = !isSubscribed && isPrivate;
209-
return (
210-
<Pressable
211-
onPress={() => {
212-
if (onSubscribeButtonPressed) {
213-
if (disabled) {
214-
showErrorAlert(
215-
_('Cannot subscribe to stream'),
216-
_('Stream #{name} is private.', { name }),
217-
{ url: new URL('/help/stream-permissions', realmUrl), globalSettings },
218-
);
219-
return;
220-
}
221-
222-
onSubscribeButtonPressed({ stream_id: streamId, name }, !isSubscribed);
223-
}
224-
}}
225-
hitSlop={12}
226-
style={{ opacity: disabled ? 0.1 : 1 }}
227-
>
228-
{({ pressed }) =>
229-
isSubscribed ? (
230-
<IconDone size={24} color={pressed ? HIGHLIGHT_COLOR : BRAND_COLOR} />
231-
) : (
232-
<IconPlus size={24} color={pressed ? HALF_COLOR : iconColor} />
233-
)
234-
}
235-
</Pressable>
236-
);
237-
})()}
238+
{subscribeButton}
238239
</View>
239240
</Touchable>
240241
);

0 commit comments

Comments
 (0)