2019-06-22 23:45:51 +00:00
|
|
|
import React from 'react';
|
2019-06-12 06:12:03 +00:00
|
|
|
import MessageBox from '@/components/MessageBox';
|
2019-06-22 23:45:51 +00:00
|
|
|
import { State, useStoreState } from 'easy-peasy';
|
|
|
|
import { ApplicationState } from '@/state/types';
|
2019-06-12 06:12:03 +00:00
|
|
|
|
|
|
|
type Props = Readonly<{
|
2019-06-16 23:57:57 +00:00
|
|
|
spacerClass?: string;
|
2019-06-22 23:45:51 +00:00
|
|
|
withBottomSpace?: boolean;
|
2019-06-12 06:12:03 +00:00
|
|
|
}>;
|
|
|
|
|
2019-06-22 23:45:51 +00:00
|
|
|
export default ({ withBottomSpace, spacerClass }: Props) => {
|
|
|
|
const flashes = useStoreState((state: State<ApplicationState>) => state.flashes.items);
|
2019-06-12 06:12:03 +00:00
|
|
|
|
2019-06-22 23:45:51 +00:00
|
|
|
if (flashes.length === 0) {
|
|
|
|
return null;
|
2019-06-12 06:12:03 +00:00
|
|
|
}
|
|
|
|
|
2019-06-22 23:45:51 +00:00
|
|
|
// noinspection PointlessBooleanExpressionJS
|
|
|
|
return (
|
|
|
|
<div className={withBottomSpace === false ? undefined : 'mb-2'}>
|
|
|
|
{
|
|
|
|
flashes.map((flash, index) => (
|
|
|
|
<React.Fragment key={flash.id || flash.type + flash.message}>
|
|
|
|
{index > 0 && <div className={spacerClass || 'mt-2'}></div>}
|
|
|
|
<MessageBox type={flash.type} title={flash.title}>
|
|
|
|
{flash.message}
|
|
|
|
</MessageBox>
|
|
|
|
</React.Fragment>
|
|
|
|
))
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|