Refactor CollectionCardComponent to improve code readability and fix loadingPlayground state handling

This commit is contained in:
anovazzi1 2024-04-26 13:40:54 -03:00
commit 2474cd348e

View file

@ -20,6 +20,10 @@ import {
} from "../ui/card"; } from "../ui/card";
import IOModal from "../../modals/IOModal"; import IOModal from "../../modals/IOModal";
import useFlowStore from "../../stores/flowStore"; import useFlowStore from "../../stores/flowStore";
import { set } from "lodash";
import LoadingComponent from "../loadingComponent";
import { f } from "million/dist/shared/million.9d4df3c1";
import Loading from "../ui/loading";
export default function CollectionCardComponent({ export default function CollectionCardComponent({
data, data,
@ -59,6 +63,7 @@ export default function CollectionCardComponent({
const setEdges = useFlowStore((state) => state.setEdges); const setEdges = useFlowStore((state) => state.setEdges);
const [openPlayground, setOpenPlayground] = useState(false); const [openPlayground, setOpenPlayground] = useState(false);
const setCurrentFlowId = useFlowsManagerStore((state) => state.setCurrentFlowId); const setCurrentFlowId = useFlowsManagerStore((state) => state.setCurrentFlowId);
const [loadingPlayground, setLoadingPlayground] = useState(false);
const name = data.is_component ? "Component" : "Flow"; const name = data.is_component ? "Component" : "Flow";
@ -373,6 +378,7 @@ export default function CollectionCardComponent({
{button && button} {button && button}
{playground && {playground &&
<Button <Button
disabled={loadingPlayground}
key={data.id} key={data.id}
tabIndex={-1} tabIndex={-1}
variant="outline" variant="outline"
@ -382,24 +388,32 @@ export default function CollectionCardComponent({
"playground-flow-button-" + data.id "playground-flow-button-" + data.id
} }
onClick={() => { onClick={() => {
setLoadingPlayground(true);
if (getFlowById(data.id)) { if (getFlowById(data.id)) {
setCurrentFlowId(data.id); setCurrentFlowId(data.id);
setOpenPlayground(true); setOpenPlayground(true);
setLoadingPlayground(false);
} }
else { else {
getFlowData().then((res) => { getFlowData().then((res) => {
setCurrentFlow(res); setCurrentFlow(res);
setOpenPlayground(true); setOpenPlayground(true);
setLoadingPlayground(false);
}); });
} }
}} }}
> >
{!loadingPlayground ?
<>
<IconComponent <IconComponent
name="ExternalLink" name="ExternalLink"
className="main-page-nav-button select-none" className="main-page-nav-button select-none"
/> />
Playground Playground
</>:
<Loading />
}
{openPlayground && < IOModal cleanOnClose={true} open={openPlayground} setOpen={setOpenPlayground}> {openPlayground && < IOModal cleanOnClose={true} open={openPlayground} setOpen={setOpenPlayground}>
<></> <></>
</IOModal>} </IOModal>}