fix(market-card.tsx): change import statement to include useEffect from react to fix missing dependency warning

feat(market-card.tsx): add useEffect hook to set the initial value of 'added' state based on whether the flow is already saved or not
feat(market-card.tsx): add logic to handleInstall function to check if flowData.current exists before adding flow
feat(market-card.tsx): add logic to handleInstall function to fetch component data and create a new flow if flowData.current is null
This commit is contained in:
anovazzi1 2023-10-24 21:00:11 -03:00
commit 6ccb166417

View file

@ -1,5 +1,5 @@
import { Link, ToyBrick } from "lucide-react";
import { useContext, useRef, useState } from "react";
import { useContext, useEffect, useRef, useState } from "react";
import IconComponent from "../../../components/genericIconComponent";
import { Badge } from "../../../components/ui/badge";
import { Button } from "../../../components/ui/button";
@ -24,6 +24,10 @@ export const MarketCardComponent = ({ data }: { data: FlowComponent }) => {
const { addFlow } = useContext(TabsContext);
const flowData = useRef<FlowType>();
useEffect(() => {
setAdded(savedFlows.has(data.id) ? true : false);
}, [added]);
function handleAdd() {
getComponent(data.id).then(
(res) => {
@ -47,7 +51,16 @@ export const MarketCardComponent = ({ data }: { data: FlowComponent }) => {
}
function handleInstall() {
addFlow(true, flowData.current!);
if (flowData.current) {
addFlow(true, flowData.current!);
} else {
getComponent(data.id).then((res) => {
console.log(res);
const newFLow = cloneFLowWithParent(res, res.id, data.is_component);
flowData.current = newFLow;
addFlow(true, newFLow);
});
}
}
function handleFork(flowId: string, is_component: boolean) {