From 0577e9829aa567d95044d9f3c7e008de9a6e32c9 Mon Sep 17 00:00:00 2001 From: Hailey Date: Tue, 11 Jun 2024 23:26:17 -0700 Subject: [PATCH] basic button for creating a starter pack on profile --- .../StarterPack/ProfileStarterPacks.tsx | 123 +++++++++--------- 1 file changed, 60 insertions(+), 63 deletions(-) diff --git a/src/components/StarterPack/ProfileStarterPacks.tsx b/src/components/StarterPack/ProfileStarterPacks.tsx index 74d22f409c..52028f7167 100644 --- a/src/components/StarterPack/ProfileStarterPacks.tsx +++ b/src/components/StarterPack/ProfileStarterPacks.tsx @@ -6,25 +6,19 @@ import { View, ViewStyle, } from 'react-native' -import {AppBskyGraphGetActorStarterPacks} from '@atproto/api' -import {Trans} from '@lingui/macro' +import {AppBskyGraphDefs, AppBskyGraphGetActorStarterPacks} from '@atproto/api' +import {msg, Trans} from '@lingui/macro' +import {useLingui} from '@lingui/react' import {InfiniteData, UseInfiniteQueryResult} from '@tanstack/react-query' -import {useTheme} from '#/lib/ThemeContext' import {logger} from '#/logger' import {isNative, isWeb} from '#/platform/detection' -import {usePalette} from 'lib/hooks/usePalette' -import {usePreferencesQuery} from 'state/queries/preferences' -import {FeedLoadingPlaceholder} from '#/view/com/util/LoadingPlaceholder' import {List, ListRef} from 'view/com/util/List' import {Text} from 'view/com/util/text/Text' +import {atoms as a, useTheme} from '#/alf' +import {Button, ButtonText} from '#/components/Button' import {StarterPackCard} from '#/components/StarterPack/StarterPackCard' -const LOADING = {_reactKey: '__loading__'} -const EMPTY = {_reactKey: '__empty__'} -const ERROR_ITEM = {_reactKey: '__error__'} -const LOAD_MORE_ERROR_ITEM = {_reactKey: '__load_more_error__'} - interface SectionRef { scrollToTop: () => void } @@ -42,6 +36,23 @@ interface ProfileFeedgensProps { setScrollViewTag: (tag: number | null) => void } +function renderItem({ + item, + index, +}: ListRenderItemInfo) { + return ( + + ) +} + +function keyExtractor(item: AppBskyGraphDefs.StarterPackView) { + return item.uri +} + export const ProfileStarterPacks = React.forwardRef< SectionRef, ProfileFeedgensProps @@ -57,29 +68,11 @@ export const ProfileStarterPacks = React.forwardRef< }, ref, ) { - const pal = usePalette('default') - const theme = useTheme() + const t = useTheme() const [isPTRing, setIsPTRing] = React.useState(false) - const {data: pages, refetch, isFetching, hasNextPage, fetchNextPage} = query - const {data: preferences} = usePreferencesQuery() + const {data, refetch, isFetching, hasNextPage, fetchNextPage} = query - const isEmpty = pages?.pages.length === 0 - - const items = React.useMemo(() => { - let items: any[] = [] - if (isEmpty) { - items = items.concat([ERROR_ITEM]) - } - if (isEmpty) { - items = items.concat([EMPTY]) - } else if (pages?.pages) { - items = pages?.pages.flatMap(page => page.starterPacks) - } - if (!isEmpty) { - items = items.concat([LOAD_MORE_ERROR_ITEM]) - } - return items - }, [isEmpty, pages]) + const items = data?.pages.flatMap(page => page.starterPacks) React.useImperativeHandle(ref, () => ({ scrollToTop: () => {}, @@ -105,35 +98,6 @@ export const ProfileStarterPacks = React.forwardRef< } }, [isFetching, hasNextPage, fetchNextPage]) - const renderItem = React.useCallback( - ({item, index}: ListRenderItemInfo) => { - if (item === EMPTY) { - return ( - - - You have no starter packs. - - - ) - } else if (item === LOADING) { - return - } - if (preferences) { - return ( - - ) - } - return null - }, - [pal, preferences], - ) - React.useEffect(() => { if (enabled && scrollElRef.current) { const nativeTag = findNodeHandle(scrollElRef.current) @@ -147,17 +111,50 @@ export const ProfileStarterPacks = React.forwardRef< testID={testID ? `${testID}-flatlist` : undefined} ref={scrollElRef} data={items} - keyExtractor={(item: any) => item._reactKey || item.uri} renderItem={renderItem} + keyExtractor={keyExtractor} refreshing={isPTRing} onRefresh={onRefresh} headerOffset={headerOffset} contentContainerStyle={isNative && {paddingBottom: headerOffset + 100}} - indicatorStyle={theme.colorScheme === 'dark' ? 'white' : 'black'} + indicatorStyle={t.name === 'light' ? 'black' : 'white'} removeClippedSubviews={true} desktopFixedHeight onEndReached={onEndReached} + ListEmptyComponent={} /> ) }) + +function EmptyComponent() { + const {_} = useLingui() + const t = useTheme() + + return ( + + + You have not created any starter packs yet! + + + Create a starter pack now to share your favorite people and feeds with + friends! + + + + ) +}