Skip to content

Commit 8beb836

Browse files
committed
refactor(blog): updated blog-component & blog-related post section as per design
1 parent 336bd69 commit 8beb836

File tree

2 files changed

+10
-43
lines changed

2 files changed

+10
-43
lines changed

src/components/blocks/blog-component/blog-component.tsx

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22

3-
import { useState, useEffect } from 'react'
3+
import { useState } from 'react'
44

55
import { SearchIcon, ArrowRightIcon, CalendarDaysIcon } from 'lucide-react'
66

@@ -111,31 +111,6 @@ const Blog = ({ blogData = [] }: BlogProps) => {
111111
const uniqueCategories = [...new Set(nonFeaturedPosts.map(post => post.category))]
112112
const categories = ['All', ...uniqueCategories.sort()]
113113

114-
// Handle hash change to automatically switch tabs
115-
useEffect(() => {
116-
const handleHashChange = () => {
117-
const hash = window.location.hash
118-
119-
if (hash.startsWith('#category-')) {
120-
const category = hash.replace('#category-', '')
121-
122-
if (categories.includes(category)) {
123-
setSelectedTab(category)
124-
}
125-
}
126-
}
127-
128-
// Check hash on initial load
129-
handleHashChange()
130-
131-
// Listen for hash changes
132-
window.addEventListener('hashchange', handleHashChange)
133-
134-
return () => {
135-
window.removeEventListener('hashchange', handleHashChange)
136-
}
137-
}, [categories])
138-
139114
const handleTabChange = (tab: string) => {
140115
setSelectedTab(tab)
141116

src/components/blocks/blog-related-post/blog-related-post.tsx

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,50 +36,42 @@ const Blog = ({ relatedPosts }: { relatedPosts: BlogPost[] }) => {
3636
{/* Tabs and Search */}
3737
<div className='grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3'>
3838
{relatedPosts.map(post => (
39-
<div
39+
<a
40+
href={`/blog/${post.slug}`}
4041
key={post.id}
4142
className='group h-full cursor-pointer overflow-hidden shadow-none transition-all duration-300 hover:shadow-md'
4243
>
4344
<Card>
4445
<CardContent className='space-y-3.5'>
45-
<a href={`/blog/${post.slug}`} className='mb-6 block overflow-hidden rounded-lg sm:mb-12'>
46+
<div className='mb-6 overflow-hidden rounded-lg sm:mb-12'>
4647
<img
4748
src={post.imageUrl}
4849
alt={post.imageAlt}
4950
className='h-59.5 w-full object-cover transition-transform duration-300 group-hover:scale-105'
5051
/>
51-
</a>
52+
</div>
5253
<div className='flex items-center justify-between gap-1.5'>
5354
<div className='text-muted-foreground flex items-center gap-1.5'>
5455
<CalendarDaysIcon className='size-6' />
5556
<span>{post.pubDate}</span>
5657
</div>
57-
<Badge className='bg-primary/10 text-primary border-0 text-sm' asChild>
58-
<a href={`/#category-${post.category}`} className='hover:bg-primary/10!'>
59-
{post.category}
60-
</a>
61-
</Badge>
58+
<Badge className='bg-primary/10 text-primary border-0 text-sm'>{post.category}</Badge>
6259
</div>
63-
<a href={`/blog/${post.slug}`} className='block'>
64-
<h3 className='line-clamp-2 text-lg font-medium md:text-xl'>{post.title}</h3>
65-
</a>
60+
<h3 className='line-clamp-2 text-lg font-medium md:text-xl'>{post.title}</h3>
6661
<p className='text-muted-foreground line-clamp-2'>{post.description}</p>
6762
<div className='flex items-center justify-between'>
6863
<span className='text-sm font-medium'>{post.author}</span>
6964
<Button
7065
size='icon'
7166
className='group-hover:bg-primary! bg-background text-foreground hover:bg-primary! hover:text-primary-foreground group-hover:text-primary-foreground border group-hover:border-transparent hover:border-transparent'
72-
asChild
7367
>
74-
<a href={`/blog/${post.slug}`}>
75-
<ArrowRightIcon className='size-4 -rotate-45' />
76-
<span className='sr-only'>Read more: {post.title}</span>
77-
</a>
68+
<ArrowRightIcon className='size-4 -rotate-45' />
69+
<span className='sr-only'>Read more: {post.title}</span>
7870
</Button>
7971
</div>
8072
</CardContent>
8173
</Card>
82-
</div>
74+
</a>
8375
))}
8476
</div>
8577
</div>

0 commit comments

Comments
 (0)