unbeleavebly

This commit is contained in:
Inohara 2023-05-06 01:41:36 +04:00
parent efea38695b
commit 886f470f03
22 changed files with 17710 additions and 1 deletions

View File

@ -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)

17348
all/react-postgres/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,39 @@
{
"name": "react-postgres",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.11.1",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}

View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script>
<title>SUBD</title>
</head>
<body>
<div id="root"></div>
</body>
</html>

18
all/react-postgres/src/App.js vendored Normal file
View File

@ -0,0 +1,18 @@
import React from 'react';
import { Routes,Route } from "react-router-dom";
import Header from "./common/Header";
import FacultyPage from "./pages/FacultyPage";
function App() {
return (
<>
<Header/>
<Routes>
<Route path="/" element={<FacultyPage/>} />
<Route path="/faculty" element={<FacultyPage/>} />
</Routes>
</>
);
}
export default App;

View File

@ -0,0 +1,26 @@
import React from 'react';
import { Link } from 'react-router-dom';
export default function Header() {
return (
<nav className="navbar navbar-expand-lg bg-light">
<div className="container-fluid">
<h1 className="navbar-brand">SUBD</h1>
<button className="navbar-toggler" type="button"
data-bs-toggle="collapse" data-bs-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span className="navbar-toggler-icon"></span>
</button>
<div className="collapse navbar-collapse" id="navbarNav">
<ul className="navbar-nav">
<li className="nav-item">
<Link className="nav-link" to="/faculty">
FACULTY
</Link>
</li>
</ul>
</div>
</div>
</nav >
);
}

View File

@ -0,0 +1,47 @@
import React from "react";
function Modal(props) {
const formRef = React.createRef();
const hide = () => {
props.onHide();
}
const done = (e) => {
e.preventDefault();
if (formRef.current.checkValidity()) {
props.onDone();
hide();
} else {
formRef.current.reportValidity();
}
}
return (
<div className="modal fade show" tabIndex="-1" aria-hidden="true"
style={{ display: props.visible ? 'block' : 'none' }}>
<div className="modal-dialog">
<div className="modal-content">
<div className="modal-header">
<h1 className="modal-title fs-5" id="exampleModalLabel">{props.header}</h1>
<button className="btn-close" type="button" aria-label="Close"
onClick={hide}></button>
</div>
<div className="modal-body">
<form ref={formRef} onSubmit={done}>
{props.children}
</form>
</div>
<div className="modal-footer">
<button className="btn btn-secondary" type="button" onClick={hide}>Close</button>
<button className="btn btn-primary" type="button" onClick={done}>
{props.confirm}
</button>
</div>
</div>
</div>
</div>
);
}
export default Modal;

13
all/react-postgres/src/index.js vendored Normal file
View File

@ -0,0 +1,13 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import { BrowserRouter } from 'react-router-dom';
import App from './App';
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<BrowserRouter>
<App></App>
</BrowserRouter>
</React.StrictMode>
);

View File

@ -0,0 +1,6 @@
export default class Faculty {
constructor(data) {
this.id = data?.id;
this.name = data?.name || '';
}
}

View File

@ -0,0 +1,131 @@
import React, {useState, useEffect} from 'react';
import Faculty from '../models/Faculty';
import Modal from '../common/Modal';
export default function FacultyPage() {
const [items, setItems] = useState([]);
const [item, setItem] = useState(new Faculty())
const [modalHeader, setModalHeader] = useState('')
const [modalConfirm, setModalConfirm] = useState('')
const [modalVisible, setModalVisible] = useState(false)
const [isEdit, setEdit] = useState(false)
useEffect(() => {
get()
//eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
function save(){
if(isEdit) upd()
else create()
get()
}
function get(){
fetch('http://localhost:3001/faculty')
.then(response => {return response.json()})
.then(data => setItems(data))
}
function create(){
const name = item.name
fetch('http://localhost:3001/faculty', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({name})
})
.then(response => get())
}
function upd(){
fetch(`http://localhost:3001/faculty/upd/${item.id}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(item)
})
.then(response => get())
}
function del(id){
fetch(`http://localhost:3001/faculty/del/${id}`, {
method: 'DELETE'
})
.then(response => get())
}
function handleCreate(){
setEdit(false)
setModalHeader('Create');
setModalConfirm('Add');
setModalVisible(true);
}
function handleFormChange(event) {
setItem({ ...item, [event.target.id]: event.target.value })
}
function handleEdit(data){
setItem(data)
setEdit(true)
setModalHeader('Update');
setModalConfirm('Save');
setModalVisible(true);
}
const hideModal = () => setModalVisible(false)
const modalDone = () => save()
return (
<>
<Modal
header={modalHeader}
confirm={modalConfirm}
visible={modalVisible}
onHide={hideModal}
onDone={modalDone}>
<div className="mb-3">
<label htmlFor="name" className="form-label">Name</label>
<input type="text" id="name" className="form-control" required
value={item.name} onChange={handleFormChange}/>
</div>
</Modal>
<div className='container'>
<button type="button" className="btn btn-success" onClick={handleCreate}>Create</button>
<table className='table'>
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">name</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
{
items.map((data, index) =>
<tr key={data.id}>
<th scope="row">{index + 1}</th>
<td>{data.name}</td>
<td>
<div>
<button type="button" className="btn btn-warning" onClick={() => handleEdit(data)}>Edit</button>
<button type="button" className="btn btn-danger" onClick={() => del(data.id)}>Delete</button>
</div>
</td>
</tr>
)
}
</tbody>
</table>
</div>
</>
);
}

@ -1 +0,0 @@
Subproject commit 119e330b10b09c970743f7b34e2e7e17f62185cc