diff --git a/src/app/component/nav.jsx b/src/app/component/nav.jsx index 2a12945..faef491 100644 --- a/src/app/component/nav.jsx +++ b/src/app/component/nav.jsx @@ -1,5 +1,4 @@ "use client" -import React from "react"; import Link from "next/link"; function nav() { diff --git a/src/app/globals.css b/src/app/globals.css index 8978812..6889d1a 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -20,7 +20,7 @@ body { color: rgb(var(--foreground-rgb)); background: linear-gradient( to bottom, - transparent, + transparent, rgb(var(--background-end-rgb)) ) rgb(var(--background-start-rgb)); @@ -35,7 +35,6 @@ body { } - .video-background { position: fixed; right: 0; diff --git a/src/app/page.jsx b/src/app/page.jsx index 66ea11b..29df3ab 100644 --- a/src/app/page.jsx +++ b/src/app/page.jsx @@ -1,5 +1,3 @@ -import Image from "next/image"; -import Link from "next/link"; export default function Home() { diff --git a/src/app/weight/conversionFactors.js b/src/app/weight/conversionFactors.js deleted file mode 100644 index e6cec3a..0000000 --- a/src/app/weight/conversionFactors.js +++ /dev/null @@ -1,136 +0,0 @@ -const conversionFactors = { - meter: { - kilometer: 0.001, - centimeter: 100, - millimeter: 1000, - micrometer: 1e6, - nanometer: 1e9, - mile: 0.000621371, - yard: 1.09361, - foot: 3.28084, - inch: 39.3701, - nauticalMile: 0.000539957, - }, - kilometer: { - meter: 1000, - centimeter: 100000, - millimeter: 1e6, - micrometer: 1e9, - nanometer: 1e12, - mile: 0.621371, - yard: 1093.61, - foot: 3280.84, - inch: 39370.1, - nauticalMile: 0.539957, - }, - centimeter: { - meter: 0.01, - kilometer: 1e-5, - millimeter: 10, - micrometer: 10000, - nanometer: 1e7, - mile: 6.2137e-6, - yard: 0.0109361, - foot: 0.0328084, - inch: 0.393701, - nauticalMile: 5.3996e-6, - }, - millimeter: { - meter: 0.001, - kilometer: 1e-6, - centimeter: 0.1, - micrometer: 1000, - nanometer: 1e6, - mile: 6.2137e-7, - yard: 0.00109361, - foot: 0.00328084, - inch: 0.0393701, - nauticalMile: 5.3996e-7, - }, - micrometer: { - meter: 1e-6, - kilometer: 1e-9, - centimeter: 1e-4, - millimeter: 0.001, - nanometer: 1000, - mile: 6.2137e-10, - yard: 1.0936e-6, - foot: 3.2808e-6, - inch: 3.937e-5, - nauticalMile: 5.3996e-10, - }, - nanometer: { - meter: 1e-9, - kilometer: 1e-12, - centimeter: 1e-7, - millimeter: 1e-6, - micrometer: 0.001, - mile: 6.2137e-13, - yard: 1.0936e-9, - foot: 3.2808e-9, - inch: 3.937e-8, - nauticalMile: 5.3996e-13, - }, - mile: { - meter: 1609.34, - kilometer: 1.60934, - centimeter: 160934, - millimeter: 1.609e6, - micrometer: 1.609e9, - nanometer: 1.609e12, - yard: 1760, - foot: 5280, - inch: 63360, - nauticalMile: 0.868976, - }, - yard: { - meter: 0.9144, - kilometer: 0.0009144, - centimeter: 91.44, - millimeter: 914.4, - micrometer: 914400, - nanometer: 914400000, - mile: 0.000568182, - foot: 3, - inch: 36, - nauticalMile: 0.000493737, - }, - foot: { - meter: 0.3048, - kilometer: 0.0003048, - centimeter: 30.48, - millimeter: 304.8, - micrometer: 304800, - nanometer: 304800000, - mile: 0.000189394, - yard: 0.333333, - inch: 12, - nauticalMile: 0.000164579, - }, - inch: { - meter: 0.0254, - kilometer: 2.54e-5, - centimeter: 2.54, - millimeter: 25.4, - micrometer: 25400, - nanometer: 25400000, - mile: 1.5783e-5, - yard: 0.0277778, - foot: 0.0833333, - nauticalMile: 1.3715e-5, - }, - nauticalMile: { - meter: 1852, - kilometer: 1.852, - centimeter: 185200, - millimeter: 1.852e6, - micrometer: 1.852e9, - nanometer: 1.852e12, - mile: 1.15078, - yard: 2025.37, - foot: 6076.12, - inch: 72913.4, - }, -}; - -export default conversionFactors; diff --git a/src/app/weight/function.js b/src/app/weight/function.js new file mode 100644 index 0000000..7277b98 --- /dev/null +++ b/src/app/weight/function.js @@ -0,0 +1,72 @@ +import units from "./unit"; + +const test = (val,fromUnit ,toUnit)=>{ + if(fromUnit === units.Kilogram.unit){ + return calWeight(val, units.Kilogram, toUnit, units) + } + else if ( fromUnit === units.Gram.unit){ + return calWeight(val, units.Gram, toUnit, units) + } + else if ( fromUnit === units.Milligram.unit ){ + return calWeight(val, units.Milligram, toUnit, units) + } + else if ( fromUnit === units.Microgram.unit ){ + return calWeight(val, units.Microgram, toUnit, units) + } + else if ( fromUnit === units.MetricTon.unit ){ + return calWeight(val, units.MetricTon, toUnit, units) + } + else if ( fromUnit === units.Pound.unit ){ + return calWeight(val, units.Pound, toUnit, units) + } + else if ( fromUnit === units.Ounce.unit ){ + return calWeight(val, units.Ounce, toUnit, units) + } + else if ( fromUnit === units.Stone.unit ){ + return calWeight(val, units.Stone, toUnit, units) + } + else if ( fromUnit === units.ShortTon.unit ){ + return calWeight(val, units.ShortTon, toUnit, units) + } + else if ( fromUnit === units.LongTon.unit ){ + return calWeight(val, units.LongTon, toUnit, units) + } +} + +const calWeight =(val, unit, toUnit, units)=>{ + if( toUnit === unit.unit ){ + return val + } + else if( toUnit === units.Gram.unit){ + return val / unit.prefix * units.Gram.prefix + } + else if( toUnit === units.Kilogram.unit){ + return val / unit.prefix * units.Kilogram.prefix + } + else if( toUnit === units.Milligram.unit ){ + return val / unit.prefix * units.Milligram.prefix + } + else if( toUnit === units.Microgram.unit ){ + return val / unit.prefix * units.Microgram.prefix + } + else if( toUnit === units.MetricTon.unit ){ + return val / unit.prefix * units.MetricTon.prefix + } + else if( toUnit === units.Pound.unit ){ + return val / unit.prefix * units.Pound.prefix + } + else if( toUnit === units.Ounce.unit ){ + return val / unit.prefix * units.Ounce.prefix + } + else if( toUnit === units.Stone.unit ){ + return val / unit.prefix * units.Stone.prefix + } + else if( toUnit === units.ShortTon.unit ){ + return val / unit.prefix * units.ShortTon.prefix + } + else if( toUnit === units.LongTon.unit ){ + return val / unit.prefix * units.LongTon.prefix + } +} + +export default test; \ No newline at end of file diff --git a/src/app/weight/page.jsx b/src/app/weight/page.jsx index ba9bdfa..641221c 100644 --- a/src/app/weight/page.jsx +++ b/src/app/weight/page.jsx @@ -1,85 +1,73 @@ "use client" -import React, { useState } from "react"; -import "./si.css" -import conversionFactors from "./conversionFactors"; +import { useState } from "react"; +import test from "./function"; -function App() { - const [inputs, setInputs] = useState([{ id: 1, value: 0, fromUnit: "meter", toUnit: "kilometer" }]); +export default function TestPage() { + const weightUnits = [ + "Kilogram", + "Gram", + "Milligram", + "Microgram", + "Metric ton", + "Pound", + "Ounce", + "Stone", + "Short ton", + "Long ton" + ]; + const [input, setInput] = useState(0) + const [fromUnit, setFromUnit] = useState("Kilogram") + const [toUnit, setToUnit] = useState("Kilogram") - const handleInputChange = (id, e) => { - const { name, value } = e.target; - const newInputs = inputs.map(input => input.id === id ? { ...input, [name]: value === "" ? 0 : parseFloat(value) } : input); - setInputs(newInputs); - }; - - const handleFromUnitChange = (id, e) => { - const { value } = e.target; - const newInputs = inputs.map(input => input.id === id ? { ...input, fromUnit: value } : input); - setInputs(newInputs); - }; - - const handleToUnitChange = (id, e) => { - const { value } = e.target; - const newInputs = inputs.map(input => input.id === id ? { ...input, toUnit: value } : input); - setInputs(newInputs); - }; - - const handleConvert = (id) => { - const input = inputs.find(input => input.id === id); - const { value, fromUnit, toUnit } = input; - const factor = conversionFactors[fromUnit][toUnit]; - if (factor !== undefined) { - const result = value * factor; - const newInputs = inputs.map(input => input.id === id ? { ...input, result } : input); - setInputs(newInputs); - } else { - const newInputs = inputs.map(input => input.id === id ? { ...input, result: "Conversion factor not defined" } : input); - setInputs(newInputs); - } - }; - - const handleAddInput = () => { - if (inputs.length < 8) { - const newId = Math.max(...inputs.map(input => input.id)) + 1; - setInputs([...inputs, { id: newId, value: 0, fromUnit: "meter", toUnit: "kilometer" }]); - } - }; - - return ( -
- {input.value} {input.fromUnit} is equal to {input.result} {input.toUnit} -
+ const convertFunction = test(input, fromUnit, toUnit) + return ( +