diff --git a/ui/.eslintrc.cjs b/ui/.eslintrc.cjs index 58f6e19..4780e44 100644 --- a/ui/.eslintrc.cjs +++ b/ui/.eslintrc.cjs @@ -19,6 +19,7 @@ module.exports = { }, plugins: ['react-refresh', 'prettier'], rules: { + "prettier/prettier": "error", 'react-refresh/only-export-components': [ 'warn', { allowConstantExport: true }, diff --git a/ui/.prettierrc b/ui/.prettierrc new file mode 100644 index 0000000..cd0621f --- /dev/null +++ b/ui/.prettierrc @@ -0,0 +1,6 @@ +{ + "printWidth": 120, + "singleQuote": true, + "tabWidth": 4, + "trailingComma": "none" +} \ No newline at end of file diff --git a/ui/package.json b/ui/package.json index c9b685f..32249f3 100644 --- a/ui/package.json +++ b/ui/package.json @@ -8,6 +8,7 @@ "build": "tsc --noEmit && vite build", "build-stage": "tsc --noEmit && vite build --mode staging", "lint": "eslint src --ext ts,tsx --report-unused-disable-directives", + "lint-fix": "eslint --fix src --ext ts,tsx .", "test": "vitest", "coverage": "vitest run --coverage", "preview": "vite preview", diff --git a/ui/src/App.tsx b/ui/src/App.tsx index 11f519e..dbcc7a2 100644 --- a/ui/src/App.tsx +++ b/ui/src/App.tsx @@ -21,6 +21,7 @@ const App = () => ( Loading...}> } /> + } /> } /> } /> } /> diff --git a/ui/src/atoms/atoms.ts b/ui/src/atoms/atoms.ts index 5082071..96f299d 100644 --- a/ui/src/atoms/atoms.ts +++ b/ui/src/atoms/atoms.ts @@ -25,6 +25,8 @@ export const structureWasUploadedAtom = atom(false); export const uploadedFileNameAtom = atom(''); +export const inputValueAtom = atom(''); + export const oxidationDataAtom = atom(null); export const graphSliderPositionAtom = atom(50); diff --git a/ui/src/components/DataViewer/Graph/ElectronicChemicalPotentialInput/ElectronicChemicalPotentialInput.tsx b/ui/src/components/DataViewer/Graph/ElectronicChemicalPotentialInput/ElectronicChemicalPotentialInput.tsx index 56daec9..2c6bb04 100644 --- a/ui/src/components/DataViewer/Graph/ElectronicChemicalPotentialInput/ElectronicChemicalPotentialInput.tsx +++ b/ui/src/components/DataViewer/Graph/ElectronicChemicalPotentialInput/ElectronicChemicalPotentialInput.tsx @@ -42,7 +42,7 @@ const ElectronicChemicalPotentialInput = ({ onChange, value }: ECPInputProps) => return ( { - The ICSD-derived reduction
potential ranges at which
each oxidation state is - likely
to be observed + The ICSD-derived reduction
potential ranges at which
each oxidation state + is likely
to be observed } > diff --git a/ui/src/components/PageWrapper/PageWrapper.tsx b/ui/src/components/PageWrapper/PageWrapper.tsx index 733bbe6..c19660c 100644 --- a/ui/src/components/PageWrapper/PageWrapper.tsx +++ b/ui/src/components/PageWrapper/PageWrapper.tsx @@ -11,9 +11,7 @@ const PageWrapper = ({ children }: PageWrapperProps) => { return (
- - {children} - + {children}
); diff --git a/ui/src/custom.d.ts b/ui/src/custom.d.ts index 249b63d..dd3eff0 100644 --- a/ui/src/custom.d.ts +++ b/ui/src/custom.d.ts @@ -4,4 +4,3 @@ declare module '*.svg' { const src: string; export default src; } - \ No newline at end of file diff --git a/ui/src/features/export-graph/export-graph-button.tsx b/ui/src/features/export-graph/export-graph-button.tsx index 7315369..8ab1430 100644 --- a/ui/src/features/export-graph/export-graph-button.tsx +++ b/ui/src/features/export-graph/export-graph-button.tsx @@ -11,7 +11,6 @@ import { InitalExportGraphSettingsState } from '@/models/ExportGraphModel'; import { BAR_HEIGHT, renderExportGraph } from './render-export-graph'; import keyImage from '@/Assets/Images/graphKey.svg'; - function fileSaveAs(uri: string, filename: string) { const link = document.createElement('a'); diff --git a/ui/src/features/input-submission/input-hooks/use-inputs.tsx b/ui/src/features/input-submission/input-hooks/use-inputs.tsx index bbd4d42..32a1bb1 100644 --- a/ui/src/features/input-submission/input-hooks/use-inputs.tsx +++ b/ui/src/features/input-submission/input-hooks/use-inputs.tsx @@ -1,4 +1,4 @@ -import { dataViewerStateAtom, structureWasUploadedAtom, uploadedFileNameAtom } from '@/atoms/atoms'; +import { dataViewerStateAtom, structureWasUploadedAtom, uploadedFileNameAtom, inputValueAtom } from '@/atoms/atoms'; import useTable from '../../data-table/table-hooks/use-table'; import { useAtom } from 'jotai'; import { LoadingState } from '@/features/data-table/table-models/data-viewer-model'; @@ -10,6 +10,8 @@ const useInputs = () => { const [, setDataViewerState] = useAtom(dataViewerStateAtom); const [structureWasUploaded, setStructureWasUploaded] = useAtom(structureWasUploadedAtom); + const [inputvalue] = useAtom(inputValueAtom); + const handleFileUpload = ( event: React.ChangeEvent, setInputText: Dispatch> @@ -61,6 +63,7 @@ const useInputs = () => { handleSubmitClick, handleEnterClick, structureWasUploaded, + inputvalue, uploadedFileName }; }; diff --git a/ui/src/features/input-submission/input-section/input-section.test.tsx b/ui/src/features/input-submission/input-section/input-section.test.tsx index 3ed327a..a5c0d64 100644 --- a/ui/src/features/input-submission/input-section/input-section.test.tsx +++ b/ui/src/features/input-submission/input-section/input-section.test.tsx @@ -6,7 +6,7 @@ import useInputs from '../input-hooks/use-inputs'; test('chemical composition input renders', () => { const { result: { - current: { handleFileUpload, handleSubmitClick, handleEnterClick } + current: { handleFileUpload, handleSubmitClick, handleEnterClick, inputvalue } } } = renderHook(useInputs); @@ -15,6 +15,7 @@ test('chemical composition input renders', () => { handleFileUpload={handleFileUpload} handleSubmitClick={handleSubmitClick} handleEnterClick={handleEnterClick} + inputvalue={inputvalue} /> ); const chemCompositionInputElem = screen.getByTestId('input-section-chemical-composition'); @@ -24,7 +25,7 @@ test('chemical composition input renders', () => { test('submit button is disabled when chemical composition input box is empty', () => { const { result: { - current: { handleFileUpload, handleSubmitClick, handleEnterClick } + current: { handleFileUpload, handleSubmitClick, handleEnterClick, inputvalue } } } = renderHook(useInputs); @@ -33,6 +34,7 @@ test('submit button is disabled when chemical composition input box is empty', ( handleFileUpload={handleFileUpload} handleSubmitClick={handleSubmitClick} handleEnterClick={handleEnterClick} + inputvalue={inputvalue} /> ); @@ -46,7 +48,7 @@ test('submit button is disabled when chemical composition input box is empty', ( test('submit button should be enabled when chemcial composition input is filled', async () => { const { result: { - current: { handleFileUpload, handleSubmitClick, handleEnterClick } + current: { handleFileUpload, handleSubmitClick, handleEnterClick, inputvalue } } } = renderHook(useInputs); @@ -55,6 +57,7 @@ test('submit button should be enabled when chemcial composition input is filled' handleFileUpload={handleFileUpload} handleSubmitClick={handleSubmitClick} handleEnterClick={handleEnterClick} + inputvalue={inputvalue} /> ); @@ -71,7 +74,7 @@ test('submit button should be enabled when chemcial composition input is filled' test('onSubmit function should be called with string in checmical composition input whe submit button is clicked', async () => { const { result: { - current: { handleFileUpload, handleEnterClick } + current: { handleFileUpload, handleEnterClick, inputvalue } } } = renderHook(useInputs); @@ -81,6 +84,7 @@ test('onSubmit function should be called with string in checmical composition in handleFileUpload={handleFileUpload} handleSubmitClick={handleSubmitClick} handleEnterClick={handleEnterClick} + inputvalue={inputvalue} /> ); diff --git a/ui/src/features/input-submission/input-section/input-section.tsx b/ui/src/features/input-submission/input-section/input-section.tsx index e5f5fb0..8249ae1 100644 --- a/ui/src/features/input-submission/input-section/input-section.tsx +++ b/ui/src/features/input-submission/input-section/input-section.tsx @@ -1,7 +1,7 @@ import { TextField, Button, Typography } from '@mui/material'; import styles from './input-section.module.css'; import UploadIcon from '@mui/icons-material/Upload'; -import React, { Dispatch, SetStateAction, useState } from 'react'; +import React, { Dispatch, SetStateAction, useEffect, useState } from 'react'; const PLACEHOLDER_TEXT = 'ex. LiMn2O4'; const LABEL_TEXT = 'Chemical Composition'; @@ -15,12 +15,24 @@ interface InputSectionProps { handleEnterClick: (event: React.KeyboardEvent, inputText: string) => void; } -const InputSection = ({ handleFileUpload, handleSubmitClick, handleEnterClick }: InputSectionProps) => { - const [inputText, setInputText] = useState(''); - +const InputSection = ({ + handleFileUpload, + handleSubmitClick, + handleEnterClick, + inputvalue +}: InputSectionProps & { inputvalue: string }) => { + const [inputText, setInputText] = useState(inputvalue || ''); + if (inputText == null) { + setInputText(''); + } const handleInputChange = (event: React.ChangeEvent) => { setInputText(event.target.value); }; + useEffect(() => { + if (inputText != '') { + handleSubmitClick(inputText); + } + }, []); return (
- - , -) + + + +); diff --git a/ui/src/pages/Home/Home.tsx b/ui/src/pages/Home/Home.tsx index beb39ef..e76a26f 100644 --- a/ui/src/pages/Home/Home.tsx +++ b/ui/src/pages/Home/Home.tsx @@ -6,11 +6,16 @@ import GetStarted from '@/components/GetStarted/GetStarted'; import InputSection from '@/features/input-submission/input-section/input-section'; import DataViewer from '@/components/DataViewer/DataViewer'; import PageWrapper from '@/components/PageWrapper/PageWrapper'; -import { useEffect } from 'react'; +import { useEffect, useState } from 'react'; import useInputs from '@/features/input-submission/input-hooks/use-inputs'; +import { useLocation } from 'react-router-dom'; function Home() { const { handleFileUpload, handleSubmitClick, handleEnterClick } = useInputs(); + const location = useLocation(); + const param = new URLSearchParams(location.search); + const qparam = param.get('q'); + const [inputText] = useState(qparam || ''); useEffect(() => { document.title = 'Oxidation State Analyzer'; @@ -42,6 +47,7 @@ function Home() { handleFileUpload={handleFileUpload} handleSubmitClick={handleSubmitClick} handleEnterClick={handleEnterClick} + inputvalue={inputText} />