-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathFailedImageProvider.jsx
More file actions
32 lines (27 loc) · 1.24 KB
/
FailedImageProvider.jsx
File metadata and controls
32 lines (27 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { useState, useCallback } from 'react';
import PropTypes from 'prop-types';
import FailedImageContext from './FailedImageContext';
import config from '../config/settings';
// SVG fallback with Material-UI Warning icon
// Uses default primary blue (#1967d2) - override entire image via config.fallbackImage if needed
const defaultFallback = 'data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" width="400" height="600"%3E%3Crect width="400" height="600" fill="%23f5f5f5"/%3E%3Cpath d="M 200 240 L 254 354 L 146 354 Z M 200 228 L 128 372 L 272 372 Z M 204.5 336 L 195.5 336 L 195.5 345 L 204.5 345 Z M 204.5 309 L 195.5 309 L 195.5 327 L 204.5 327 Z" fill="%231967d2"/%3E%3C/svg%3E';
export default function FailedImageProvider({ children }) {
const fallbackImage = config.fallbackImage || defaultFallback;
const [failedImages, setFailedImages] = useState(new Set());
const notifyFailure = useCallback((imageId) => {
setFailedImages((prev) => new Set(prev).add(imageId));
}, []);
return (
<FailedImageContext.Provider value={{
failedImages,
fallbackImage,
notifyFailure,
}}
>
{children}
</FailedImageContext.Provider>
);
}
FailedImageProvider.propTypes = {
children: PropTypes.node.isRequired,
};