Detect without resolution, disable links
This commit is contained in:
+16
-32
@@ -5,6 +5,7 @@ import {
|
|||||||
AppBskyFeedDefs,
|
AppBskyFeedDefs,
|
||||||
AppBskyGraphDefs,
|
AppBskyGraphDefs,
|
||||||
AtUri,
|
AtUri,
|
||||||
|
RichText as RichTextApi,
|
||||||
} from '@atproto/api'
|
} from '@atproto/api'
|
||||||
import {msg, plural, Trans} from '@lingui/macro'
|
import {msg, plural, Trans} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
@@ -24,7 +25,6 @@ import * as Toast from 'view/com/util/Toast'
|
|||||||
import {useTheme} from '#/alf'
|
import {useTheme} from '#/alf'
|
||||||
import {atoms as a} from '#/alf'
|
import {atoms as a} from '#/alf'
|
||||||
import {Button, ButtonIcon} from '#/components/Button'
|
import {Button, ButtonIcon} from '#/components/Button'
|
||||||
import {useRichText} from '#/components/hooks/useRichText'
|
|
||||||
import {PlusLarge_Stroke2_Corner0_Rounded as Plus} from '#/components/icons/Plus'
|
import {PlusLarge_Stroke2_Corner0_Rounded as Plus} from '#/components/icons/Plus'
|
||||||
import {Trash_Stroke2_Corner0_Rounded as Trash} from '#/components/icons/Trash'
|
import {Trash_Stroke2_Corner0_Rounded as Trash} from '#/components/icons/Trash'
|
||||||
import {Link as InternalLink, LinkProps} from '#/components/Link'
|
import {Link as InternalLink, LinkProps} from '#/components/Link'
|
||||||
@@ -33,21 +33,18 @@ import * as Prompt from '#/components/Prompt'
|
|||||||
import {RichText} from '#/components/RichText'
|
import {RichText} from '#/components/RichText'
|
||||||
import {Text} from '#/components/Typography'
|
import {Text} from '#/components/Typography'
|
||||||
|
|
||||||
type CommonProps = {
|
|
||||||
disableDescriptionFacets?: boolean
|
|
||||||
}
|
|
||||||
type Props =
|
type Props =
|
||||||
| ({
|
| {
|
||||||
type: 'feed'
|
type: 'feed'
|
||||||
view: AppBskyFeedDefs.GeneratorView
|
view: AppBskyFeedDefs.GeneratorView
|
||||||
} & CommonProps)
|
}
|
||||||
| ({
|
| {
|
||||||
type: 'list'
|
type: 'list'
|
||||||
view: AppBskyGraphDefs.ListView
|
view: AppBskyGraphDefs.ListView
|
||||||
} & CommonProps)
|
}
|
||||||
|
|
||||||
export function Default(props: Props) {
|
export function Default(props: Props) {
|
||||||
const {type, view, disableDescriptionFacets} = props
|
const {type, view} = props
|
||||||
const displayName = type === 'feed' ? view.displayName : view.name
|
const displayName = type === 'feed' ? view.displayName : view.name
|
||||||
const purpose = type === 'list' ? view.purpose : undefined
|
const purpose = type === 'list' ? view.purpose : undefined
|
||||||
return (
|
return (
|
||||||
@@ -63,10 +60,7 @@ export function Default(props: Props) {
|
|||||||
/>
|
/>
|
||||||
<Action uri={view.uri} pin type={type} purpose={purpose} />
|
<Action uri={view.uri} pin type={type} purpose={purpose} />
|
||||||
</Header>
|
</Header>
|
||||||
<Description
|
<Description description={view.description} />
|
||||||
description={view.description}
|
|
||||||
disableFacets={disableDescriptionFacets}
|
|
||||||
/>
|
|
||||||
{type === 'feed' && <Likes count={view.likeCount || 0} />}
|
{type === 'feed' && <Likes count={view.likeCount || 0} />}
|
||||||
</Outer>
|
</Outer>
|
||||||
</Link>
|
</Link>
|
||||||
@@ -204,25 +198,15 @@ export function TitleAndBylinePlaceholder({creator}: {creator?: boolean}) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Description({
|
export function Description({description}: {description?: string}) {
|
||||||
description,
|
const [rt] = React.useState(() => {
|
||||||
disableFacets,
|
if (!description) return
|
||||||
}: {
|
const rt = new RichTextApi({text: description || ''})
|
||||||
description?: string
|
rt.detectFacetsWithoutResolution()
|
||||||
disableFacets?: boolean
|
return rt
|
||||||
}) {
|
})
|
||||||
if (!description) return null
|
if (!rt) return null
|
||||||
return disableFacets ? (
|
return <RichText value={rt} style={[a.leading_snug]} disableLinks />
|
||||||
<RichText value={description} style={[a.leading_snug]} />
|
|
||||||
) : (
|
|
||||||
<DescriptionWithFacets description={description} />
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export function DescriptionWithFacets({description}: {description?: string}) {
|
|
||||||
const [rt] = useRichText(description || '')
|
|
||||||
if (!description) return null
|
|
||||||
return <RichText value={rt ?? description} style={[a.leading_snug]} />
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Likes({count}: {count: number}) {
|
export function Likes({count}: {count: number}) {
|
||||||
|
|||||||
Reference in New Issue
Block a user