Skip to content

Commit a3537aa

Browse files
committed
Better toast.
1 parent d685f0d commit a3537aa

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

app/dismiss-button.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use client';
2+
3+
import Cookies from 'js-cookie';
4+
import { useRouter } from 'next/navigation';
5+
6+
export default function DismissButton() {
7+
const router = useRouter();
8+
9+
return (
10+
<button
11+
className="contents underline text-blue-600"
12+
onClick={() => {
13+
Cookies.set('template-banner-hidden', 'true');
14+
router.refresh();
15+
}}
16+
>
17+
Dismiss →
18+
</button>
19+
);
20+
}

app/toast.tsx

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,15 @@
1-
'use client';
2-
3-
import { useState, useEffect } from 'react';
4-
import Cookies from 'js-cookie';
1+
import { cookies } from 'next/headers';
2+
import DismissButton from './dismiss-button';
53

64
export default function Toast() {
7-
const [bannerHidden, setBannerHidden] = useState(true);
8-
9-
useEffect(() => {
10-
setBannerHidden(Cookies.get('template-banner-hidden') === 'true');
11-
}, []);
5+
const cookieStore = cookies();
6+
const isHidden = cookieStore.get('template-banner-hidden');
127

13-
return bannerHidden ? null : (
8+
return isHidden ? null : (
149
<div className="sticky rounded-2xl w-11/12 sm:w-[581px] h-40 sm:h-[80px] p-0.5 z-10 bottom-10 left-0 right-0 mx-auto">
1510
<div className="rounded-[14px] w-full h-full bg-gray-50 border border-gray-200 flex flex-col sm:flex-row items-center justify-center sm:justify-between space-y-3 sm:space-y-0 px-5">
1611
<p className="text-black text-[13px] font-mono w-[304px] h-10 flex items-center justify-center p-3">
17-
Get started with Next.js and Vercel instantly.{' '}
18-
<button
19-
className="contents underline text-blue-600"
20-
onClick={() => {
21-
setBannerHidden(true);
22-
Cookies.set('template-banner-hidden', 'true');
23-
}}
24-
>
25-
Dismiss →
26-
</button>
12+
Get started with Next.js and Vercel instantly. <DismissButton />
2713
</p>
2814
<a
2915
className="text-white text-[13px] font-mono bg-black hover:bg-gray-700 transition-all rounded-md w-[220px] h-10 flex items-center justify-center whitespace-nowrap"

0 commit comments

Comments
 (0)