diff --git a/src/frontend/src/components/cardComponent/index.tsx b/src/frontend/src/components/cardComponent/index.tsx index 4578c5f21..b9c9bb46c 100644 --- a/src/frontend/src/components/cardComponent/index.tsx +++ b/src/frontend/src/components/cardComponent/index.tsx @@ -13,13 +13,28 @@ import { CardHeader, CardTitle, } from "../ui/card"; +import { FlowType } from "../../types/flow"; export const CardComponent = ({ flow, idx, removeFlow, setTabIndex, setActiveTab, +}: { + flow: FlowType; + idx: number; + removeFlow: (id: string) => void; + setTabIndex: (idx: number) => void; + setActiveTab: (tab: string) => void; }) => { + // flow has a style attribute + // if it is empty just get a random style + // if it is not empty use that style + // if it is not empty and it is not a valid style get a random style + + let emoji = flow.style?.emoji || "🤖"; + // get random tailwind color + let color = flow.style?.color || "bg-blue-400"; return ( @@ -28,10 +43,10 @@ export const CardComponent = ({ - {idx === 0 ? "🤖" : "🛠️"} + {emoji} {flow.name} diff --git a/src/frontend/src/pages/MainPage/index.tsx b/src/frontend/src/pages/MainPage/index.tsx index b4757132c..d5b351ca5 100644 --- a/src/frontend/src/pages/MainPage/index.tsx +++ b/src/frontend/src/pages/MainPage/index.tsx @@ -87,7 +87,7 @@ export default function HomePage() { const { dark, setDark } = useContext(darkContext); const [activeTab, setActiveTab] = useState("myflow"); const [rename, setRename] = useState(false); - const { notificationCenter, setNotificationCenter } = + const { notificationCenter, setNotificationCenter, setErrorData } = useContext(alertContext); useEffect(() => { //create the first flow @@ -96,9 +96,23 @@ export default function HomePage() { } }, [addFlow, flows.length, templates]); + function handleAddFlow() { + try { + addFlow(); + // saveFlowStyleInDataBase(); + } catch (err) { + setErrorData(err); + } + } + function handleSave(flow) { // Put your save logic here. - updateFlowInDatabase(flow); + try { + updateFlowInDatabase(flow); + // updateFlowStyleInDataBase(flow); + } catch (err) { + setErrorData(err); + } } return ( @@ -197,7 +211,7 @@ export default function HomePage() { { - addFlow(); + handleAddFlow(); }} > diff --git a/src/frontend/src/types/flow/index.ts b/src/frontend/src/types/flow/index.ts index 6c118aa49..3cfbee421 100644 --- a/src/frontend/src/types/flow/index.ts +++ b/src/frontend/src/types/flow/index.ts @@ -7,6 +7,7 @@ export type FlowType = { id: string; data: ReactFlowJsonObject; description: string; + style?: FlowStyleType; }; export type NodeType = { id: string; @@ -20,3 +21,9 @@ export type NodeDataType = { id: string; value: any; }; +// FlowStyleType is the type of the style object that is used to style the +// Flow card with an emoji and a color. +export type FlowStyleType = { + emoji: string; + color: string; +};