Add WIP UIs for trending topics and suggested starterpacks
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
import {View} from 'react-native'
|
||||
import {ScrollView} from 'react-native-gesture-handler'
|
||||
import {AppBskyGraphDefs} from '@atproto/api'
|
||||
|
||||
import {logger} from '#/logger'
|
||||
import {useModerationOpts} from '#/state/preferences/moderation-opts'
|
||||
import {atoms as a, useBreakpoints, web} from '#/alf'
|
||||
import {Embed} from './StarterPackCard'
|
||||
|
||||
const DESKTOP_CARD_WIDTH = 400
|
||||
const MOBILE_CARD_WIDTH = 300
|
||||
|
||||
export function Grid({
|
||||
isSuggestionsLoading,
|
||||
error,
|
||||
starterPacks,
|
||||
}: {
|
||||
isSuggestionsLoading: boolean
|
||||
starterPacks: AppBskyGraphDefs.StarterPackViewBasic[]
|
||||
error: Error | null
|
||||
}) {
|
||||
const moderationOpts = useModerationOpts()
|
||||
const {gtMobile} = useBreakpoints()
|
||||
const width = gtMobile ? DESKTOP_CARD_WIDTH : MOBILE_CARD_WIDTH
|
||||
const isLoading = isSuggestionsLoading || !moderationOpts
|
||||
const maxLength = gtMobile ? 4 : 6
|
||||
|
||||
const content = isLoading ? (
|
||||
Array(maxLength)
|
||||
.fill(0)
|
||||
.map((_, i) => (
|
||||
<View
|
||||
key={i}
|
||||
style={[gtMobile && web([a.flex_0, {width: 'calc(50% - 6px)'}])]}>
|
||||
{/* TODO <SuggestedFollowPlaceholder /> */}
|
||||
</View>
|
||||
))
|
||||
) : error || !starterPacks.length ? null : (
|
||||
<>
|
||||
{starterPacks.slice(0, maxLength).map(starterPack => (
|
||||
<View key={starterPack.uri} style={[{width}]}>
|
||||
<Embed starterPack={starterPack} />
|
||||
</View>
|
||||
))}
|
||||
</>
|
||||
)
|
||||
|
||||
if (error || (!isLoading && !starterPacks.length)) {
|
||||
logger.debug(`Not enough starter packs to show suggested starter packs`)
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<ScrollView
|
||||
horizontal
|
||||
showsHorizontalScrollIndicator={false}
|
||||
snapToInterval={width + a.gap_md.gap}
|
||||
decelerationRate="fast">
|
||||
<View style={[a.px_md, a.pt_sm, a.pb_lg, a.flex_row, a.gap_md]}>
|
||||
{content}
|
||||
</View>
|
||||
</ScrollView>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
import {View} from 'react-native'
|
||||
import {msg} from '@lingui/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
|
||||
import {atoms as a, useTheme} from '#/alf'
|
||||
import {Link as InternalLink, LinkProps} from '#/components/Link'
|
||||
import {Text} from '#/components/Typography'
|
||||
|
||||
export function Grid({topics}: {topics: string[]}) {
|
||||
return (
|
||||
<View style={[a.flex_row, a.flex_wrap, a.gap_sm, a.px_sm, a.py_sm]}>
|
||||
{topics.map(topic => (
|
||||
<Item key={topic} topic={topic} />
|
||||
))}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
export function Item({topic}: {topic: string}) {
|
||||
return (
|
||||
<Link topic={topic}>
|
||||
<Card topic={topic} />
|
||||
</Link>
|
||||
)
|
||||
}
|
||||
|
||||
export function Card({topic}: {topic: string}) {
|
||||
const t = useTheme()
|
||||
return (
|
||||
<View
|
||||
style={[
|
||||
a.flex_1,
|
||||
a.gap_xs,
|
||||
a.px_md,
|
||||
a.py_md,
|
||||
a.border,
|
||||
t.atoms.border_contrast_medium,
|
||||
a.rounded_md,
|
||||
]}>
|
||||
<Topic topic={topic} />
|
||||
</View>
|
||||
)
|
||||
}
|
||||
|
||||
export function Link({
|
||||
topic,
|
||||
children,
|
||||
style,
|
||||
...rest
|
||||
}: {
|
||||
topic: string
|
||||
} & Omit<LinkProps, 'to' | 'label'>) {
|
||||
const {_} = useLingui()
|
||||
return (
|
||||
<InternalLink
|
||||
label={_(msg`Search posts that include ${topic}`)}
|
||||
to={{
|
||||
screen: 'Search',
|
||||
params: {q: topic},
|
||||
}}
|
||||
style={[a.flex_col, style]}
|
||||
{...rest}>
|
||||
{children}
|
||||
</InternalLink>
|
||||
)
|
||||
}
|
||||
|
||||
export function Topic({topic}: {topic: string}) {
|
||||
return (
|
||||
<View style={[a.flex_1]}>
|
||||
<Text
|
||||
emoji
|
||||
style={[a.text_md, a.font_bold, a.leading_snug, a.self_start]}
|
||||
numberOfLines={1}>
|
||||
{topic}
|
||||
</Text>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user