[Glitch] Fix WebUI crashing when SVG support is disabled

Port 7f203d6a7b to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
th-downstream
Claire 4 years ago
parent 5a89279d20
commit 847bc13838

@ -2,10 +2,35 @@
import React from 'react'; import React from 'react';
import { Sparklines, SparklinesCurve } from 'react-sparklines'; import { Sparklines, SparklinesCurve } from 'react-sparklines';
import { FormattedMessage } from 'react-intl'; import { FormattedMessage } from 'react-intl';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes'; import ImmutablePropTypes from 'react-immutable-proptypes';
import Permalink from './permalink'; import Permalink from './permalink';
import ShortNumber from 'flavours/glitch/components/short_number'; import ShortNumber from 'flavours/glitch/components/short_number';
class SilentErrorBoundary extends React.Component {
static propTypes = {
children: PropTypes.node,
};
state = {
error: false,
};
componentDidCatch () {
this.setState({ error: true });
}
render () {
if (this.state.error) {
return null;
}
return this.props.children;
}
}
/** /**
* Used to render counter of how much people are talking about hashtag * Used to render counter of how much people are talking about hashtag
* *
@ -51,17 +76,19 @@ const Hashtag = ({ hashtag }) => (
</div> </div>
<div className='trends__item__sparkline'> <div className='trends__item__sparkline'>
<Sparklines <SilentErrorBoundary>
width={50} <Sparklines
height={28} width={50}
data={hashtag height={28}
.get('history') data={hashtag
.reverse() .get('history')
.map((day) => day.get('uses')) .reverse()
.toArray()} .map((day) => day.get('uses'))
> .toArray()}
<SparklinesCurve style={{ fill: 'none' }} /> >
</Sparklines> <SparklinesCurve style={{ fill: 'none' }} />
</Sparklines>
</SilentErrorBoundary>
</div> </div>
</div> </div>
); );

Loading…
Cancel
Save