import React, { useEffect } from 'react'; import { defineMessages, useIntl, FormattedMessage } from 'react-intl'; import { useDispatch } from 'react-redux'; import { Link } from 'react-router-dom'; import { createSelector } from 'reselect'; import { deleteList, fetchLists } from 'soapbox/actions/lists'; import { openModal } from 'soapbox/actions/modals'; import Icon from 'soapbox/components/icon'; import ScrollableList from 'soapbox/components/scrollable_list'; import { IconButton, Spinner } from 'soapbox/components/ui'; import { CardHeader, CardTitle } from 'soapbox/components/ui'; import { useAppSelector } from 'soapbox/hooks'; import Column from '../ui/components/column'; import NewListForm from './components/new_list_form'; import type { RootState } from 'soapbox/store'; const messages = defineMessages({ heading: { id: 'column.lists', defaultMessage: 'Lists' }, subheading: { id: 'lists.subheading', defaultMessage: 'Your lists' }, add: { id: 'lists.new.create', defaultMessage: 'Add list' }, deleteHeading: { id: 'confirmations.delete_list.heading', defaultMessage: 'Delete list' }, deleteMessage: { id: 'confirmations.delete_list.message', defaultMessage: 'Are you sure you want to permanently delete this list?' }, deleteConfirm: { id: 'confirmations.delete_list.confirm', defaultMessage: 'Delete' }, editList: { id: 'lists.edit', defaultMessage: 'Edit list' }, deleteList: { id: 'lists.delete', defaultMessage: 'Delete list' }, }); const getOrderedLists = createSelector([(state: RootState) => state.lists], lists => { if (!lists) { return lists; } return lists.toList().filter((item) => !!item).sort((a: any, b: any) => a.get('title').localeCompare(b.get('title'))); }); const Lists: React.FC = () => { const dispatch = useDispatch(); const intl = useIntl(); const lists = useAppSelector((state) => getOrderedLists(state)); useEffect(() => { dispatch(fetchLists()); }, []); if (!lists) { return ( ); } const handleEditClick = (id: number) => (e: React.MouseEvent) => { e.preventDefault(); dispatch(openModal('LIST_EDITOR', { listId: id })); }; const handleDeleteClick = (id: number) => (e: React.MouseEvent) => { e.preventDefault(); dispatch(openModal('CONFIRM', { heading: intl.formatMessage(messages.deleteHeading), message: intl.formatMessage(messages.deleteMessage), confirm: intl.formatMessage(messages.deleteConfirm), onConfirm: () => { dispatch(deleteList(id)); }, })); }; const emptyMessage = ; return (

{lists.map((list: any) => ( {list.title} ))}
); }; export default Lists;