Skip to content

Commit a3c3282

Browse files
committed
✅ Adds like count to trip show page
1 parent e9a1462 commit a3c3282

File tree

3 files changed

+36
-15
lines changed

3 files changed

+36
-15
lines changed

src/components/HitchhikingTrip.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import CountryFlags from './helpers/CountryFlags';
2626
import ExperienceCircle from './helpers/ExperienceCircle';
2727
import ExperiencesForRides from './helpers/ExperiencesForRides';
2828
import LikeRide from './helpers/LikeRide';
29+
import { NumberOfLikesCount } from './helpers/NumberOfLikesCount';
2930

3031
export function HitchhikingTrip({
3132
user,
@@ -76,6 +77,7 @@ export function HitchhikingTrip({
7677
<div className="flex flex-col items-center justify-between text-gray-500">
7778
<div className="flex items-center mt-2 gap-2 dark:text-white">
7879
<ExperiencesForRides rides={rides} />
80+
<NumberOfLikesCount trip={trip} />
7981
<CountryFlags trip={trip} />
8082
</div>
8183
{rides.length > 0 && (
@@ -107,9 +109,8 @@ export function HitchhikingTrip({
107109
</div>
108110
<article>
109111
<div
110-
className={`h-56 sm:h-64 xl:h-76 pb-4 ${
111-
ridesWithPhoto.length === 0 && 'hidden'
112-
}`}
112+
className={`h-56 sm:h-64 xl:h-76 pb-4 ${ridesWithPhoto.length === 0 && 'hidden'
113+
}`}
113114
>
114115
<Carousel slideInterval={5000} slide={true}>
115116
{ridesWithPhoto.map(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Trip } from '@/types'
2+
import { Tooltip } from 'flowbite-react'
3+
import React, { FC } from 'react'
4+
import { FaHeart } from 'react-icons/fa'
5+
6+
interface NumberOfLikesCountProps { trip: Trip };
7+
8+
export const NumberOfLikesCount: FC<NumberOfLikesCountProps> = ({ trip }) => {
9+
if (trip.likes_count === 0) return null;
10+
11+
return (
12+
<Tooltip content={`Received ${trip.likes_count} likes`}>
13+
<div className='relative gap-2 flex items-center'>
14+
{trip.likes_count}
15+
<FaHeart className='text-red-500' />
16+
</div>
17+
</Tooltip>
18+
)
19+
}

src/types/Trip.ts

+13-12
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,30 @@ export type Location = {
1414
export type Timestamp = { seconds: number; nanoseconds: number };
1515

1616
export type Trip = {
17-
id: number | string;
18-
to_param: string;
19-
arrival: Date;
20-
departure: Date;
21-
created_at: Date;
22-
google_duration?: number;
23-
distance?: number;
24-
travelling_with: number;
2517
age_at_trip: number;
18+
arrival: Date;
2619
average_speed: string;
20+
center: string;
21+
comments: Comment[];
2722
country_distances: Country[];
28-
origin: Location;
23+
created_at: Date;
24+
departure: Date;
2925
destination: Location;
26+
distance?: number;
27+
google_duration?: number;
28+
id: number | string;
29+
likes_count: number;
30+
origin: Location;
3031
rides: Ride[];
32+
to_param: string;
3133
total_distance: number;
32-
center: string;
33-
user_id: number;
34+
travelling_with: number;
3435
user: {
3536
username: string;
3637
md5_email: string;
3738
gender: 'male' | 'female' | 'non-binary' | null;
3839
};
39-
comments: Comment[];
40+
user_id: number;
4041
};
4142

4243
export type TripUser = {

0 commit comments

Comments
 (0)