Skip to content

Commit

Permalink
Merge pull request #1278 from andrew-bierman/feat/trips-scoring
Browse files Browse the repository at this point in the history
Feat/trips scoring
  • Loading branch information
taronaleksanian authored Oct 2, 2024
2 parents 17e8ff3 + a6bb94c commit e878b93
Show file tree
Hide file tree
Showing 19 changed files with 1,543 additions and 31 deletions.
4 changes: 2 additions & 2 deletions packages/app/components/ScoreContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,11 @@ export const ScoreContainer: React.FC<ScoreContainerProps> = ({
<RText style={{ fontWeight: 300, color: currentTheme.colors.text }}>
{description}
</RText>
{isOwner && (
{/* {isOwner && (
<RButton style={styles.button} onPress={handleScoreClick}>
<RText style={styles.buttonText}>Calculate Score</RText>
</RButton>
)}
)} */}
</YStack>
{isAlreadyScored && (
<View
Expand Down
24 changes: 24 additions & 0 deletions packages/app/components/ScoreLabel/ScoreLable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React, { type FC } from 'react';
import { RStack, RText } from '@packrat/ui';
import useTheme from 'app/hooks/useTheme';
import { StarIcon } from 'lucide-react-native';

interface ScoreLabelProps {
score: number;
}
export const ScoreLabel: FC<ScoreLabelProps> = ({ score }) => {
const { currentTheme } = useTheme();

return (
<RStack
style={{
flexDirection: 'row',
gap: 4,
alignItems: 'center',
}}
>
<StarIcon size={16} color={currentTheme.colors.text} />
<RText>{score}</RText>
</RStack>
);
};
1 change: 1 addition & 0 deletions packages/app/components/ScoreLabel/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './ScoreLable';
3 changes: 3 additions & 0 deletions packages/app/modules/feed/components/FeedCard/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const feedItemPackCardConverter: Converter<
createdAt: formatDistanceToNowStrict(new Date(input.createdAt), {
addSuffix: false,
}),
is_public: input.is_public,
title: truncateString(input.name, 25),
ownerId:
typeof input.owner_id === 'string'
Expand Down Expand Up @@ -57,6 +58,7 @@ export const feedItemTripCardConverter: Converter<
addSuffix: false,
}),
title: truncateString(input.name, 25),
is_public: input.is_public,
ownerId:
typeof input.owner_id === 'string'
? input.owner_id
Expand All @@ -67,6 +69,7 @@ export const feedItemTripCardConverter: Converter<
startDate: input.start_date,
endDate: input.end_date,
activity: input.activity,
score: !isNaN(input.total_score) ? roundNumber(input.total_score) : 0,
},
favoriteCount: input.favorites_count,
};
Expand Down
2 changes: 2 additions & 0 deletions packages/app/modules/feed/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export interface TripFeedItem extends BaseFeedItem {
start_date: string;
end_date: string;
activity: string;
scores: { totalScore: number };
total_score: number;
}

export type FeedItem = PackFeedItem | TripFeedItem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@ import { LocationLabel } from '../LocationLabel';
interface TripCardProps extends FeedCardProps<TripDetails> {}

export const TripPrimaryCard: FC<TripCardProps> = (props) => {
const tripDetails = Object.entries(props.details)
.filter(([key]) => key !== 'description')
.map(([key, value]) => ({
key,
label: key,
value,
}));

return (
<Card
title={props.title}
Expand All @@ -41,6 +33,11 @@ export const TripPrimaryCard: FC<TripCardProps> = (props) => {
<RText>{props.details.description}</RText>
<Details
items={[
{
key: 'score',
label: 'Score',
value: props.details.score,
},
{
key: 'startDate',
label: 'Start Date',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Card } from '@packrat/ui';
import { Card, RStack, RText } from '@packrat/ui';
import React, { type FC } from 'react';
import { TripImage } from './TripImage';
import { type FeedCardProps } from 'app/modules/feed';
import { type TripDetails } from 'modules/trip/model';
import { LocationLabel } from '../LocationLabel';
import { ScoreLabel } from 'app/components/ScoreLabel';

interface TripCardProps extends FeedCardProps<TripDetails> {}

Expand All @@ -15,6 +16,18 @@ export const TripSecondaryCard: FC<TripCardProps> = (props) => {
image={
<TripImage style={{ justifyContent: 'flex-start', paddingTop: 15 }} />
}
actions={
<RStack
style={{
flexDirection: 'column',
alignSelf: 'stretch',
justifyContent: 'space-between',
}}
>
<RText>Score</RText>
<ScoreLabel score={props.details.score} />
</RStack>
}
subtitle={<LocationLabel location={props.details.destination} />}
type={props.cardType}
/>
Expand Down
1 change: 1 addition & 0 deletions packages/app/modules/trip/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export interface TripDetails {
description: string;
destination: string;
activity: string;
score: number;
}
1 change: 0 additions & 1 deletion packages/app/modules/user/components/UserDataCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { useAddFavorite } from 'app/modules/feed';
import { useAuthUser } from 'app/modules/auth';
import { UserTripCard } from './UserTripCard';
import { UserPackCard } from './UserPackCard';
import { View, Text } from 'react-native';

const convertersByType = {
pack: UserDataPackCardConverter,
Expand Down
21 changes: 7 additions & 14 deletions packages/app/modules/user/components/UserPackCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
import { type PackDetails } from 'app/modules/pack/model';
import { useEditPack } from 'app/modules/pack/hooks';
import useTheme from 'app/hooks/useTheme';
import { StarIcon } from 'lucide-react-native';
import { useUserPacks } from 'app/modules/pack/hooks';
import { ScoreLabel } from 'app/components/ScoreLabel';

interface PackCardProps extends FeedCardProps<PackDetails> {}

Expand Down Expand Up @@ -46,20 +46,13 @@ export const UserPackCard: FC<PackCardProps> = (props) => {
link={`/pack/${props.id}`}
image={<PackImage />}
subtitle={
<RStack
style={{
flexDirection: 'row',
gap: 4,
alignItems: 'center',
}}
>
<StarIcon size={16} color={currentTheme.colors.text} />
<RText>
{!isNaN(props.details.similarityScore)
<ScoreLabel
score={
!isNaN(props.details.similarityScore)
? props.details.similarityScore
: props.details.score}
</RText>
</RStack>
: Number(props.details.score)
}
/>
}
actions={
<RStack style={{ flexDirection: 'row', gap: 12 }}>
Expand Down
4 changes: 3 additions & 1 deletion packages/app/screens/trip/TripDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ export function TripDetails() {
return (
<ScoreContainer
type="trip"
data={data}
data={{
total_score: data?.scores?.totalScore || 0,
}}
isOwner={Boolean(isOwner)}
/>
);
Expand Down
9 changes: 9 additions & 0 deletions server/migrations/0004_ambitious_old_lace.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE IF NOT EXISTS `item_image` (
`id` text PRIMARY KEY NOT NULL,
`item_id` text NOT NULL,
`url` text NOT NULL,
`created_at` text DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (`item_id`) REFERENCES `item`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
ALTER TABLE trip ADD `scores` text DEFAULT '{"totalScore":0}';
Loading

0 comments on commit e878b93

Please sign in to comment.