diff --git a/packages/app/components/feedPreview/FeedPreviewCard.tsx b/packages/app/components/feedPreview/FeedPreviewCard.tsx index 49b976c71..5bd256285 100644 --- a/packages/app/components/feedPreview/FeedPreviewCard.tsx +++ b/packages/app/components/feedPreview/FeedPreviewCard.tsx @@ -4,7 +4,7 @@ import { RLink } from '@packrat/ui'; import { LayoutChangeEvent, View } from 'react-native'; import useCustomStyles from 'app/hooks/useCustomStyles'; import loadStyles from './feedpreview.style'; -import { AntDesign, MaterialIcons } from '@expo/vector-icons'; +import { AntDesign, Fontisto, MaterialIcons } from '@expo/vector-icons'; import useTheme from 'app/hooks/useTheme'; import { useItemWeightUnit } from 'app/hooks/items'; import { convertWeight } from 'app/utils/convertWeight'; @@ -17,15 +17,24 @@ export type FeedItem = any; interface FeedPreviewCardProps { linkStr: string; item: FeedItem; + feedType: string; } const RText: any = OriginalRText; -const FeedPreviewCard: React.FC = ({ linkStr, item }) => { +const FeedPreviewCard: React.FC = ({ + linkStr, + item, + feedType, +}) => { const { currentTheme } = useTheme(); const styles = useCustomStyles(loadStyles); const [weightUnit] = useItemWeightUnit(); - const formattedWeight = convertWeight(item.total_weight, 'g', weightUnit); + const formattedWeight = convertWeight( + item.total_weight ?? item.weight, + item.unit ?? 'g', + weightUnit, + ); const [cardWidth, setCardWidth] = useState(); const handleSetCardWidth = (event: LayoutChangeEvent) => { @@ -33,6 +42,93 @@ const FeedPreviewCard: React.FC = ({ linkStr, item }) => { setCardWidth(width); }; + if (feedType == 'similarItems') { + return ( + + + + + + + + + {item.name} + + + + {formatNumber(formattedWeight)} + {weightUnit} + + + + Qty: {item.quantity} + + + + + {new Date(item.createdAt).toLocaleString('en-US', { + month: 'short', + day: '2-digit', + ...(new Date(item.createdAt).getFullYear() == + new Date().getFullYear() + ? {} + : { year: 'numeric' }), + })} + + + + + + ); + } + return ( diff --git a/packages/app/components/feedPreview/index.tsx b/packages/app/components/feedPreview/index.tsx index d4bd8fdbf..b2649ca9c 100644 --- a/packages/app/components/feedPreview/index.tsx +++ b/packages/app/components/feedPreview/index.tsx @@ -2,6 +2,7 @@ import React from 'react'; import Carousel from '../carousel'; import { useFeed } from 'app/hooks/feed'; import { default as FeedPreviewCard, type FeedItem } from './FeedPreviewCard'; +import Loader from 'app/components/Loader'; interface FeedPreviewScrollProps { itemWidth: number; @@ -14,16 +15,18 @@ const FeedPreviewScroll: React.FC = ({ feedType, id, }) => { - const { data: feedData } = useFeed({ feedType, id }); + const { data: feedData, isLoading } = useFeed({ feedType, id }); - return ( + return isLoading ? ( + + ) : ( {feedData ?.filter((item): item is FeedItem => item.type !== null) .map((item: FeedItem) => { const linkStr = `/${item.type}/${item.id}`; return linkStr ? ( - + ) : null; })} diff --git a/packages/app/hooks/feed/index.ts b/packages/app/hooks/feed/index.ts index f588cb888..636e8cfaa 100644 --- a/packages/app/hooks/feed/index.ts +++ b/packages/app/hooks/feed/index.ts @@ -1,7 +1,8 @@ import { usePublicFeed } from './publicFeed'; import { useUserPacks } from './../packs'; import { useUserTrips } from '../singletrips'; -import { useSimilarPacks } from 'app/hooks/packs/useSimilarPacks'; +import { useSimilarPacks } from 'app/hooks/packs'; +import { useSimilarItems } from 'app/hooks/items'; export const useFeed = ({ queryString = 'Most Recent', @@ -25,6 +26,8 @@ export const useFeed = ({ return useUserTrips(ownerId || undefined); case 'similarPacks': return useSimilarPacks(id); + case 'similarItems': + return useSimilarItems(id); default: return { data: null, error: null, isLoading: true }; } diff --git a/packages/app/hooks/items/index.ts b/packages/app/hooks/items/index.ts index 2512212e1..1244bc362 100644 --- a/packages/app/hooks/items/index.ts +++ b/packages/app/hooks/items/index.ts @@ -5,3 +5,4 @@ export { useItemsUpdater } from './useItemsUpdater'; export { useItemWeightUnit } from './useItemWeightUnit'; export { useItemId } from './useItemId'; export { useItem } from './useItem'; +export { useSimilarItems } from './useSimilarItems'; diff --git a/packages/app/hooks/items/useSimilarItems.ts b/packages/app/hooks/items/useSimilarItems.ts new file mode 100644 index 000000000..2b8db4967 --- /dev/null +++ b/packages/app/hooks/items/useSimilarItems.ts @@ -0,0 +1,13 @@ +import { queryTrpc } from '../../trpc'; + +export const useSimilarItems = (id: string) => { + const { data, error, isLoading, refetch } = + queryTrpc.getSimilarItems.useQuery( + { id, limit: 10 }, + { + refetchOnWindowFocus: true, + }, + ); + + return { data, error, isLoading, refetch }; +}; diff --git a/packages/app/screens/items/item-details.tsx b/packages/app/screens/items/item-details.tsx index e16046de5..d49ebdd7f 100644 --- a/packages/app/screens/items/item-details.tsx +++ b/packages/app/screens/items/item-details.tsx @@ -10,6 +10,7 @@ import { usePagination } from 'app/hooks/common'; import { BaseModal, DropdownComponent, + RH3, RImage, RScrollView, RStack, @@ -18,16 +19,20 @@ import { } from '@packrat/ui'; import useResponsive from 'app/hooks/useResponsive'; import { CustomCard } from 'app/components/card'; +import LargeCard from 'app/components/card/LargeCard'; +import FeedPreview from 'app/components/feedPreview'; export default function ItemDetails() { const { limit, handleLimitChange, page, handlePageChange } = usePagination(); const [itemId] = useItemId(); const { data: item, isError } = useItem(itemId); const styles = useCustomStyles(loadStyles); + const { currentTheme } = useTheme(); + console.log({ item, itemId }); return ( - + {!isError && item && ( @@ -55,6 +60,26 @@ export default function ItemDetails() { } type="item" /> + + + Similar Items + + + )}