diff --git a/.idea/workspace.xml b/.idea/workspace.xml index f9a3ff9..15b429f 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -6,7 +6,8 @@ - + + - { - "history": [ + +}]]> { "prStates": [ { @@ -116,7 +120,7 @@ "Vitest.removeDuplicateLines function.newlines option.should filter newlines when newlines is set to filter.executor": "Run", "Vitest.replaceText function (regexp mode).should return the original text when passed an invalid regexp.executor": "Run", "Vitest.replaceText function.executor": "Run", - "git-widget-placeholder": "main", + "git-widget-placeholder": "#44 on fork/ady-cf/feature/validate-json", "ignore.virus.scanning.warn.message": "true", "kotlin-language-version-configured": "true", "last_opened_file_path": "C:/Users/Ibrahima/IdeaProjects/omni-tools/.husky", @@ -167,7 +171,7 @@ - + @@ -240,10 +244,10 @@ + - diff --git a/src/pages/tools/json/validateJson/index.tsx b/src/pages/tools/json/validateJson/index.tsx index c3cdfc7..39333af 100644 --- a/src/pages/tools/json/validateJson/index.tsx +++ b/src/pages/tools/json/validateJson/index.tsx @@ -1,16 +1,10 @@ -import { Box } from '@mui/material'; -import React, { useRef, useState, useEffect } from 'react'; +import React, { useState } from 'react'; import ToolTextInput from '@components/input/ToolTextInput'; import ToolTextResult from '@components/result/ToolTextResult'; -import ToolInputAndResult from '@components/ToolInputAndResult'; -import ToolInfo from '@components/ToolInfo'; -import Separator from '@components/Separator'; -import ToolExamples, { - CardExampleType -} from '@components/examples/ToolExamples'; -import { FormikProps } from 'formik'; -import { validateJson } from './servcie'; +import { CardExampleType } from '@components/examples/ToolExamples'; +import { validateJson } from './service'; import { ToolComponentProps } from '@tools/defineTool'; +import ToolContent from '@components/ToolContent'; const exampleCards: CardExampleType<{}>[] = [ { @@ -54,15 +48,8 @@ const exampleCards: CardExampleType<{}>[] = [ export default function ValidateJson({ title }: ToolComponentProps) { const [input, setInput] = useState(''); const [result, setResult] = useState(''); - const formRef = useRef>(null); - useEffect(() => { - if (input) { - compute(input); - } - }, [input]); - - const compute = (input: string) => { + const compute = (options: any, input: string) => { const { valid, error } = validateJson(input); if (valid) { @@ -73,37 +60,33 @@ export default function ValidateJson({ title }: ToolComponentProps) { }; return ( - - - } - result={} - /> - - + } + resultComponent={ + + } + initialValues={{}} + getGroups={null} + toolInfo={{ + title: 'What is JSON Validation?', + description: ` JSON (JavaScript Object Notation) is a lightweight data-interchange format. JSON validation ensures that the structure of the data conforms to the JSON standard. A valid JSON object must have: - Property names enclosed in double quotes. - - Properly balanced curly braces `{}`. + - Properly balanced curly braces {}. - No trailing commas after the last key-value pair. - Proper nesting of objects and arrays. This tool checks the input JSON and provides feedback to help identify and fix common errors. - " - /> - - - - []} - formRef={formRef} - setInput={setInput} - /> - + ` + }} + exampleCards={exampleCards} + input={input} + setInput={setInput} + compute={compute} + /> ); } diff --git a/src/pages/tools/json/validateJson/servcie.ts b/src/pages/tools/json/validateJson/service.ts similarity index 86% rename from src/pages/tools/json/validateJson/servcie.ts rename to src/pages/tools/json/validateJson/service.ts index 400c1bb..2d53367 100644 --- a/src/pages/tools/json/validateJson/servcie.ts +++ b/src/pages/tools/json/validateJson/service.ts @@ -1,14 +1,13 @@ -export const validateJson = ( - input: string -): { valid: boolean; error?: string } => { - try { - JSON.parse(input); - return { valid: true }; - } catch (error) { - if (error instanceof SyntaxError) { - const message = error.message; - return { valid: false, error: error.message }; - } - return { valid: false, error: 'Unknown error occurred' }; - } -}; +export const validateJson = ( + input: string +): { valid: boolean; error?: string } => { + try { + JSON.parse(input); + return { valid: true }; + } catch (error) { + if (error instanceof SyntaxError) { + return { valid: false, error: error.message }; + } + return { valid: false, error: 'Unknown error occurred' }; + } +};