fix: Clear blocks modal search input when closing the modal (#2501)

This commit is contained in:
Elliot Lintz
2023-04-17 17:26:36 +02:00
committed by GitHub
parent 6ceb791891
commit 0f8051b577

View File

@@ -23,9 +23,20 @@ export const BlocksDrawer: React.FC<Props> = (props) => {
const [searchTerm, setSearchTerm] = useState('');
const [filteredBlocks, setFilteredBlocks] = useState(blocks);
const { closeModal } = useModal();
const { closeModal, modalState } = useModal();
const [isModalOpen, setIsModalOpen] = useState(false);
const { t, i18n } = useTranslation('fields');
useEffect(() => {
setIsModalOpen(Boolean(modalState[drawerSlug]?.isOpen));
}, [modalState, drawerSlug]);
useEffect(() => {
if (!isModalOpen) {
setSearchTerm('');
}
}, [isModalOpen]);
useEffect(() => {
const matchingBlocks = blocks.reduce((matchedBlocks, block) => {
if (block.slug.toLowerCase().indexOf(searchTerm.toLowerCase()) !== -1) matchedBlocks.push(block);