Skip to content

Commit

Permalink
feat: card is highlighted when the item was searched for by algolia
Browse files Browse the repository at this point in the history
  • Loading branch information
nsdonato committed Apr 1, 2024
1 parent 5bfd226 commit d825de3
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions components/card/card.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
'use client'

import { useEffect } from 'react'

import { PageItem } from '@/lib/db-types'
import { getFormattedIdentifier } from '@/lib/utils'

Expand All @@ -13,6 +17,21 @@ type CardProps = {
export const Card = ({ item }: CardProps) => {
const { cover, imgPlaceholder, titleCard, infoExtra, links, videos } = item

useEffect(() => {
const highlightedCard =
window.location.hash === `#${getFormattedIdentifier(item.imgPlaceholder)}`

if (highlightedCard) {
const card = document.getElementById(
getFormattedIdentifier(item.imgPlaceholder)
)
card?.classList.add('ring-accent')
setTimeout(() => {
card?.classList.remove('ring-accent')
}, 2000)
}
}, [item.imgPlaceholder])

return (
<div
className='card p-4 ring-1 bg-base-100 shadow-lg h-auto hover:scale-105 transition-transform'
Expand Down

0 comments on commit d825de3

Please sign in to comment.