Skip to content

Commit

Permalink
Update backend base URL and limit toast messages (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
csy070802 committed Dec 29, 2023
1 parent 0f27b67 commit 2c4f667
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -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
13 changes: 11 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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);
Expand All @@ -35,6 +35,15 @@ export default function App() {
</S.InfoText>
);
}

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 (
<>
<Routes>
Expand Down

0 comments on commit 2c4f667

Please sign in to comment.