From 4f1c690f6c01120813417f023033929b043010b6 Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Mon, 5 May 2025 19:48:14 +0600 Subject: [PATCH] fix: hide the announcement for 3 days --- .../SQLCourse/CourseAnnouncement.tsx | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/components/SQLCourse/CourseAnnouncement.tsx b/src/components/SQLCourse/CourseAnnouncement.tsx index 3f778a35d..8a9d32e0b 100644 --- a/src/components/SQLCourse/CourseAnnouncement.tsx +++ b/src/components/SQLCourse/CourseAnnouncement.tsx @@ -2,10 +2,22 @@ import { Database, X } from 'lucide-react'; import { useState, useEffect } from 'react'; import { cn } from '../../lib/classname'; +const COURSE_ANNOUNCEMENT_STORAGE_KEY = '__course_announcement_closed_at__'; + export function CourseAnnouncement() { const [isVisible, setIsVisible] = useState(false); useEffect(() => { + const closedAt = Number( + localStorage.getItem(COURSE_ANNOUNCEMENT_STORAGE_KEY) || '0', + ); + + // only show if the closed at passed 3 days ago + const shouldShow = closedAt < Date.now(); + if (!shouldShow) { + return; + } + const timer = setTimeout(() => setIsVisible(true), 5000); return () => clearTimeout(timer); }, []); @@ -14,7 +26,7 @@ export function CourseAnnouncement() {
@@ -26,10 +38,12 @@ export function CourseAnnouncement() { Announcing our SQL course - + Start Learning Visit @@ -38,9 +52,15 @@ export function CourseAnnouncement() {