From 7e504ebbdd0b7c38deae9d41229b40af776ae089 Mon Sep 17 00:00:00 2001 From: dialmedu Date: Wed, 29 Nov 2023 00:09:23 -0500 Subject: [PATCH] add select UI Component and check options --- frontend/src/App.tsx | 2 + .../src/components/OutputSettingsSection.tsx | 101 +++++++++++++++++- frontend/src/types.ts | 6 ++ 3 files changed, 107 insertions(+), 2 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 0941a8b..060a6f3 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -25,6 +25,7 @@ import { CSSOption, OutputSettings, JSFrameworkOption, + UIComponentOption, } from "./types"; import { IS_RUNNING_ON_CLOUD } from "./config"; import { PicoBadge } from "./components/PicoBadge"; @@ -57,6 +58,7 @@ function App() { const [outputSettings, setOutputSettings] = useState({ css: CSSOption.TAILWIND, js: JSFrameworkOption.VANILLA, + components: UIComponentOption.HTML, }); const [shouldIncludeResultImage, setShouldIncludeResultImage] = useState(false); diff --git a/frontend/src/components/OutputSettingsSection.tsx b/frontend/src/components/OutputSettingsSection.tsx index fd76281..8f4200a 100644 --- a/frontend/src/components/OutputSettingsSection.tsx +++ b/frontend/src/components/OutputSettingsSection.tsx @@ -5,7 +5,7 @@ import { SelectItem, SelectTrigger, } from "./ui/select"; -import { CSSOption, JSFrameworkOption, OutputSettings } from "../types"; +import { CSSOption, UIComponentOption, JSFrameworkOption, OutputSettings } from "../types"; import { Accordion, AccordionContent, @@ -14,6 +14,7 @@ import { } from "./ui/accordion"; import { capitalize } from "../lib/utils"; import toast from "react-hot-toast"; +import { useEffect } from "react"; function displayCSSOption(option: CSSOption) { switch (option) { @@ -54,6 +55,7 @@ function OutputSettingsSection({ outputSettings, setOutputSettings }: Props) { return { css: CSSOption.TAILWIND, js: JSFrameworkOption.REACT, + components: UIComponentOption.HTML }; } else { return { @@ -69,6 +71,7 @@ function OutputSettingsSection({ outputSettings, setOutputSettings }: Props) { setOutputSettings(() => ({ css: CSSOption.TAILWIND, js: value as JSFrameworkOption, + components: UIComponentOption.HTML })); } else { setOutputSettings((prev) => ({ @@ -78,6 +81,80 @@ function OutputSettingsSection({ outputSettings, setOutputSettings }: Props) { } }; + const onUIComponentOptionChange = (value: string) => { + if (value === UIComponentOption.IONIC) { + setOutputSettings(() => ({ + css: CSSOption.TAILWIND, + js: JSFrameworkOption.VANILLA, + components: value as UIComponentOption + })); + } else { + setOutputSettings((prev) => ({ + ...prev, + components: value as UIComponentOption, + })); + } + }; + + + const checkUIComponentOptionOrDefault = (valueItem: UIComponentOption ) : UIComponentOption => { + switch (valueItem) { + case UIComponentOption.IONIC: + if (outputSettings.js != JSFrameworkOption.VANILLA || outputSettings.css != CSSOption.TAILWIND) { + return UIComponentOption.HTML + } + } + return valueItem; + } + + const checkCSSOptionOrDefault = (valueItem: CSSOption ) : CSSOption => { + switch (valueItem) { + default: + return valueItem; + } + } + + const checkJSFrameworkOptionOrDefault = (valueItem: JSFrameworkOption ) : JSFrameworkOption => { + switch (valueItem) { + case JSFrameworkOption.REACT: + if(outputSettings.css != CSSOption.TAILWIND) { + return JSFrameworkOption.VANILLA + } + break; + } + return valueItem; + } + + useEffect(() => { + checkOutputSettingsOptions(); + }, [outputSettings]); + + const checkOutputSettingsOptions = () => { + if ( isHiddenOption(outputSettings.css) || isHiddenOption(outputSettings.js) || isHiddenOption(outputSettings.components)) + { + setOutputSettings((prev) => { + return { + css: checkCSSOptionOrDefault(prev.css), + js: checkJSFrameworkOptionOrDefault(prev.js), + components: checkUIComponentOptionOrDefault(prev.components), + }; + }) + } + }; + + const isHiddenOption = ( option : CSSOption| JSFrameworkOption | UIComponentOption ) : boolean => { + if (Object.values(CSSOption).includes(option as CSSOption)){ + return checkCSSOptionOrDefault(option as CSSOption) != option + } + if (Object.values(JSFrameworkOption).includes(option as JSFrameworkOption)){ + return checkJSFrameworkOptionOrDefault(option as JSFrameworkOption) != option + } + if (Object.values(UIComponentOption).includes(option as UIComponentOption)){ + return checkUIComponentOptionOrDefault(option as UIComponentOption) != option + } + return true + } + return ( @@ -113,11 +190,31 @@ function OutputSettingsSection({ outputSettings, setOutputSettings }: Props) { Vanilla - React + React +
+ Component Library + +
+
+ Output: {outputSettings.js} + {outputSettings.css} + {outputSettings.components} +
diff --git a/frontend/src/types.ts b/frontend/src/types.ts index 964ad5a..0963f32 100644 --- a/frontend/src/types.ts +++ b/frontend/src/types.ts @@ -14,9 +14,15 @@ export enum JSFrameworkOption { VUE = "vue", } +export enum UIComponentOption { + HTML = 'HTML', + IONIC = 'ionic' +} + export interface OutputSettings { css: CSSOption; js: JSFrameworkOption; + components: UIComponentOption; } export interface Settings {