diff --git a/src/components/ListCard.tsx b/src/components/ListCard.tsx new file mode 100644 index 0000000000..5dfe320564 --- /dev/null +++ b/src/components/ListCard.tsx @@ -0,0 +1,101 @@ +import React from 'react' +import {View} from 'react-native' +import {AppBskyActorDefs, AppBskyGraphDefs, AtUri} from '@atproto/api' +import {Trans} from '@lingui/macro' +import {useQueryClient} from '@tanstack/react-query' + +import {sanitizeHandle} from 'lib/strings/handles' +import {precacheList} from 'state/queries/feed' +import {useTheme} from '#/alf' +import {atoms as a} from '#/alf' +import {Avatar, Description, Header, Outer} from '#/components/FeedCard' +import {Link as InternalLink, LinkProps} from '#/components/Link' +import {Text} from '#/components/Typography' + +/* + * This component is based on `FeedCard` and is tightly coupled with that + * component. Please refer to `FeedCard` for more context. + */ + +export { + AvatarPlaceholder, + TitleAndBylinePlaceholder, +} from '#/components/FeedCard' + +export {Avatar, Description, Header, Outer} + +type Props = { + view: AppBskyGraphDefs.ListView +} + +export function Default(props: Props) { + const {view} = props + return ( + + +
+ + +
+ +
+ + ) +} + +export function Link({ + view, + children, + ...props +}: Props & Omit) { + const queryClient = useQueryClient() + + const href = React.useMemo(() => { + return createProfileListHref({list: view}) + }, [view]) + + React.useEffect(() => { + precacheList(queryClient, view) + }, [view, queryClient]) + + return ( + + {children} + + ) +} + +export function TitleAndByline({ + title, + creator, +}: { + title: string + creator?: AppBskyActorDefs.ProfileViewBasic +}) { + const t = useTheme() + + return ( + + + {title} + + {creator && ( + + List by {sanitizeHandle(creator.handle, '@')} + + )} + + ) +} + +export function createProfileListHref({ + list, +}: { + list: AppBskyGraphDefs.ListView +}) { + const urip = new AtUri(list.uri) + const handleOrDid = list.creator.handle || list.creator.did + return `/profile/${handleOrDid}/lists/${urip.rkey}` +} diff --git a/src/view/com/lists/ProfileLists.tsx b/src/view/com/lists/ProfileLists.tsx index 62c944efcb..dc385d4361 100644 --- a/src/view/com/lists/ProfileLists.tsx +++ b/src/view/com/lists/ProfileLists.tsx @@ -18,7 +18,7 @@ import {useAnalytics} from 'lib/analytics/analytics' import {FeedLoadingPlaceholder} from '#/view/com/util/LoadingPlaceholder' import {EmptyState} from 'view/com/util/EmptyState' import {atoms as a, useTheme} from '#/alf' -import * as FeedCard from '#/components/FeedCard' +import * as ListCard from '#/components/ListCard' import {ErrorMessage} from '../util/error/ErrorMessage' import {List, ListRef} from '../util/List' import {LoadMoreRetryBtn} from '../util/LoadMoreRetryBtn' @@ -172,7 +172,7 @@ export const ProfileLists = React.forwardRef( a.px_lg, a.py_lg, ]}> - + ) },