Improve push notification banner to reappear after a set time
Update the push notification banner logic to dismiss for 7 days instead of indefinitely, and track dismissal using timestamps. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 23852c00-4779-460a-9e0c-d09fee4b6c92 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: 9df9e674-e5e7-4e30-8a1e-b07cb5483e58 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/f209e72a-0939-48fa-84fc-57854de71967/23852c00-4779-460a-9e0c-d09fee4b6c92/ICRgny1 Replit-Helium-Checkpoint-Created: true
This commit is contained in:
parent
354ea959ae
commit
5bb5773141
@ -5,6 +5,7 @@ import { useToast } from "@/hooks/use-toast";
|
||||
import { isPushSupported, getExistingSubscription, subscribeToPush } from "@/lib/push-utils";
|
||||
|
||||
const DISMISS_KEY = "folx-push-prompt-dismissed";
|
||||
const DISMISS_DAYS = 7;
|
||||
|
||||
export default function PushPromptBanner() {
|
||||
const [visible, setVisible] = useState(false);
|
||||
@ -12,9 +13,14 @@ export default function PushPromptBanner() {
|
||||
|
||||
useEffect(() => {
|
||||
if (!isPushSupported()) return;
|
||||
if (localStorage.getItem(DISMISS_KEY)) return;
|
||||
if (Notification.permission === "denied") return;
|
||||
|
||||
const dismissedAt = localStorage.getItem(DISMISS_KEY);
|
||||
if (dismissedAt) {
|
||||
const elapsed = Date.now() - parseInt(dismissedAt, 10);
|
||||
if (elapsed < DISMISS_DAYS * 24 * 60 * 60 * 1000) return;
|
||||
}
|
||||
|
||||
const timer = setTimeout(async () => {
|
||||
const sub = await getExistingSubscription();
|
||||
if (!sub) setVisible(true);
|
||||
@ -25,7 +31,7 @@ export default function PushPromptBanner() {
|
||||
|
||||
const dismiss = () => {
|
||||
setVisible(false);
|
||||
localStorage.setItem(DISMISS_KEY, "1");
|
||||
localStorage.setItem(DISMISS_KEY, Date.now().toString());
|
||||
};
|
||||
|
||||
const accept = async () => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user