about summary refs log tree commit diff
path: root/src/view/com/pager/FeedsTabBar.web.tsx
blob: 57c83f17c68c42caadb6341326b367e083b3633f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import React from 'react'
import {View, StyleSheet} from 'react-native'
import Animated from 'react-native-reanimated'
import {TabBar} from 'view/com/pager/TabBar'
import {RenderTabBarFnProps} from 'view/com/pager/Pager'
import {usePalette} from 'lib/hooks/usePalette'
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
import {FeedsTabBar as FeedsTabBarMobile} from './FeedsTabBarMobile'
import {useMinimalShellMode} from 'lib/hooks/useMinimalShellMode'
import {useShellLayout} from '#/state/shell/shell-layout'
import {usePinnedFeedsInfos} from '#/state/queries/feed'
import {useSession} from '#/state/session'
import {TextLink} from '#/view/com/util/Link'
import {CenteredView} from '../util/Views'
import {isWeb} from 'platform/detection'
import {useNavigation} from '@react-navigation/native'
import {NavigationProp} from 'lib/routes/types'

export function FeedsTabBar(
  props: RenderTabBarFnProps & {testID?: string; onPressSelected: () => void},
) {
  const {isMobile, isTablet} = useWebMediaQueries()
  const {hasSession} = useSession()

  if (isMobile) {
    return <FeedsTabBarMobile {...props} />
  } else if (isTablet) {
    if (hasSession) {
      return <FeedsTabBarTablet {...props} />
    } else {
      return <FeedsTabBarPublic />
    }
  } else {
    return null
  }
}

function FeedsTabBarPublic() {
  const pal = usePalette('default')
  const {isSandbox} = useSession()

  return (
    <CenteredView sideBorders>
      <View
        style={[
          pal.view,
          {
            flexDirection: 'row',
            alignItems: 'center',
            justifyContent: 'space-between',
            paddingHorizontal: 18,
            paddingVertical: 12,
          },
        ]}>
        <TextLink
          type="title-lg"
          href="/"
          style={[pal.text, {fontWeight: 'bold'}]}
          text={
            <>
              {isSandbox ? 'SANDBOX' : 'Bluesky'}{' '}
              {/*hasNew && (
                <View
                  style={{
                    top: -8,
                    backgroundColor: colors.blue3,
                    width: 8,
                    height: 8,
                    borderRadius: 4,
                  }}
                />
              )*/}
            </>
          }
          // onPress={emitSoftReset}
        />
      </View>
    </CenteredView>
  )
}

function FeedsTabBarTablet(
  props: RenderTabBarFnProps & {testID?: string; onPressSelected: () => void},
) {
  const {feeds, hasPinnedCustom} = usePinnedFeedsInfos()
  const pal = usePalette('default')
  const {hasSession} = useSession()
  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 onPressDiscoverFeeds = React.useCallback(() => {
    if (isWeb) {
      navigation.navigate('Feeds')
    } else {
      navigation.navigate('FeedsTab')
      navigation.popToTop()
    }
  }, [navigation])

  const onSelect = React.useCallback(
    (index: number) => {
      if (showFeedsLinkInTabBar && index === items.length - 1) {
        onPressDiscoverFeeds()
      } else if (props.onSelect) {
        props.onSelect(index)
      }
    },
    [items.length, onPressDiscoverFeeds, props, showFeedsLinkInTabBar],
  )

  return (
    // @ts-ignore the type signature for transform wrong here, translateX and translateY need to be in separate objects -prf
    <Animated.View
      style={[pal.view, styles.tabBar, headerMinimalShellTransform]}
      onLayout={e => {
        headerHeight.value = e.nativeEvent.layout.height
      }}>
      <TabBar
        key={items.join(',')}
        {...props}
        onSelect={onSelect}
        items={items}
        indicatorColor={pal.colors.link}
      />
    </Animated.View>
  )
}

const styles = StyleSheet.create({
  tabBar: {
    position: 'absolute',
    zIndex: 1,
    // @ts-ignore Web only -prf
    left: 'calc(50% - 299px)',
    width: 598,
    top: 0,
    flexDirection: 'row',
    alignItems: 'center',
  },
})