Skip to content

Commit

Permalink
add score to pack secondary card
Browse files Browse the repository at this point in the history
  • Loading branch information
taronaleksanian committed Sep 8, 2024
1 parent 44b5ad1 commit aff140e
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 11 deletions.
6 changes: 5 additions & 1 deletion packages/app/modules/feed/components/FeedCard/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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';
import { roundNumber } from 'app/utils';

type Converter<Input, Result> = (
input: Input,
Expand All @@ -23,7 +24,10 @@ export const feedItemPackCardConverter: Converter<
? input.owner_id
: input.owner_id?.id || '',
details: {
score: input.total_score,
score: !isNaN(input.total_score) ? roundNumber(input.total_score) : 0,
similarityScore: !isNaN(input.similarityScore)
? roundNumber(input.similarityScore)
: undefined,
weight: input.total_weight,
quantity:
input?.itemPacks?.reduce(
Expand Down
1 change: 1 addition & 0 deletions packages/app/modules/feed/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface FeedItem {
username: string;
};
name: string;
similarityScore?: number;
total_weight: number;
total_score: number;
is_public: boolean;
Expand Down
35 changes: 25 additions & 10 deletions packages/app/modules/pack/components/PackCard/PackSecondaryCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Card, RStack } from '@packrat/ui';
import { Card, RStack, RText } from '@packrat/ui';
import React, { type FC } from 'react';
import { PackImage } from './PackImage';
import {
Expand All @@ -7,6 +7,7 @@ import {
type FeedCardProps,
} from 'app/modules/feed';
import { type PackDetails } from 'app/modules/pack/model';
import { StarIcon } from 'lucide-react-native';

interface PackCardProps extends FeedCardProps<PackDetails> {}

Expand All @@ -20,16 +21,30 @@ export const PackSecondaryCard: FC<PackCardProps> = (props) => {
}
subtitle={<CreatedAtLabel date={props.createdAt} />}
actions={
<RStack style={{ flexDirection: 'row', gap: 12 }}>
<FavoriteButton
count={props.favoriteCount}
isAuthUserFavorite={props.isUserFavorite}
onClick={(e) => {
e.stopPropagation();
e.preventDefault();
props.toggleFavorite();
<RStack
style={{
flexDirection: 'column',
alignSelf: 'stretch',
justifyContent: 'space-between',
}}
>
<RText>
{!isNaN(props.details.similarityScore) ? 'Similarity' : 'Score'}
</RText>
<RStack
style={{
flexDirection: 'row',
gap: 4,
alignItems: 'center',
}}
/>
>
<StarIcon size={16} />
<RText>
{!isNaN(props.details.similarityScore)
? props.details.similarityScore
: props.details.score}
</RText>
</RStack>
</RStack>
}
type={props.cardType}
Expand Down
1 change: 1 addition & 0 deletions packages/app/modules/pack/model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export interface PackDetails {
score?: number;
similarityScore?: number;
quantity: number;
weight: number;
}
1 change: 1 addition & 0 deletions packages/app/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './numberUtils';
2 changes: 2 additions & 0 deletions packages/app/utils/numberUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const roundNumber = (num: number) =>
Math.round((num + Number.EPSILON) * 100) / 100;

0 comments on commit aff140e

Please sign in to comment.