Skip to content

Commit

Permalink
refactor: componentizing track
Browse files Browse the repository at this point in the history
  • Loading branch information
geekhadev committed Jan 17, 2024
1 parent dc27d9b commit dd748ba
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
22 changes: 22 additions & 0 deletions src/components/Track.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import Link from 'next/link'

const Track = ({ track: { id, slug, title, excerpt, cover, date, authorAvatar, authorName } }) => {
return (
<Link href={`/tracks/${slug}`} key={id} className="flex flex-col group">
<img src={cover} alt={title} width="330" height="170" className='rounded-2xl group-hover:scale-105 group-hover:rotate-1 transition' />
<dic className='flex flex-col gap-1'>
<h3 className="col-span-2 text-xl mt-4 font-bold flex flex-row items-center text-gray-200 text-balance">
{title}
</h3>
<p className="text-gray-400 text-balance">{excerpt}</p>
<div className='flex gap-2 items-center'>
{authorAvatar && <img className="size-6 rounded-full" src={authorAvatar} alt={authorName} />}
{date && <p className="text-gray-400 text-balance">{authorName}</p>}
{date && <p className="text-yellow-500 text-balance">Incia: {date}</p>}
</div>
</dic>
</Link>
)
}

export default Track
19 changes: 2 additions & 17 deletions src/components/TracksList.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Link from 'next/link'
import Track from '@/components/Track'

const TracksList = ({ title, badget, tracks }) => (
<section className="gap-4 py-6">
Expand All @@ -10,22 +10,7 @@ const TracksList = ({ title, badget, tracks }) => (
}
</h3>
<div className="grid grid-cols-3 gap-4 py-6">
{tracks.map(({ id, slug, title, excerpt, cover, date, authorAvatar, authorName }) => (
<Link href={`/tracks/${slug}`} key={id} className="flex flex-col group">
<img src={cover} alt={title} className='rounded-2xl group-hover:scale-105 group-hover:rotate-1 transition' />
<dic className='flex flex-col gap-1'>
<h3 className="col-span-2 text-xl mt-4 font-bold flex flex-row items-center text-gray-200 text-balance">
{title}
</h3>
<p className="text-gray-400 text-balance">{excerpt}</p>
<div className='flex gap-2 items-center'>
{authorAvatar && <img className="size-6 rounded-full" src={authorAvatar} alt={authorName} />}
{date && <p className="text-gray-400 text-balance">{authorName}</p>}
{date && <p className="text-yellow-500 text-balance">Incia: {date}</p>}
</div>
</dic>
</Link>
))}
{tracks.map((track) => <Track track={track} key={track.id} />)}
</div>
</section>
)
Expand Down

0 comments on commit dd748ba

Please sign in to comment.