Четвёртая партия фронта.

This commit is contained in:
Programmist73 2023-04-19 20:23:17 +04:00
parent 15b5ebd034
commit ce8c5ca468
7 changed files with 310 additions and 0 deletions

@ -0,0 +1,70 @@
# Getting Started with Create React App
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Available Scripts
In the project directory, you can run:
### `npm start`
Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
The page will reload when you make changes.\
You may also see any lint errors in the console.
### `npm test`
Launches the test runner in the interactive watch mode.\
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `npm run build`
Builds the app for production to the `build` folder.\
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.\
Your app is ready to be deployed!
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
### `npm run eject`
**Note: this is a one-way operation. Once you `eject`, you can't go back!**
If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
## Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To learn React, check out the [React documentation](https://reactjs.org/).
### Code Splitting
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
### Analyzing the Bundle Size
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
### Making a Progressive Web App
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
### Advanced Configuration
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
### Deployment
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
### `npm run build` fails to minify
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)

@ -0,0 +1,133 @@
import React, { useState, useEffect, useRef} from 'react';
import axios from 'axios';
import '../styles/App.css';
import TankList from './items/Tank/TankList';
import './AddTank.css';
const PageForChecking = () => {
const[tankItems, setTankItems] = useState([]);
const [nationItems, setNationItems] = useState([]);
const [levelItems, setLevelItems] = useState([]);
const [chooiceNation, setChooiceNation] = useState();
const [chooiceFirstLevel, setChooiceFirstLevel] = useState();
const [chooiceSecondLevel, setChooiceSecondLevel] = useState();
//загрузка всех имеющихся танков, а также уровней и наций при старте
useEffect(() => {
axios.get('http://localhost:8080/level/')
.then((responce) => {
console.log(responce.data);
setLevelItems(responce.data)
});
axios.get('http://localhost:8080/nation/')
.then((responce) => {
console.log(responce.data);
setNationItems(responce.data)
});
}, [])
const getChoiceNation = (newId) => {
setChooiceNation(nationItems[newId - 1].nation);
}
const getChooiceFirstLevel = (newId) => {
setChooiceFirstLevel(levelItems[newId - 1].level);
}
const getChooiceSecondLevel = (newId) => {
setChooiceSecondLevel(levelItems[newId - 1].level);
}
function findList(){
console.log(chooiceNation);
console.log(chooiceFirstLevel);
console.log(chooiceSecondLevel);
axios.get('http://localhost:8080/tank/filteredList/?nation=' + chooiceNation + '&firstLevel=' + chooiceFirstLevel + '&secondLevel=' + chooiceSecondLevel)
.then((response) => {
setTankItems(response.data)
});
console.log(tankItems)
}
return(
<div>
<div className="Group_create_level">
<h1>Фильтрация танков</h1>
<div>
<p style={{fontWeight: "900"}}>
Выберите нацию:
<select
onChange={(event) => getChoiceNation(event.target.selectedIndex)}
>
<option selected>Выберите нацию</option>
{nationItems.map((nationItem) =>
<option
value={nationItem.nation}
key={nationItem.id}
>
{nationItem.nation}
</option>
)}
</select>
</p>
<p style={{fontWeight: "900"}}>
Выберите начальный диапазон уровней:
<select style={{marginTop: "10px"}}
onChange={(event) => getChooiceFirstLevel(event.target.selectedIndex)}
>
<option selected>Выберите уровень</option>
{levelItems.map((levelItem) =>
<option
value={levelItem.level}
key={levelItem.id}
>
{levelItem.level}
</option>
)}
</select>
</p>
<p style={{fontWeight: "900"}}>
Выберите конечный диапазон уровней:
<select style={{marginTop: "10px"}}
onChange={(event) => getChooiceSecondLevel(event.target.selectedIndex)}
>
<option selected>Выберите уровень</option>
{levelItems.map((levelItem) =>
<option
value={levelItem.level}
key={levelItem.id}
>
{levelItem.level}
</option>
)}
</select>
</p>
</div>
<button className='add-level-button'
onClick={findList}
>
Найти танки
</button>
</div>
<div className="Card_list">
{tankItems.length !== 0
?
<TankList tankItems={tankItems}
/>
:
<h1 style={{textAlign: 'center'}}>Отсутствуют какие-либо танки при таком фильтре!</h1>
}
</div>
</div>
);
}
export default PageForChecking

@ -0,0 +1,37 @@
.tank-card{
display: flex;
width: 100%;
padding: 15px;
margin-top: 5px;
border: 5px solid;
border-color: #14A76C;
border-radius: 10px;
justify-content: space-around;
align-items: center;
font-family: Courier, monospace;
font-weight: 900;
}
.tank-attribute{
padding: 5px;
border-radius: 10px;
background-color: #FF652F;
font-family: Courier, monospace;
font-weight: 900;
align-items: center;
}
.tank-button-group{
display: flex;
width: 20%;
justify-content: space-around;
align-items: center;
}
.tank-button{
padding: 10px;
border-radius: 10px;
background-color: #FF652F;
font-family: Courier, monospace;
font-weight: 900;
}

@ -0,0 +1,48 @@
import React, { useState } from 'react';
import axios from 'axios';
import './TankItem.css';
import ModalTank from './ModalTank';
const TankItem = (data) => {
const [tank, setTank] = useState(null);
//состояние для контроля вызова модального окна
const[modal, setModal] = useState(false);
function deleteTank(){
axios.delete('http://localhost:8080/tank/' + data.tankItem.id)
.then((response) => {
console.log("Удаление танка с id " + data.tankItem.id)
});
}
return (
<div className="tank-card">
<p className="tank-attribute"> id: {data.tankItem.id} </p>
<p className="tank-attribute"> название: {data.tankItem.name} </p>
<p className="tank-attribute"> уровень: {data.tankItem.level.level} </p>
<p className="tank-attribute"> нация: {data.tankItem.nation.nation} </p>
<p className="tank-attribute"> стоимость: {data.tankItem.cost} </p>
<div className='tank-button-group'>
<button className="tank-button" type="button"
onClick={() => setModal(true)}
>
Редактировать
</button>
<button className="tank-button" type="button"
onClick={deleteTank}
>
Удалить
</button>
<ModalTank
data={data.tankItem}
visible={modal}
setVisible={setModal}
/>
</div>
</div>
);
}
export default TankItem

@ -0,0 +1,22 @@
import React from 'react'
import TankItem from './TankItem';
const TankList = (tanks) => {
return (
<div>
<div>
<h1 style={{textAlign: 'center', fontFamily: 'courier, monospace', background: '#FF652F', borderRadius: '10px'}}>
Список существующих наций:
</h1>
</div>
{tanks.tankItems.map((tankItem) =>
<TankItem
tankItem={tankItem}
key={tankItem.id}
/>
)}
</div>
);
}
export default TankList;

Binary file not shown.

After

(image error) Size: 497 KiB

Binary file not shown.

After

(image error) Size: 474 KiB