diff --git a/src/App.jsx b/src/App.jsx index 7413e5d..a3bd4f2 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -131,10 +131,10 @@ function App() { const [darkMode, setDarkMode] = useState(true); const [isPortrait, setIsPortrait] = useState(window.innerHeight > window.innerWidth); const [changed, setChanged] = useState(false); - const [buttonVariant, setButtonVariant] = useState('outlined'); + const [componentVariant, setComponentVariant] = useState('outlined'); useEffect(() => { - setButtonVariant(darkMode ? 'outlined' : 'contained'); + setComponentVariant(darkMode ? 'outlined' : 'contained'); }, [darkMode]); // Prevent page reload @@ -162,6 +162,13 @@ function App() { return () => window.removeEventListener('resize', handleResize); }, []); + useEffect(() => { + const cachedTheme = localStorage.getItem('darkMode'); + if (cachedTheme !== null) { + setDarkMode(cachedTheme === 'true'); + } + }, []); + // Check if inputs are updated useEffect(() => { if (JSON.stringify(inputs) === JSON.stringify(base)) { @@ -227,7 +234,6 @@ function App() { { @@ -103,7 +103,6 @@ function Inputs({ darkMode, buttonVariant, changed, setChanged, errors, setError - + - + diff --git a/src/components/Inputs/Arguments.jsx b/src/components/Inputs/Arguments.jsx index be41833..94b2e78 100644 --- a/src/components/Inputs/Arguments.jsx +++ b/src/components/Inputs/Arguments.jsx @@ -13,7 +13,7 @@ import Button from '@mui/material/Button'; import Typography from '@mui/material/Typography'; // Arguments component for managing input arguments -function Arguments({ buttonVariant, errors, setErrors, inputs, setInputs }) { +function Arguments({ darkMode, errors, setErrors, inputs, setInputs }) { // Check if there are duplicate names among the input arguments function hasDuplicateNames(data) { const names = data.map(obj => obj.name.trim()); @@ -90,7 +90,7 @@ function Arguments({ buttonVariant, errors, setErrors, inputs, setInputs }) { + { + const file = event.target.files[0]; + if (file) { + const fileExtension = file.name.split('.').pop().toLowerCase(); + if (fileExtension !== "yaml" && fileExtension !== "yml") { + setErrorMessage("Only yaml files can be uploaded."); + console.error("Only yaml files can be uploaded."); + return; + } + try { + // Dosyayı okuma işlemi + const fileContent = await file.text(); + + // YAML parse işlemi + const parsed = yaml.load(fileContent); + await setInputs(parsed[0]); + + console.log(JSON.stringify(parsed, null, 4)); + + } catch (error) { + console.error("Error while file processing the yaml file, check format.", error); + } + } + }; + return ( + + ); +} diff --git a/src/components/Navbar.jsx b/src/components/Navbar.jsx index 25d9b82..f0a49be 100644 --- a/src/components/Navbar.jsx +++ b/src/components/Navbar.jsx @@ -40,7 +40,9 @@ function Navbar( { darkMode, setDarkMode } ) { // Function to toggle the theme mode const handleThemeToggle = () => { - setDarkMode(!darkMode); + const newMode = !darkMode; + setDarkMode(newMode); + localStorage.setItem('darkMode', newMode); }; return ( diff --git a/src/components/YamlContent.jsx b/src/components/YamlContent.jsx index a6f5bd1..23de4e0 100644 --- a/src/components/YamlContent.jsx +++ b/src/components/YamlContent.jsx @@ -61,7 +61,7 @@ function cleanObject(obj) { } // Main component to handle YAML content display and interactions -function YamlContent({ darkMode, buttonVariant, inputs, setInputs, updated, base, validationErrors, setChanged, changed }) { +function YamlContent({ darkMode, inputs, setInputs, updated, base, validationErrors, setChanged, changed }) { const [formatted_yaml, setFormattedYaml] = React.useState(null); // Stores formatted YAML content const [showContent, setShowContent] = React.useState(false); // Toggles YAML content display const [showValidationErrors, setShowValidationErrors] = React.useState(false); // Toggles validation error display @@ -144,7 +144,7 @@ function YamlContent({ darkMode, buttonVariant, inputs, setInputs, updated, base {/* Button group for actions: Download, Copy, Reset */} - + @@ -160,7 +160,7 @@ function YamlContent({ darkMode, buttonVariant, inputs, setInputs, updated, base {showValidationErrors && ( - + Some of the required fields are missing. {[...new Set(validationErrors)].map((error, index) => (
  • {error}