diff --git a/frontend/src/menuAside.ts b/frontend/src/menuAside.ts index 8d79539..b2ff736 100644 --- a/frontend/src/menuAside.ts +++ b/frontend/src/menuAside.ts @@ -48,6 +48,11 @@ const menuAside: MenuAsideItem[] = [ icon: 'mdiCalculator' in icon ? icon['mdiCalculator' as keyof typeof icon] : icon.mdiTable ?? icon.mdiTable, permissions: 'READ_CALCULATIONS' }, + { + href: '/calculator', + label: 'Calculator', + icon: icon.mdiCalculator, + }, { href: '/ai_requests/ai_requests-list', label: 'Ai requests', @@ -88,4 +93,4 @@ const menuAside: MenuAsideItem[] = [ }, ] -export default menuAside +export default menuAside \ No newline at end of file diff --git a/frontend/src/pages/calculator.tsx b/frontend/src/pages/calculator.tsx new file mode 100644 index 0000000..9a2e9d2 --- /dev/null +++ b/frontend/src/pages/calculator.tsx @@ -0,0 +1,77 @@ +import { mdiCalculator, mdiHistory } from '@mdi/js' +import Head from 'next/head' +import React, { useState, ReactElement } from 'react' +import CardBox from '../components/CardBox' +import LayoutAuthenticated from '../layouts/Authenticated' +import SectionMain from '../components/SectionMain' +import SectionTitleLineWithButton from '../components/SectionTitleLineWithButton' +import { getPageTitle } from '../config' +import BaseButton from '../components/BaseButton' +import BaseButtons from '../components/BaseButtons' +import FormField from '../components/FormField' + +const CalculatorPage = () => { + const [input, setInput] = useState('') + const [results, setResults] = useState({ hex: '', dec: '', oct: '', bin: '' }) + + const handleCalculate = () => { + // Basic implementation for now - this should ideally call the backend + try { + const decValue = parseInt(input, 10) + if (isNaN(decValue)) throw new Error('Invalid input') + + setResults({ + hex: decValue.toString(16).toUpperCase(), + dec: decValue.toString(10), + oct: decValue.toString(8), + bin: decValue.toString(2) + }) + } catch (e) { + alert('Error: Please enter a valid decimal number') + } + } + + return ( + <> + + {getPageTitle('Calculator')} + + + + {''} + + + + setInput(e.target.value)} + className="w-full p-2 border rounded" + placeholder="e.g. 255" + /> + + + + + + + {results.dec && ( + +
+
Decimal: {results.dec}
+
Hex: 0x{results.hex}
+
Octal: {results.oct}
+
Binary: {results.bin}
+
+
+ )} +
+ + ) +} + +CalculatorPage.getLayout = function getLayout(page: ReactElement) { + return {page} +} + +export default CalculatorPage