diff --git a/src/features/ui/components/modals/zaps-modal.tsx b/src/features/ui/components/modals/zaps-modal.tsx new file mode 100644 index 000000000..f562cd03b --- /dev/null +++ b/src/features/ui/components/modals/zaps-modal.tsx @@ -0,0 +1,87 @@ +import { List as ImmutableList } from 'immutable'; +import React, { useEffect, useMemo } from 'react'; +import { FormattedMessage } from 'react-intl'; + +import { fetchZaps } from 'soapbox/actions/interactions'; +import ScrollableList from 'soapbox/components/scrollable-list'; +import { Modal, Spinner, Text } from 'soapbox/components/ui'; +import AccountContainer from 'soapbox/containers/account-container'; +import { useAppDispatch, useAppSelector } from 'soapbox/hooks'; +import { shortNumberFormat } from 'soapbox/utils/numbers'; + +interface IAccountWithZaps { + id: string; + zap_comment: string; + zap_amount: number; +} + +interface IZapsModal { + onClose: (string: string) => void; + statusId: string; +} + +const ZapsModal: React.FC = ({ onClose, statusId }) => { + const dispatch = useAppDispatch(); + const zaps = useAppSelector((state) => state.user_lists.zapped_by.get(statusId)?.items); + + + const accounts = useMemo((): ImmutableList | undefined => { + if (!zaps) return; + + return zaps.map(({ account, zap_amount, zap_comment }) =>({ id: account, zap_amount, zap_comment })).flatten() as ImmutableList; + }, [zaps]); + + const fetchData = () => { + dispatch(fetchZaps(statusId)); + }; + + useEffect(() => { + fetchData(); + }, []); + + const onClickClose = () => { + onClose('ZAPS'); + }; + + let body; + + if (!zaps || !accounts) { + body = ; + } else { + const emptyMessage = ; + + body = ( + + {accounts.map((account) => { + return ( +
+ + {shortNumberFormat(account.zap_amount / 1000)} + + +
+ ); + }, + )} +
+ ); + } + + return ( + } + onClose={onClickClose} + > + {body} + + ); +}; + +export default ZapsModal;