Skip to content

Commit ea1042f

Browse files
Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 7055b39 commit ea1042f

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/app/portfolio/page.tsx

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

3-
import React, { useEffect, useState } from 'react'
3+
import React, { useEffect, useRef, useState } from 'react'
44
import Link from 'next/link'
55
import VideoPlayer from '@/components/video-player'
66
import PortfolioCard from '@/components/portfolio/PortfolioCard'
@@ -266,6 +266,7 @@ export default function Portfolio() {
266266
const [bannerVisible, setBannerVisible] = useState(false)
267267
const [activeModal, setActiveModal] = useState<string | null>(null)
268268
const [toastMessage, setToastMessage] = useState<string | null>(null)
269+
const toastTimeoutRef = useRef<number | null>(null)
269270

270271
useEffect(() => {
271272
setBannerVisible(true)
@@ -274,9 +275,24 @@ export default function Portfolio() {
274275
// Show toast notification (mirroring notyError from Laravel)
275276
const showToast = (message: string) => {
276277
setToastMessage(message)
277-
setTimeout(() => setToastMessage(null), 3000)
278+
if (toastTimeoutRef.current !== null) {
279+
clearTimeout(toastTimeoutRef.current)
280+
}
281+
const timeoutId = window.setTimeout(() => {
282+
setToastMessage(null)
283+
toastTimeoutRef.current = null
284+
}, 3000)
285+
toastTimeoutRef.current = timeoutId
278286
}
279287

288+
useEffect(() => {
289+
return () => {
290+
if (toastTimeoutRef.current !== null) {
291+
clearTimeout(toastTimeoutRef.current)
292+
}
293+
}
294+
}, [])
295+
280296
const handleReadMore = (item: (typeof portfolioItems)[0]) => {
281297
if (item.comingSoon) {
282298
showToast('Additional Details Coming soon.')

0 commit comments

Comments
 (0)