bigbuffet-rw/app/soapbox/features/ui/components/favourites_modal.tsx
marcin mikołajczak 1e74c6d3d7 TypeScript, FC, styles and fixes
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
2022-05-28 18:03:19 +02:00

62 lines
1.6 KiB
TypeScript

import React, { useEffect } from 'react';
import { FormattedMessage } from 'react-intl';
import { fetchFavourites } from 'soapbox/actions/interactions';
import ScrollableList from 'soapbox/components/scrollable_list';
import { Modal, Spinner } from 'soapbox/components/ui';
import AccountContainer from 'soapbox/containers/account_container';
import { useAppDispatch, useAppSelector } from 'soapbox/hooks';
interface IFavouritesModal {
onClose: (type: string) => void,
statusId: string,
}
const FavouritesModal: React.FC<IFavouritesModal> = ({ onClose, statusId }) => {
const dispatch = useAppDispatch();
const accountIds = useAppSelector((state) => state.user_lists.getIn(['favourited_by', statusId]));
const fetchData = () => {
dispatch(fetchFavourites(statusId));
};
useEffect(() => {
fetchData();
}, []);
const onClickClose = () => {
onClose('FAVOURITES');
};
let body;
if (!accountIds) {
body = <Spinner />;
} else {
const emptyMessage = <FormattedMessage id='empty_column.favourites' defaultMessage='No one has liked this post yet. When someone does, they will show up here.' />;
body = (
<ScrollableList
scrollKey='favourites'
emptyMessage={emptyMessage}
itemClassName='pb-3'
>
{accountIds.map((id: string) =>
<AccountContainer key={id} id={id} />,
)}
</ScrollableList>
);
}
return (
<Modal
title={<FormattedMessage id='column.favourites' defaultMessage='Likes' />}
onClose={onClickClose}
>
{body}
</Modal>
);
};
export default FavouritesModal;