diff options
author | Hailey <153161762+haileyok@users.noreply.github.com> | 2024-01-30 17:54:29 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-30 17:54:29 -0800 |
commit | 28455f49dcb5ed2aa2b3d728ae3114e5c1cf7ebb (patch) | |
tree | eabbd3caf911978714cc8c441f490f6fa2143579 | |
parent | faf48db67971eb135e8997093255ed7ac8016304 (diff) | |
download | voidsky-28455f49dcb5ed2aa2b3d728ae3114e5c1cf7ebb.tar.zst |
prevent duplicate keys in feed tab bar (#2666)
-rw-r--r-- | src/view/com/pager/FeedsTabBar.web.tsx | 20 | ||||
-rw-r--r-- | src/view/com/pager/FeedsTabBarMobile.tsx | 20 | ||||
-rw-r--r-- | src/view/com/pager/TabBar.tsx | 2 |
3 files changed, 27 insertions, 15 deletions
diff --git a/src/view/com/pager/FeedsTabBar.web.tsx b/src/view/com/pager/FeedsTabBar.web.tsx index 385da5544..9fe03b7e9 100644 --- a/src/view/com/pager/FeedsTabBar.web.tsx +++ b/src/view/com/pager/FeedsTabBar.web.tsx @@ -88,11 +88,17 @@ function FeedsTabBarTablet( const navigation = useNavigation<NavigationProp>() const {headerMinimalShellTransform} = useMinimalShellMode() const {headerHeight} = useShellLayout() - const pinnedDisplayNames = hasSession ? feeds.map(f => f.displayName) : [] - const showFeedsLinkInTabBar = hasSession && !hasPinnedCustom - const items = showFeedsLinkInTabBar - ? pinnedDisplayNames.concat('Feeds ✨') - : pinnedDisplayNames + + const items = React.useMemo(() => { + if (!hasSession) return [] + + const pinnedNames = feeds.map(f => f.displayName) + + if (!hasPinnedCustom) { + return pinnedNames.concat('Feeds ✨') + } + return pinnedNames + }, [hasSession, hasPinnedCustom, feeds]) const onPressDiscoverFeeds = React.useCallback(() => { if (isWeb) { @@ -105,13 +111,13 @@ function FeedsTabBarTablet( const onSelect = React.useCallback( (index: number) => { - if (showFeedsLinkInTabBar && index === items.length - 1) { + if (hasSession && !hasPinnedCustom && index === items.length - 1) { onPressDiscoverFeeds() } else if (props.onSelect) { props.onSelect(index) } }, - [items.length, onPressDiscoverFeeds, props, showFeedsLinkInTabBar], + [items.length, onPressDiscoverFeeds, props, hasSession, hasPinnedCustom], ) return ( diff --git a/src/view/com/pager/FeedsTabBarMobile.tsx b/src/view/com/pager/FeedsTabBarMobile.tsx index b9959a6d9..4eba241ae 100644 --- a/src/view/com/pager/FeedsTabBarMobile.tsx +++ b/src/view/com/pager/FeedsTabBarMobile.tsx @@ -36,11 +36,17 @@ export function FeedsTabBar( const {feeds, hasPinnedCustom} = usePinnedFeedsInfos() const {headerHeight} = useShellLayout() const {headerMinimalShellTransform} = useMinimalShellMode() - const pinnedDisplayNames = hasSession ? feeds.map(f => f.displayName) : [] - const showFeedsLinkInTabBar = hasSession && !hasPinnedCustom - const items = showFeedsLinkInTabBar - ? pinnedDisplayNames.concat('Feeds ✨') - : pinnedDisplayNames + + const items = React.useMemo(() => { + if (!hasSession) return [] + + const pinnedNames = feeds.map(f => f.displayName) + + if (!hasPinnedCustom) { + return pinnedNames.concat('Feeds ✨') + } + return pinnedNames + }, [hasSession, hasPinnedCustom, feeds]) const onPressFeedsLink = React.useCallback(() => { if (isWeb) { @@ -53,13 +59,13 @@ export function FeedsTabBar( const onSelect = React.useCallback( (index: number) => { - if (showFeedsLinkInTabBar && index === items.length - 1) { + if (hasSession && !hasPinnedCustom && index === items.length - 1) { onPressFeedsLink() } else if (props.onSelect) { props.onSelect(index) } }, - [items.length, onPressFeedsLink, props, showFeedsLinkInTabBar], + [items.length, onPressFeedsLink, props, hasSession, hasPinnedCustom], ) const onPressAvi = React.useCallback(() => { diff --git a/src/view/com/pager/TabBar.tsx b/src/view/com/pager/TabBar.tsx index c3a95c5c0..dadcfcebd 100644 --- a/src/view/com/pager/TabBar.tsx +++ b/src/view/com/pager/TabBar.tsx @@ -78,7 +78,7 @@ export function TabBar({ return ( <PressableWithHover testID={`${testID}-selector-${i}`} - key={item} + key={`${item}-${i}`} onLayout={e => onItemLayout(e, i)} style={[styles.item, selected && indicatorStyle]} hoverStyle={pal.viewLight} |