Remove notification system and fix data refresh issues

- Removed NotificationPanel component and related files
- Removed notifications API endpoint and utils
- Fixed data refresh functionality with cache-busting
- Added refreshing state with better UI feedback
- Added no-cache headers to API endpoint
- Improved refresh button with loading state
This commit is contained in:
Aram Chia Sarafian
2025-07-13 19:12:00 -07:00
parent ba831bf15a
commit 5206aceded
7 changed files with 128 additions and 502 deletions

View File

@ -3,7 +3,6 @@
import dynamic from 'next/dynamic';
import { useState, useEffect } from 'react';
import LibraryList from './components/LibraryList';
import NotificationPanel from './components/NotificationPanel';
// Dynamically import the map component to avoid SSR issues
const MapComponent = dynamic(() => import('./components/MapComponent'), {
@ -27,6 +26,7 @@ interface ApiResponse {
export default function Home() {
const [locations, setLocations] = useState<LocationData[]>([]);
const [loading, setLoading] = useState(true);
const [refreshing, setRefreshing] = useState(false);
const [error, setError] = useState<string | null>(null);
const [lastUpdated, setLastUpdated] = useState<string>('');
// Start with menu collapsed only on mobile
@ -42,10 +42,22 @@ export default function Home() {
fetchAvailability();
}, []);
const fetchAvailability = async () => {
const fetchAvailability = async (isRefresh = false) => {
try {
setLoading(true);
const response = await fetch('/api/availability');
if (isRefresh) {
setRefreshing(true);
} else {
setLoading(true);
}
setError(null);
// Add cache-busting parameter to ensure fresh data
const timestamp = new Date().getTime();
const response = await fetch(`/api/availability?t=${timestamp}`, {
cache: 'no-cache',
headers: {
'Cache-Control': 'no-cache',
},
});
if (!response.ok) {
throw new Error('Failed to fetch data');
}
@ -56,7 +68,11 @@ export default function Home() {
} catch (err) {
setError(err instanceof Error ? err.message : 'Unknown error');
} finally {
setLoading(false);
if (isRefresh) {
setRefreshing(false);
} else {
setLoading(false);
}
}
};
@ -111,8 +127,6 @@ export default function Home() {
</div>
</div>
<NotificationPanel locations={locations} />
{lastUpdated && (
<p style={{ fontSize: '12px', color: '#666', marginTop: '10px' }}>
Last updated: {new Date(lastUpdated).toLocaleString()}
@ -120,19 +134,20 @@ export default function Home() {
)}
<button
onClick={fetchAvailability}
onClick={() => fetchAvailability(true)}
disabled={refreshing}
style={{
marginTop: '10px',
padding: '8px 16px',
backgroundColor: '#007cba',
backgroundColor: refreshing ? '#ccc' : '#007cba',
color: 'white',
border: 'none',
borderRadius: '4px',
cursor: 'pointer',
cursor: refreshing ? 'not-allowed' : 'pointer',
width: '100%',
}}
>
Refresh Data
{refreshing ? 'Refreshing...' : 'Refresh Data'}
</button>
</>
)}