- Introduced `PageSeo` component for managing page metadata for social sharing. - Created Open Graph image templates using SVG and static fonts for better visual representation. - Implemented service alert management with functions to check active alerts and format route numbers. - Added utility functions for generating and watching alert validity. - Developed a script to generate Open Graph images dynamically based on page content. - Included tests for service alert functionalities to ensure correctness and reliability.
23 lines
872 B
TypeScript
23 lines
872 B
TypeScript
import { useEffect, useState } from 'react';
|
|
import type { ServiceAlert } from '@/lib/ridebus';
|
|
import { getActiveAlerts, watchAlertValidity } from '@/lib/serviceAlerts';
|
|
|
|
export function useActiveAlerts(alerts: ServiceAlert[], cityId: number) {
|
|
const [now, setNow] = useState(Date.now);
|
|
useEffect(() => {
|
|
const refresh = () => setNow(Date.now());
|
|
const refreshVisible = () => {
|
|
if (document.visibilityState === 'visible') refresh();
|
|
};
|
|
const stopWatching = watchAlertValidity(alerts, refresh);
|
|
document.addEventListener('visibilitychange', refreshVisible);
|
|
window.addEventListener('focus', refresh);
|
|
return () => {
|
|
stopWatching();
|
|
document.removeEventListener('visibilitychange', refreshVisible);
|
|
window.removeEventListener('focus', refresh);
|
|
};
|
|
}, [alerts]);
|
|
return getActiveAlerts(alerts, cityId, now);
|
|
}
|