Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frontend/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
VITE_BASE_URL=http://localhost:5173
VITE_API_HOST=http://127.0.0.1:7091
VITE_API_STREAMING=true

VITE_NOTIFICATION_TEXT="What's new in 0.14.0 — Changelog"
VITE_NOTIFICATION_LINK="#"
11 changes: 11 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"rehype-katex": "^7.0.1",
"remark-gfm": "^4.0.0",
"remark-math": "^6.0.0",
"sonner": "^2.0.7",
"tailwind-merge": "^3.3.1"
},
"devDependencies": {
Expand Down
23 changes: 6 additions & 17 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import useTokenAuth from './hooks/useTokenAuth';
import Navigation from './Navigation';
import PageNotFound from './PageNotFound';
import Setting from './settings';
import Notification from './components/Notification';
// import Notification from './components/Notification';

import { Toaster } from 'sonner';
import { NotificationToast } from './components/NotificationToast';

function AuthWrapper({ children }: { children: React.ReactNode }) {
const { isAuthLoading } = useTokenAuth();
Expand Down Expand Up @@ -48,32 +51,18 @@ function MainLayout() {
<Outlet />
</div>
<UploadToast />
<Toaster position="bottom-right" richColors />
<NotificationToast />
</div>
);
}
export default function App() {
const [, , componentMounted] = useDarkTheme();
const [showNotification, setShowNotification] = useState<boolean>(() => {
const saved = localStorage.getItem('showNotification');
return saved ? JSON.parse(saved) : true;
});
const notificationText = import.meta.env.VITE_NOTIFICATION_TEXT;
const notificationLink = import.meta.env.VITE_NOTIFICATION_LINK;
if (!componentMounted) {
return <div />;
}
return (
<div className="relative h-full overflow-hidden">
{notificationLink && notificationText && showNotification && (
<Notification
notificationText={notificationText}
notificationLink={notificationLink}
handleCloseNotification={() => {
setShowNotification(false);
localStorage.setItem('showNotification', 'false');
}}
/>
)}
<Routes>
<Route
element={
Expand Down
52 changes: 52 additions & 0 deletions frontend/src/components/NotificationToast.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { useEffect } from 'react';
import { toast } from 'sonner';

export function NotificationToast() {
useEffect(() => {
const message = import.meta.env.VITE_NOTIFICATION_TEXT;
const link = import.meta.env.VITE_NOTIFICATION_LINK;

console.log('Omar Emad , ', message, link);
if (!message) return;

const lastSeenNotification = localStorage.getItem('lastseennotification');
if (lastSeenNotification === `${message}/${link}`) return;
localStorage.setItem('lastseennotification', `${message}/${link}`);

toast.custom(
(t) => (
<div
onClick={() => toast.dismiss(t)}
className="flex cursor-pointer items-center justify-between gap-3 rounded-lg bg-[linear-gradient(90deg,rgba(57,0,134,0)_16.83%,#6222B7_53.02%,rgba(57,0,134,0)_87.5%),linear-gradient(90deg,#390086_0%,#6222B7_100%)] px-5 py-4 text-sm text-white transition select-none hover:opacity-90"
>
{link ? (
<a
href={link}
target="_blank"
rel="noopener noreferrer"
onClick={(e) => e.stopPropagation()}
className="underline hover:no-underline"
>
{message}
</a>
) : (
<span>{message}</span>
)}

<button
onClick={(e) => {
e.stopPropagation();
toast.dismiss(t);
}}
className="text-lg leading-none font-bold text-white/70 hover:text-white"
>
×
</button>
</div>
),
{ duration: 10000, position: 'bottom-right' }, // 10 seconds , measured in ms
);
}, []);

return null; // this component doesn’t render anything itself
}