From 2c4f667a26fce8af239d5775bdcaf48873158afb Mon Sep 17 00:00:00 2001 From: Chltjdbs <130429968+csy070802@users.noreply.github.com> Date: Fri, 29 Dec 2023 20:48:00 +0900 Subject: [PATCH] Update backend base URL and limit toast messages (#128) --- .env | 4 ++-- src/App.tsx | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.env b/.env index f4cee57..dc5ec44 100644 --- a/.env +++ b/.env @@ -1,8 +1,8 @@ # PRODUCTION -# VITE_APP_BACKEND_BASEURL=https://api.tmpf.me +VITE_APP_BACKEND_BASEURL=https://api.tmpf.me # DEV # VITE_APP_BACKEND_BASEURL=https://dev.tmpf.me # LOCAL DEV -VITE_APP_BACKEND_BASEURL=http://localhost:5000 +# VITE_APP_BACKEND_BASEURL=http://localhost:5000 diff --git a/src/App.tsx b/src/App.tsx index f86e766..267e035 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,6 +1,6 @@ import { Outlet, Route, Routes, useNavigate } from 'react-router-dom'; import { useState, useEffect } from 'react'; -import { Toaster } from 'react-hot-toast'; +import toast, { Toaster, useToasterStore } from "react-hot-toast"; import { Navbar } from './components'; import * as S from './styles/app'; import { Analytics } from '@vercel/analytics/react'; @@ -14,7 +14,7 @@ async function checkServerStatus() { url: `${import.meta.env.VITE_APP_BACKEND_BASEURL}`, }); } - +const TOAST_LIMIT = 2; export default function App() { const navigate = useNavigate(); const [serverDown, setServerDown] = useState(false); @@ -35,6 +35,15 @@ export default function App() { ); } + + const { toasts } = useToasterStore(); + useEffect(() => { + toasts + .filter((t) => t.visible) // Only consider visible toasts + .filter((_, i) => i >= TOAST_LIMIT) // Is toast index over limit + .forEach((t) => toast.dismiss(t.id)); // Dismiss – Use toast.remove(t.id) removal without animation + }, [toasts]); + return ( <>