Inzynierka_Gwiazdy/react/src/App.js

104 lines
2.9 KiB
JavaScript
Raw Normal View History

2023-09-20 17:27:25 +02:00
import './App.css';
import { useState } from 'react';
import axios from 'axios';
function App() {
const [datasetQuarry, setDatasetQuarry] = useState('');
const [tableQuarry, setTableQuarry] = useState('');
const [columns, setColumns] = useState('');
const [results, setResults] = useState('');
const [isVisible, setIsVisible] = useState(true);
2023-09-20 17:27:25 +02:00
const fetchDataFromAPI = async (dataset, table, column) => {
try {
2023-09-20 20:19:16 +02:00
const response = await axios.get(`https://cat-fact.herokuapp.com/facts/?dataset=${dataset}&table=${table}&column=${column}`);
2023-09-20 17:27:25 +02:00
const data = response.data;
setResults(data);
} catch (error) {
console.error('Error fetching data:', error);
setResults('Error fetching data');
}
};
const handleButtonClick = () => {
fetchDataFromAPI(datasetQuarry, tableQuarry, columns);
};
const toggleVisibility = () => {
setIsVisible(!isVisible);
};
2023-09-20 17:27:25 +02:00
return (
<body>
{isVisible && <div className="container2">
<div className='headerlearn'>
<header>Learning tables</header>
</div>
<input
className='datasetL'
type="text"
placeholder="Dataset quarry"
value={datasetQuarry}
onChange={(e) => setDatasetQuarry(e.target.value)}
/>
<input
className='tableL'
type="text"
placeholder="Table quarry"
value={tableQuarry}
onChange={(e) => setTableQuarry(e.target.value)}
/>
<div className="columsL" id="columns-heigh">
<input
type="text"
placeholder="Columns"
value={columns}
onChange={(e) => setColumns(e.target.value)}
/>
</div>
</div>}
<div className="container">
<div className='headertest'>
<header>Test tables</header>
</div>
<input
className='dataset'
type="text"
placeholder="Dataset quarry"
value={datasetQuarry}
onChange={(e) => setDatasetQuarry(e.target.value)}
/>
<input
className='table'
type="text"
placeholder="Table quarry"
value={tableQuarry}
onChange={(e) => setTableQuarry(e.target.value)}
/>
<div className="colums" id="columns-heigh">
<input
type="text"
placeholder="Columns"
value={columns}
onChange={(e) => setColumns(e.target.value)}
/>
</div>
<button className='toggle' onClick={toggleVisibility}>
Toggle more
</button>
<button className="test" type="button" onClick={handleButtonClick}>
Test
</button>
<textarea
className='Resoult'
placeholder="Results"
value={results}
onChange={(e) => setResults(e.target.value)}
></textarea>
2023-09-20 17:27:25 +02:00
</div>
</body>
2023-09-20 17:27:25 +02:00
);
}
export default App;