fix: info page card and map error states (#412)
This commit is contained in:
+26
-2
@@ -7,6 +7,7 @@ import mapData from '../assets/data/map-data.json'
|
|||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
style?: CSSProperties
|
style?: CSSProperties
|
||||||
|
error?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MapRecord {
|
interface MapRecord {
|
||||||
@@ -47,22 +48,27 @@ function addPins(map: DottedMap, pins: MapRecord[], color: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const mapPrecomputed = new DottedMap({ map: JSON.parse(mapData) })
|
const mapPrecomputed = new DottedMap({ map: JSON.parse(mapData) })
|
||||||
|
const mapNoPins = new DottedMap({ map: JSON.parse(mapData) })
|
||||||
addPins(mapPrecomputed, deduplicatedRecords, '#303030')
|
addPins(mapPrecomputed, deduplicatedRecords, '#303030')
|
||||||
|
|
||||||
const mapSvgOptions: DottedMapWithoutCountriesLib.SvgSettings = { shape: 'hexagon', radius: 0.21, color: '#dadada' }
|
const mapSvgOptions: DottedMapWithoutCountriesLib.SvgSettings = { shape: 'hexagon', radius: 0.21, color: '#dadada' }
|
||||||
|
|
||||||
export default function Card({ style }: Props): ReactElement {
|
export default function Card({ style, error }: Props): ReactElement {
|
||||||
const { peers } = useContext(Context)
|
const { peers } = useContext(Context)
|
||||||
const [map, setMap] = useState<string>(mapPrecomputed.getSVG(mapSvgOptions))
|
const [map, setMap] = useState<string>(mapPrecomputed.getSVG(mapSvgOptions))
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
// Display error map
|
||||||
|
if (error) setMap(mapNoPins.getSVG({ ...mapSvgOptions, color: '#eaeaea' }))
|
||||||
|
|
||||||
|
// Display just the base map without any connections
|
||||||
if (!peers) return
|
if (!peers) return
|
||||||
|
|
||||||
const points = findIntersection(fullMapDb, peers)
|
const points = findIntersection(fullMapDb, peers)
|
||||||
const mapNew = Object.create(mapPrecomputed)
|
const mapNew = Object.create(mapPrecomputed)
|
||||||
addPins(mapNew, points, '#09CA6C')
|
addPins(mapNew, points, '#09CA6C')
|
||||||
setMap(mapNew.getSVG(mapSvgOptions))
|
setMap(mapNew.getSVG(mapSvgOptions))
|
||||||
}, [peers])
|
}, [peers, error])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@@ -74,6 +80,7 @@ export default function Card({ style }: Props): ReactElement {
|
|||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignItems: 'center',
|
alignItems: 'center',
|
||||||
justifyContent: 'center',
|
justifyContent: 'center',
|
||||||
|
position: 'relative',
|
||||||
})}
|
})}
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
@@ -81,6 +88,23 @@ export default function Card({ style }: Props): ReactElement {
|
|||||||
src={`data:image/svg+xml;utf8,${encodeURIComponent(map)}`}
|
src={`data:image/svg+xml;utf8,${encodeURIComponent(map)}`}
|
||||||
style={{ maxWidth: '100%', maxHeight: '100%', objectFit: 'contain', flex: 1 }}
|
style={{ maxWidth: '100%', maxHeight: '100%', objectFit: 'contain', flex: 1 }}
|
||||||
/>
|
/>
|
||||||
|
{error && (
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="60"
|
||||||
|
height="60"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="#f44336"
|
||||||
|
strokeWidth="0"
|
||||||
|
strokeLinecap="round"
|
||||||
|
strokeLinejoin="round"
|
||||||
|
style={{ position: 'absolute', top: '50%', left: '50%', transform: 'translate(-50%, -50%)', opacity: 0.25 }}
|
||||||
|
>
|
||||||
|
<path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"></path>
|
||||||
|
<line stroke="#f3f3f3" strokeWidth="2" x1="12" y1="9" x2="12" y2="13"></line>
|
||||||
|
<line stroke="#f3f3f3" strokeWidth="2" x1="12" y1="17" x2="12.01" y2="17"></line>
|
||||||
|
</svg>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ export default function Status(): ReactElement {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'stretch', alignContent: 'stretch' }}>
|
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'stretch', alignContent: 'stretch' }}>
|
||||||
{status.all ? (
|
{status.all === 'OK' ? (
|
||||||
<Card
|
<Card
|
||||||
buttonProps={{ iconType: Search, children: 'Access Content', onClick: () => navigate(ROUTES.DOWNLOAD) }}
|
buttonProps={{ iconType: Search, children: 'Access Content', onClick: () => navigate(ROUTES.DOWNLOAD) }}
|
||||||
icon={<Globe />}
|
icon={<Globe />}
|
||||||
@@ -105,7 +105,7 @@ export default function Status(): ReactElement {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div style={{ height: '16px' }} />
|
<div style={{ height: '16px' }} />
|
||||||
<Map />
|
<Map error={status.topology.checkState !== 'OK'} />
|
||||||
<div style={{ height: '2px' }} />
|
<div style={{ height: '2px' }} />
|
||||||
<ExpandableListItem label="Connected peers" value={topology?.connected ?? '-'} />
|
<ExpandableListItem label="Connected peers" value={topology?.connected ?? '-'} />
|
||||||
<ExpandableListItem label="Population" value={topology?.population ?? '-'} />
|
<ExpandableListItem label="Population" value={topology?.population ?? '-'} />
|
||||||
|
|||||||
Reference in New Issue
Block a user