about summary refs log tree commit diff
path: root/src/view/com/util/FeedInfoText.tsx
blob: 3ad05facb34b02ae7bc5bf917af90a44a6162fc5 (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
import {type StyleProp, StyleSheet, type TextStyle} from 'react-native'

import {sanitizeDisplayName} from '#/lib/strings/display-names'
import {type TypographyVariant} from '#/lib/ThemeContext'
import {useFeedSourceInfoQuery} from '#/state/queries/feed'
import {TextLinkOnWebOnly} from './Link'
import {LoadingPlaceholder} from './LoadingPlaceholder'

export function FeedNameText({
  type = 'md',
  uri,
  href,
  lineHeight,
  numberOfLines,
  style,
}: {
  type?: TypographyVariant
  uri: string
  href: string
  lineHeight?: number
  numberOfLines?: number
  style?: StyleProp<TextStyle>
}) {
  const {data, isError} = useFeedSourceInfoQuery({uri})

  let inner
  if (data?.displayName || isError) {
    const displayName = data?.displayName || uri.split('/').pop() || ''
    inner = (
      <TextLinkOnWebOnly
        type={type}
        style={style}
        lineHeight={lineHeight}
        numberOfLines={numberOfLines}
        href={href}
        text={sanitizeDisplayName(displayName)}
      />
    )
  } else {
    inner = (
      <LoadingPlaceholder
        width={80}
        height={8}
        style={styles.loadingPlaceholder}
      />
    )
  }

  return inner
}

const styles = StyleSheet.create({
  loadingPlaceholder: {position: 'relative', top: 1, left: 2},
})