Skip to content

Commit 52d6db6

Browse files
authored
Merge pull request #153 from oslabs-beta/dev
Dev
2 parents 705d446 + cef7dcc commit 52d6db6

File tree

2 files changed

+59
-19
lines changed

2 files changed

+59
-19
lines changed

client/src/App.tsx

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ const App = () => {
2323
return window.matchMedia('(prefers-color-scheme: dark)').matches;
2424
});
2525

26+
// Toast position state for responsive behavior
27+
const [toastPosition, setToastPosition] = useState('top-center');
28+
2629
// ----------------------------------------------------------
2730
// * USEEFFECT for light/dark mode toggle
2831
// ----------------------------------------------------------
@@ -36,6 +39,26 @@ const App = () => {
3639
}
3740
}, [isDark]);
3841

42+
// ----------------------------------------------------------
43+
// * USEEFFECT for responsive toast positioning
44+
// ----------------------------------------------------------
45+
useEffect(() => {
46+
const mediaQuery = window.matchMedia('(min-width: 640px)');
47+
48+
const updateToastPosition = (e) => {
49+
setToastPosition(e.matches ? 'bottom-right' : 'top-center');
50+
};
51+
52+
// Set initial position
53+
updateToastPosition(mediaQuery);
54+
55+
// Listen for screen size changes
56+
mediaQuery.addEventListener('change', updateToastPosition);
57+
58+
// Cleanup listener
59+
return () => mediaQuery.removeEventListener('change', updateToastPosition);
60+
}, []);
61+
3962
const toggleTheme = () => {
4063
setIsDark((prevIsDark) => !prevIsDark);
4164
};
@@ -61,20 +84,22 @@ const App = () => {
6184
</div>
6285
</SignedOut>
6386
<SignedIn>
87+
{/* SONNER TOAST NOTIFICATIONS - Moved outside to same stacking context as Header */}
88+
<Toaster
89+
theme={isDark ? 'dark' : 'light'}
90+
position={toastPosition}
91+
className="z-[60]" // Higher than header's z-50
92+
richColors={true}
93+
expand={false}
94+
duration={5000}
95+
closeButton={false}
96+
/>
97+
6498
{/* Create a fixed viewport container that starts from top (overlaps with header) */}
6599
<div className="fixed bottom-0 left-0 right-0 top-0 flex flex-col">
66100
{/* Scrollable content area with top padding to account for header */}
67101
<div className="flex-1 overflow-y-auto pb-24 pt-16">
68102
<div className="max-w-9xl mx-auto">
69-
{/* SONNER TOAST NOTIFICATIONS */}
70-
<Toaster
71-
theme={isDark ? 'dark' : 'light'}
72-
position="bottom-right"
73-
richColors={true}
74-
expand={false}
75-
duration={5000}
76-
closeButton={false}
77-
/>
78103
{/* SIMPLE WEBSOCKET TOAST NOTIFICATIONS */}
79104
<ToastNotifications />
80105
<Routes>

client/src/components/ToastNotifications.tsx

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@ interface K8sNotification {
2323

2424
const ToastNotifications = () => {
2525
useEffect(() => {
26-
console.log('[Toast] 🚀 Component mounted, attempting WebSocket connection...');
27-
console.log('[Toast] 🔗 Connecting to:', import.meta.env.VITE_API_URL || 'http://localhost:3000');
28-
26+
console.log(
27+
'[Toast] 🚀 Component mounted, attempting WebSocket connection...',
28+
);
29+
console.log(
30+
'[Toast] 🔗 Connecting to:',
31+
import.meta.env.VITE_API_URL || 'http://localhost:3000',
32+
);
33+
2934
// Connect to WebSocket server with more options
3035
const socket = io(import.meta.env.VITE_API_URL || 'http://localhost:3000', {
3136
reconnection: true,
@@ -45,7 +50,10 @@ const ToastNotifications = () => {
4550
});
4651

4752
socket.on('disconnect', (reason) => {
48-
console.log('[Toast] ❌ Disconnected from WebSocket server. Reason:', reason);
53+
console.log(
54+
'[Toast] ❌ Disconnected from WebSocket server. Reason:',
55+
reason,
56+
);
4957
toast.warning('Disconnected from monitoring server');
5058
});
5159

@@ -63,13 +71,17 @@ const ToastNotifications = () => {
6371
title: notification.title,
6472
severity: notification.metadata.severity,
6573
namespace: notification.metadata.namespace,
66-
pod: notification.metadata.pod
74+
pod: notification.metadata.pod,
6775
});
6876

6977
// Create toast message
7078
const message = `${notification.title}\n${notification.metadata.namespace}/${notification.metadata.pod}\n${notification.message}`;
71-
72-
console.log('[Toast] 🍞 Showing toast for:', notification.type, notification.metadata.severity);
79+
80+
console.log(
81+
'[Toast] 🍞 Showing toast for:',
82+
notification.type,
83+
notification.metadata.severity,
84+
);
7385

7486
// Show toast based on type and severity
7587
switch (notification.type) {
@@ -98,7 +110,10 @@ const ToastNotifications = () => {
98110
toast.info(message, { duration: 5000 });
99111
break;
100112
default:
101-
console.log('[Toast] ❓ Unknown notification type:', notification.type);
113+
console.log(
114+
'[Toast] ❓ Unknown notification type:',
115+
notification.type,
116+
);
102117
toast.info(message, { duration: 5000 });
103118
}
104119
});
@@ -113,9 +128,9 @@ const ToastNotifications = () => {
113128
console.log('[Toast] 🧪 Connection status check:');
114129
console.log('[Toast] 🔌 Connected:', socket.connected);
115130
console.log('[Toast] 🆔 Socket ID:', socket.id);
116-
131+
117132
// Test toast to make sure Sonner is working
118-
toast.info('Toast component loaded and ready!');
133+
toast.info('Coffybara loaded and ready!');
119134
}, 2000);
120135

121136
// Cleanup on unmount

0 commit comments

Comments
 (0)