Skip to content

Commit a7e24e4

Browse files
authored
Merge pull request #8 from NisanurBulut/dev_eros
Dev eros is complated
2 parents 47de79d + 10d4886 commit a7e24e4

25 files changed

+17790
-1
lines changed

README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,12 @@ Hestia is a reactjs application that stores a list of books using localStorage.
116116
![App-Hestia](https://github.com/NisanurBulut/MythologyOfReactJs/blob/master/Trailers/Trailer_Hestia.gif)
117117
<br>
118118
<hr>
119-
20. <b>Guide ReactJs</b> <br>
119+
20. <b>Eros</b> <br>
120+
This work is practical views of reactJs Hooks.
121+
122+
![App-Eros](https://github.com/NisanurBulut/MythologyOfReactJs/blob/master/Trailers/Trailer_Eros.gif)
123+
<br>
124+
21. <b>Guide ReactJs</b> <br>
120125
This work is practical views of reactJs tutorials.
121126

122127
[Literature for ReactJs](https://github.com/NisanurBulut/MythologyOfReactJs/tree/master/guideReactJs)
@@ -125,6 +130,7 @@ This work is practical views of reactJs tutorials.
125130
<br>
126131
<hr>
127132

133+
<hr>
128134
### Helpfull Websites
129135
[uidesigndaily](https://uidesigndaily.com/posts/sketch-birthdays-list-card-widget-day-1042)
130136
[Devto](https://dev.to/) [popmotion](https://popmotion.io) [json-server](https://github.com/typicode/json-server)

Trailers/Trailer_Eros.gif

502 KB
Loading

eros/.gitignore

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# production
12+
/build
13+
14+
# misc
15+
.DS_Store
16+
.env.local
17+
.env.development.local
18+
.env.test.local
19+
.env.production.local
20+
21+
npm-debug.log*
22+
yarn-debug.log*
23+
yarn-error.log*

eros/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<b>Eros</b> <br>
2+
This work is practical views of reactJs Hooks.
3+
4+
![App-Eros](https://github.com/NisanurBulut/MythologyOfReactJs/blob/master/Trailers/Trailer_Eros.gif)
5+
<br>

eros/db.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"contacts": [
3+
{
4+
"text": "Furkan",
5+
"day": "1 November",
6+
"reminder": true,
7+
"id": 1
8+
}
9+
]
10+
}

eros/package-lock.json

+17,208
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eros/package.json

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "eros",
3+
"version": "0.1.0",
4+
"private": true,
5+
"dependencies": {
6+
"@testing-library/jest-dom": "^5.11.9",
7+
"@testing-library/react": "^11.2.5",
8+
"@testing-library/user-event": "^12.7.0",
9+
"react": "^17.0.1",
10+
"react-dom": "^17.0.1",
11+
"react-icons": "^4.2.0",
12+
"react-scripts": "4.0.2",
13+
"web-vitals": "^1.1.0"
14+
},
15+
"scripts": {
16+
"start": "react-scripts start",
17+
"build": "react-scripts build",
18+
"test": "react-scripts test",
19+
"eject": "react-scripts eject",
20+
"server":"json-server --watch db.json --port 5000"
21+
},
22+
"eslintConfig": {
23+
"extends": [
24+
"react-app",
25+
"react-app/jest"
26+
]
27+
},
28+
"browserslist": {
29+
"production": [
30+
">0.2%",
31+
"not dead",
32+
"not op_mini all"
33+
],
34+
"development": [
35+
"last 1 chrome version",
36+
"last 1 firefox version",
37+
"last 1 safari version"
38+
]
39+
}
40+
}

eros/public/favicon.ico

3.78 KB
Binary file not shown.

eros/public/index.html

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8" />
5+
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1" />
7+
<meta name="theme-color" content="#000000" />
8+
<meta
9+
name="description"
10+
content="Web site created using create-react-app"
11+
/>
12+
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
13+
<!--
14+
manifest.json provides metadata used when your web app is installed on a
15+
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
16+
-->
17+
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
18+
<!--
19+
Notice the use of %PUBLIC_URL% in the tags above.
20+
It will be replaced with the URL of the `public` folder during the build.
21+
Only files inside the `public` folder can be referenced from the HTML.
22+
23+
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
24+
work correctly both with client-side routing and a non-root public URL.
25+
Learn how to configure a non-root public URL by running `npm run build`.
26+
-->
27+
<title>React App</title>
28+
</head>
29+
<body>
30+
<noscript>You need to enable JavaScript to run this app.</noscript>
31+
<div id="root"></div>
32+
<!--
33+
This HTML file is a template.
34+
If you open it directly in the browser, you will see an empty page.
35+
36+
You can add webfonts, meta tags, or analytics to this file.
37+
The build step will place the bundled scripts into the <body> tag.
38+
39+
To begin the development, run `npm start` or `yarn start`.
40+
To create a production bundle, use `npm run build` or `yarn build`.
41+
-->
42+
</body>
43+
</html>

eros/public/logo192.png

5.22 KB
Loading

eros/public/logo512.png

9.44 KB
Loading

eros/public/manifest.json

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"short_name": "React App",
3+
"name": "Create React App Sample",
4+
"icons": [
5+
{
6+
"src": "favicon.ico",
7+
"sizes": "64x64 32x32 24x24 16x16",
8+
"type": "image/x-icon"
9+
},
10+
{
11+
"src": "logo192.png",
12+
"type": "image/png",
13+
"sizes": "192x192"
14+
},
15+
{
16+
"src": "logo512.png",
17+
"type": "image/png",
18+
"sizes": "512x512"
19+
}
20+
],
21+
"start_url": ".",
22+
"display": "standalone",
23+
"theme_color": "#000000",
24+
"background_color": "#ffffff"
25+
}

eros/public/robots.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# https://www.robotstxt.org/robotstxt.html
2+
User-agent: *
3+
Disallow:

eros/src/App.css

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
@import url('https://fonts.googleapis.com/css2?family=Lovers+Quarrel&display=swap');
2+
.App {
3+
text-align: center;
4+
}
5+
6+
.App-logo {
7+
height: 40vmin;
8+
pointer-events: none;
9+
}
10+
11+
@media (prefers-reduced-motion: no-preference) {
12+
.App-logo {
13+
animation: App-logo-spin infinite 20s linear;
14+
}
15+
}
16+
17+
.App-header {
18+
background-color: #282c34;
19+
min-height: 100vh;
20+
display: flex;
21+
align-items: center;
22+
justify-content: center;
23+
flex-direction: column;
24+
color: white;
25+
}
26+
.App-header h2 {
27+
font-family: 'Lovers Quarrel', cursive;
28+
font-size: 100px;
29+
}
30+
.App-link {
31+
color: #61dafb;
32+
}
33+
34+
@keyframes App-logo-spin {
35+
from {
36+
transform: rotate(0deg);
37+
}
38+
to {
39+
transform: rotate(360deg);
40+
}
41+
}

eros/src/App.js

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import React, { useState, useEffect } from 'react';
2+
import logo from './logo.svg';
3+
import Header from './components/Header';
4+
import './App.css';
5+
import Contacts from './components/Contacts';
6+
import AddContact from './components/AddContact';
7+
8+
function App() {
9+
const url = 'http://localhost:5000/contacts';
10+
const [showAddContact, setShowAddContact] = useState(false);
11+
const [contacts, setContacts] = useState([]);
12+
const fetchContacts = async () => {
13+
const res = await fetch(url);
14+
const data = await res.json();
15+
return data;
16+
};
17+
const fetchContact = async (id) => {
18+
const res = await fetch(`${url}/${id}`);
19+
const data = await res.json();
20+
return data;
21+
};
22+
useEffect(() => {
23+
const getGontacts = async () => {
24+
const contactsFromServer = await fetchContacts();
25+
setContacts(contactsFromServer);
26+
};
27+
getGontacts();
28+
}, []);
29+
30+
const deleteContact = async (id) => {
31+
await fetch(`${url}/${id}`, {
32+
method:'DELETE'
33+
});
34+
setContacts(contacts.filter((a) => a.id !== id));
35+
};
36+
const toggleReminder = async (id) => {
37+
const reminderContact = await fetchContact(id);
38+
const updateContact = {...reminderContact, reminder:!reminderContact.reminder}
39+
const res = await fetch (`${url}/${id}`, {
40+
method:'PUT',
41+
headers:{'Content-type':'application/json'},
42+
body:JSON.stringify(updateContact)
43+
})
44+
const data = await res.json();
45+
46+
setContacts(
47+
contacts.map((contact) =>
48+
contact.id === id
49+
? { ...contact, reminder: data.reminder }
50+
: contact
51+
)
52+
);
53+
};
54+
const addContact = async (contact) => {
55+
console.log(JSON.stringify(contact));
56+
const res = await fetch (`${url}`, {
57+
method:'POST',
58+
headers:{'Content-type':'application/json'},
59+
body:JSON.stringify(contact)
60+
})
61+
const data = await res.json();
62+
setContacts([...contacts, data]);
63+
setShowAddContact(false);
64+
// const id = Math.floor(Math.random() * 1000) + 1;
65+
// const newContact = { id, ...contact };
66+
// setContacts([...contacts, newContact]);
67+
};
68+
return (
69+
<div className="App">
70+
<header className="App-header">
71+
<h2>Love Tracker</h2>
72+
<div className="container">
73+
<Header
74+
title="Eros"
75+
onAdd={() => setShowAddContact(!showAddContact)}
76+
showAddContact={showAddContact}
77+
/>
78+
79+
{contacts.length > 0 ? (
80+
<Contacts
81+
contacts={contacts}
82+
onDelete={deleteContact}
83+
onToggleReminder={toggleReminder}
84+
/>
85+
) : (
86+
'No contacts'
87+
)}
88+
{showAddContact && <AddContact onAdd={addContact} />}
89+
</div>
90+
</header>
91+
</div>
92+
);
93+
}
94+
95+
export default App;

eros/src/components/AddContact.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React, { useState } from 'react';
2+
import { RiUserHeartFill } from 'react-icons/all';
3+
function AddContact({ onAdd }) {
4+
5+
const [text, setText] = useState('');
6+
const [day, setDay] = useState('');
7+
const [reminder, setReminder] = useState(false);
8+
const onSubmit = (e) => {
9+
e.preventDefault();
10+
if (!text) {
11+
alert('Please add a text');
12+
return;
13+
}
14+
onAdd({ text, day, reminder });
15+
setText('');
16+
setDay('');
17+
};
18+
return (
19+
<form className="add-form" onSubmit={onSubmit}>
20+
<div className="form-control">
21+
<input
22+
type="text"
23+
placeholder="contact"
24+
onChange={(e) => setText(e.target.value)}
25+
/>
26+
</div>
27+
<div className="form-control">
28+
<input
29+
type="text"
30+
placeholder="birthDay"
31+
onChange={(e) => setDay(e.target.value)}
32+
/>
33+
</div>
34+
<button type="submit" className="btn btn-block">
35+
<RiUserHeartFill className="iconStyle" size={25} />
36+
</button>
37+
</form>
38+
);
39+
}
40+
41+
export default AddContact;

eros/src/components/Button.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { HiHeart, HiOutlineHeart } from 'react-icons/all';
4+
const Button = ({ color, onClick, showAdd }) => {
5+
6+
return (
7+
<button onClick={onClick}>
8+
{showAdd ? <HiHeart className="" size={35} /> :
9+
<HiOutlineHeart className="" size={35} />}
10+
</button>
11+
);
12+
};
13+
Button.defaultProps = {
14+
color: 'steelblue',
15+
};
16+
Button.prototype = {
17+
text: PropTypes.string,
18+
color: PropTypes.string,
19+
onClick:PropTypes.func
20+
};
21+
export default Button;

0 commit comments

Comments
 (0)