import { useEffect, useState, useCallback } from 'react'; import { FormattedMessage, useIntl, defineMessages } from 'react-intl'; import { isFulfilled } from '@reduxjs/toolkit'; import CircleIcon from '@/material-icons/400-24px/account_circle.svg?react'; import CloseIcon from '@/material-icons/400-24px/close.svg?react'; import { fetchCircles } from 'mastodon/actions/circles'; import { createCircle } from 'mastodon/actions/circles_typed'; import { apiGetAccountCircles, apiAddAccountToCircle, apiRemoveAccountFromCircle, } from 'mastodon/api/circles'; import type { ApiCircleJSON } from 'mastodon/api_types/circles'; 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 { getOrderedCircles } from 'mastodon/selectors/circles'; import { useAppDispatch, useAppSelector } from 'mastodon/store'; const messages = defineMessages({ newCircle: { id: 'circles.new_circle_name', defaultMessage: 'New circle name', }, createCircle: { id: 'circles.create', defaultMessage: 'Create', }, close: { id: 'lightbox.close', defaultMessage: 'Close', }, }); const CircleItem: 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 NewCircleItem: React.FC<{ onCreate: (circle: ApiCircleJSON) => 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(createCircle({ title })).then((result) => { if (isFulfilled(result)) { onCreate(result.payload); setTitle(''); } return ''; }); }, [setTitle, dispatch, onCreate, title]); return (