2023-06-04 21:40:04 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) Contributors to the Suwayomi project
|
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
2023-08-14 21:43:06 +02:00
|
|
|
import { useEffect, useState } from 'react';
|
2023-06-04 21:40:04 +02:00
|
|
|
import { Droppable, DroppableProps } from 'react-beautiful-dnd';
|
|
|
|
|
|
|
|
|
|
// issue: https://github.com/atlassian/react-beautiful-dnd/issues/2399
|
|
|
|
|
// credit for fix: https://github.com/atlassian/react-beautiful-dnd/issues/2399#issuecomment-1175638194
|
|
|
|
|
export default function StrictModeDroppable({ children, ...props }: DroppableProps) {
|
|
|
|
|
const [enabled, setEnabled] = useState(false);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const animation = requestAnimationFrame(() => setEnabled(true));
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
cancelAnimationFrame(animation);
|
|
|
|
|
setEnabled(false);
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
if (!enabled) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <Droppable {...props}>{children}</Droppable>;
|
|
|
|
|
}
|