import { useEffect, useState, useCallback } from 'react'; import { FormattedMessage, useIntl, defineMessages } from 'react-intl'; import { isFulfilled } from '@reduxjs/toolkit'; import CloseIcon from '@/material-icons/400-24px/close.svg?react'; import ListAltIcon from '@/material-icons/400-24px/list_alt.svg?react'; import { fetchLists } from 'mastodon/actions/lists'; import { createList } from 'mastodon/actions/lists_typed'; import { apiGetAccountLists, apiAddAccountToList, apiRemoveAccountFromList, } from 'mastodon/api/lists'; import type { ApiListJSON } from 'mastodon/api_types/lists'; import { Button } from 'mastodon/components/button'; import { CheckBox } from 'mastodon/components/check_box'; import { Icon } from 'mastodon/components/icon'; import { IconButton } from 'mastodon/components/icon_button'; import { getOrderedLists } from 'mastodon/selectors/lists'; import { useAppDispatch, useAppSelector } from 'mastodon/store'; const messages = defineMessages({ newList: { id: 'lists.new_list_name', defaultMessage: 'New list name', }, createList: { id: 'lists.create', defaultMessage: 'Create', }, close: { id: 'lightbox.close', defaultMessage: 'Close', }, }); const ListItem: React.FC<{ id: string; title: string; checked: boolean; onChange: (id: string, checked: boolean) => void; }> = ({ id, title, checked, onChange }) => { const handleChange = useCallback( (e: React.ChangeEvent) => { onChange(id, e.target.checked); }, [id, onChange], ); return ( // eslint-disable-next-line jsx-a11y/label-has-associated-control ); }; const NewListItem: React.FC<{ onCreate: (list: ApiListJSON) => void; }> = ({ onCreate }) => { const intl = useIntl(); const dispatch = useAppDispatch(); const [title, setTitle] = useState(''); const handleChange = useCallback( ({ target: { value } }: React.ChangeEvent) => { setTitle(value); }, [setTitle], ); const handleSubmit = useCallback(() => { if (title.trim().length === 0) { return; } void dispatch(createList({ title })).then((result) => { if (isFulfilled(result)) { onCreate(result.payload); setTitle(''); } return ''; }); }, [setTitle, dispatch, onCreate, title]); return (