-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1220 from andrew-bierman/feat/card-component
- Loading branch information
Showing
36 changed files
with
579 additions
and
301 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
packages/app/modules/feed/components/CreatedAtLabel/CreatedAtLabel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { XStack, RText } from '@packrat/ui'; | ||
import { Clock } from '@tamagui/lucide-icons'; | ||
import React, { type FC } from 'react'; | ||
|
||
interface CreatedAtLabelProps { | ||
date: string; | ||
} | ||
export const CreatedAtLabel: FC<CreatedAtLabelProps> = ({ date }) => { | ||
return ( | ||
<XStack | ||
style={{ marginTop: 4, alignItems: 'center', maxWidth: '100%' }} | ||
space={4} | ||
> | ||
<Clock size={16} /> | ||
<RText>{date}</RText> | ||
</XStack> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { CreatedAtLabel } from './CreatedAtLabel'; |
28 changes: 28 additions & 0 deletions
28
packages/app/modules/feed/components/FavoriteButton/FavoriteButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { AntDesign } from '@expo/vector-icons'; | ||
import { RText, XStack } from '@packrat/ui'; | ||
import React, { type FC } from 'react'; | ||
import { Pressable, type GestureResponderEvent } from 'react-native'; | ||
|
||
interface FavoriteButtonProps { | ||
isAuthUserFavorite: boolean; | ||
onClick: (e: GestureResponderEvent) => void; | ||
count: number; | ||
} | ||
export const FavoriteButton: FC<FavoriteButtonProps> = ({ | ||
onClick, | ||
isAuthUserFavorite, | ||
count, | ||
}) => { | ||
return ( | ||
<XStack style={{ alignItems: 'center' }} space="$2"> | ||
<Pressable onPress={onClick}> | ||
<AntDesign | ||
name="heart" | ||
size={16} | ||
color={isAuthUserFavorite ? 'red' : undefined} | ||
/> | ||
</Pressable> | ||
<RText style={{ fontSize: 14 }}>{count}</RText> | ||
</XStack> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { FavoriteButton } from './FavoriteButton'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { FeedCard } from './FeedCard'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { type FeedCardProps, type FeedItem } from 'modules/feed/model'; | ||
import { formatDistanceToNowStrict } from 'date-fns'; | ||
import { type PackDetails } from 'app/modules/pack'; | ||
import { truncateString } from 'app/utils/truncateString'; | ||
|
||
type Converter<Input, Result> = ( | ||
input: Input, | ||
currentUserId?: string | number, | ||
) => Result; | ||
|
||
export const feedItemPackCardConverter: Converter< | ||
FeedItem, | ||
Omit<FeedCardProps<PackDetails>, 'cardType' | 'toggleFavorite'> | ||
> = (input, currentUserId) => { | ||
return { | ||
id: input.id, | ||
createdAt: formatDistanceToNowStrict(new Date(input.createdAt), { | ||
addSuffix: false, | ||
}), | ||
title: truncateString(input.name, 25), | ||
ownerId: | ||
typeof input.owner_id === 'string' | ||
? input.owner_id | ||
: input.owner_id?.id || '', | ||
details: { | ||
score: input.total_score, | ||
weight: input.total_weight, | ||
quantity: | ||
input?.itemPacks?.reduce( | ||
(accumulator, currentValue) => | ||
accumulator + currentValue?.item?.quantity, | ||
0, | ||
) ?? 0, | ||
}, | ||
isUserFavorite: input?.userFavoritePacks?.some( | ||
(obj) => obj?.userId === currentUserId, | ||
), | ||
favoriteCount: input.favorites_count, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
export { FeedCard } from './FeedCard'; | ||
export { FeedSearchFilter } from './FeedSearchFilter'; | ||
export { SearchProvider, SearchContext } from './SearchProvider'; | ||
export { FavoriteButton } from './FavoriteButton'; | ||
export { CreatedAtLabel } from './CreatedAtLabel'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
export { useFeed } from './useFeed'; | ||
export { useAddFavorite } from './useAddFavorite'; | ||
export { useFetchUserFavorites } from './useFetchUserFavorites'; |
2 changes: 1 addition & 1 deletion
2
...ges/app/hooks/favorites/useAddFavorite.ts → .../app/modules/feed/hooks/useAddFavorite.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../hooks/favorites/useFetchUserFavorites.ts → ...dules/feed/hooks/useFetchUserFavorites.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,11 @@ | ||
export * from './widgets'; | ||
export * from './screens'; | ||
export { useFeed } from './hooks'; | ||
export { SearchProvider, FeedSearchFilter, FeedCard } from './components'; | ||
export { useFeed, useAddFavorite, useFetchUserFavorites } from './hooks'; | ||
export { | ||
SearchProvider, | ||
FeedSearchFilter, | ||
FeedCard, | ||
FavoriteButton, | ||
CreatedAtLabel, | ||
} from './components'; | ||
export { type FeedCardProps, type FeedItem } from './model'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { type CardType } from '@packrat/ui'; | ||
|
||
export type FeedType = 'pack'; | ||
|
||
export interface FeedItem { | ||
id: string; | ||
owner: { | ||
id: string; | ||
username: string; | ||
}; | ||
name: string; | ||
total_weight: number; | ||
total_score: number; | ||
is_public: boolean; | ||
favorited_by: Array<{ | ||
id: string; | ||
}>; | ||
userFavoritePacks?: Array<{ userId: string }>; | ||
favorites_count: number; | ||
owner_id: string | { id: string }; | ||
destination: string; | ||
createdAt: string; | ||
owners: Array<{ any: any }>; | ||
duration: string; | ||
type: FeedType; | ||
itemPacks?: any[]; | ||
} | ||
|
||
export interface FeedCardProps<Details> { | ||
id: string; | ||
title: string; | ||
cardType: CardType; | ||
createdAt: string; | ||
details: Details; | ||
ownerId: string; | ||
favoriteCount: number; | ||
isUserFavorite: boolean; | ||
toggleFavorite: () => void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.