Skip to content

Commit

Permalink
Merge pull request #37 from gone-bike/fix/bikes-section
Browse files Browse the repository at this point in the history
add: add BikesList component, show match score only when showMatch is…
  • Loading branch information
darioguarascio authored Jun 13, 2023
2 parents a1a5d00 + 7ef24be commit aabc004
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 32 deletions.
41 changes: 41 additions & 0 deletions astro/src/components/bikes/BikesList.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
import BikesCard, {
type BikesCardProps,
} from "@components/cards/BikesCard.astro";
export interface BikesListProps {
items: BikesCardProps[];
showMatch?: boolean;
class?: string;
}
const {
items = [],
showMatch = false,
class: classes,
} = Astro.props as BikesListProps;
---

<ul
class:list={[
"my-4 md:my-10 grid gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4",
{},
classes,
]}
>
{
items?.length > 0 &&
items.map((item) => (
<BikesCard
dateStr={item.dateStr}
showMatch={showMatch}
matchScore={item.matchScore}
brand={item.brand}
model={item.model}
location={item.location}
lang={item.lang}
imgs={item.imgs}
/>
))
}
</ul>
43 changes: 29 additions & 14 deletions astro/src/components/cards/BikesCard.astro
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
relativeDateTimeFormatter,
} from "@utils/formatters";
export interface BikesCardProps {
export interface BikesCardData {
lang: string;
matchScore: number;
brand: string;
Expand All @@ -19,8 +19,20 @@ export interface BikesCardProps {
imgs: CarouselItemProps[];
}
const { lang, matchScore, brand, model, dateStr, location, imgs } =
Astro.props as BikesCardProps;
export interface BikesCardProps extends BikesCardData {
showMatch?: boolean;
}
const {
lang,
matchScore,
brand,
model,
dateStr,
location,
imgs,
showMatch = false,
} = Astro.props as BikesCardProps;
changeLanguage(lang);
Expand All @@ -45,18 +57,21 @@ const formattedRelativeDate = relativeDateTimeFormatter({
>
<CarouselVue client:only items={imgs} />

<div class="mt-6">
<span class="block text-center text-gray-800 text-sm"
>Match Score: {matchScore}%</span
>
<div class="w-full bg-gray-200 rounded-full h-1.5">
<div
class="bg-gradient-to-r from-red-gradient-clr to-teal-gradient-clr h-full rounded-full"
style={{ width: `${matchScore}%` }}
>
{
showMatch && (
<div class="mt-6">
<span class="block text-center text-gray-800 text-sm">
Match Score: {matchScore}%
</span>
<div class="w-full bg-gray-200 rounded-full h-1.5">
<div
class="bg-gradient-to-r from-red-gradient-clr to-teal-gradient-clr h-full rounded-full"
style={{ width: `${matchScore}%` }}
/>
</div>
</div>
</div>
</div>
)
}
<div class="pb-2.5 border-b borde-gray-200">
<h3 class="text-xl font-bold mt-2.5">{brand}</h3>
<h4 class="text-gray-500 mt-1">{model}</h4>
Expand Down
95 changes: 77 additions & 18 deletions astro/src/components/sections/BikesSection.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import { t } from "i18next";
import SearchBikes from "@components/bikes/SearchBikes.astro";
import BaseContainer from "@components/base/BaseContainer.astro";
import BikesCard from "@components/cards/BikesCard.astro";
import BasePagination from "@components/base/BasePagination.astro";
import BikesList from "@components/bikes/BikesList.astro";
const imgArr = [
{
Expand All @@ -19,6 +19,81 @@ const imgArr = [
alt: "...3",
},
];
const bikesList = [
{
dateStr: "2022-05-28",
matchScore: 75,
brand: "Forme",
model: "Hooklow 2",
location: "Milano, Italy",
lang: "en",
imgs: imgArr,
},
{
dateStr: "2022-05-28",
matchScore: 75,
brand: "Forme",
model: "Hooklow 2",
location: "Milano, Italy",
lang: "en",
imgs: imgArr,
},
{
dateStr: "2022-05-28",
matchScore: 75,
brand: "Forme",
model: "Hooklow 2",
location: "Milano, Italy",
lang: "en",
imgs: imgArr,
},
{
dateStr: "2022-05-28",
matchScore: 75,
brand: "Forme",
model: "Hooklow 2",
location: "Milano, Italy",
lang: "en",
imgs: imgArr,
},
{
dateStr: "2022-05-28",
matchScore: 75,
brand: "Forme",
model: "Hooklow 2",
location: "Milano, Italy",
lang: "en",
imgs: imgArr,
},
{
dateStr: "2022-05-28",
matchScore: 75,
brand: "Forme",
model: "Hooklow 2",
location: "Milano, Italy",
lang: "en",
imgs: imgArr,
},
{
dateStr: "2022-05-28",
matchScore: 75,
brand: "Forme",
model: "Hooklow 2",
location: "Milano, Italy",
lang: "en",
imgs: imgArr,
},
{
dateStr: "2022-05-28",
matchScore: 75,
brand: "Forme",
model: "Hooklow 2",
location: "Milano, Italy",
lang: "en",
imgs: imgArr,
},
];
---

<section class="mt-10 pt-6 md:pt-8 pb-8 md:pb-10">
Expand All @@ -38,23 +113,7 @@ const imgArr = [

<SearchBikes lang="en" />

<div
class="my-4 md:my-10 grid gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4"
>
{
Array.from(Array(10).keys()).map(() => (
<BikesCard
dateStr="2022-05-28"
matchScore={75}
brand="Forme"
model="Hooklow 2"
location="Milano, Italy"
lang="en"
imgs={imgArr}
/>
))
}
</div>
<BikesList items={bikesList} />

<BasePagination />
</BaseContainer>
Expand Down

0 comments on commit aabc004

Please sign in to comment.