Skip to content

Commit

Permalink
Merge pull request #144 from keemsebin/feature#140
Browse files Browse the repository at this point in the history
Feature#140
  • Loading branch information
keemsebin committed Jun 6, 2024
2 parents dede696 + 24303ec commit cb58eb4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
31 changes: 31 additions & 0 deletions src/components/toast/ToasterWithMax.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React, { useEffect, useState } from 'react';
import toast, { Toaster, useToasterStore } from 'react-hot-toast';

export default function ToasterWithMax() {
const { toasts } = useToasterStore();
const [toastLimit, setToastLimit] = useState<number>(2);

useEffect(() => {
toasts
.filter((t) => t.visible)
.filter((_, i) => i >= toastLimit)
.forEach((t) => toast.dismiss(t.id));
}, [toasts, toastLimit]);

return (
<>
<Toaster
containerStyle={{
position: 'fixed',
maxHeight: '0.5rem',
}}
toastOptions={{
style: {
fontWeight: 600,
padding: '0.5rem',
},
}}
/>
</>
);
}
16 changes: 2 additions & 14 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Analytics } from '@vercel/analytics/react';
import { CookiesProvider } from 'react-cookie';
import { Toaster } from 'react-hot-toast';
import Layout from '@/components/layout';
import ToasterWithMax from '@/components/toast/ToasterWithMax';

const queryClient = new QueryClient({
defaultOptions: {
Expand Down Expand Up @@ -42,20 +43,7 @@ export default function App({ Component, pageProps }: AppProps) {
</QueryClientProvider>
</CookiesProvider>

<Toaster
containerStyle={{
position: 'fixed',
overflow: 'hidden',
maxHeight: '5rem',
}}
toastOptions={{
style: {
fontWeight: 600,
padding: '0.75rem 1rem',
marginTop: '0.5rem',
},
}}
/>
<ToasterWithMax />
</>
);
}

0 comments on commit cb58eb4

Please sign in to comment.