Skip to content

Commit 064181d

Browse files
authored
Merge pull request #2 from epythonlab/react
React Login UI
2 parents e210be1 + 9a8f015 commit 064181d

File tree

14 files changed

+445
-3
lines changed

14 files changed

+445
-3
lines changed

nodejs/console.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* frequently used to log some sort of output */
2+
console.log('This is my first node js');
3+
/* explicitly delivers a warning to the console */
4+
console.warn();
5+
/* explicitly delivers an error message to the console
6+
You can log an error as a string or as an object.
7+
If logged as a new Error(), a traceback will be
8+
included as part of the message
9+
*/
10+
console.error();
11+
/* Logs a traceback when an error occurs in your code.
12+
Gives line number and column number of the file that
13+
the error probably occurred */
14+
console.trace();

nodejs/data.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1,Asibeh,Tenager,asibeh@gmail.com,female
2+
2,Fuad,Mohammed,fuad@gail.com,male
3+
3,Alemstehay,Melese,Alemstehay@gamil.com,female

nodejs/first.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Load HTTP module
2+
const http = require("http");
3+
const hostname = "127.0.0.1";
4+
const port = 8000;
5+
// Create HTTP server
6+
const server = http.createServer(function (req, res) {
7+
// Set the response HTTP header with HTTP status and
8+
// Content type
9+
res.writeHead(200, { "Content-Type": "text/plain" });
10+
11+
// Send the response body "Hello World"
12+
res.end("Welcome to Sage Training Institute\n");
13+
});
14+
// Prints a log once the server starts listening
15+
server.listen(port, hostname, function () {
16+
console.log(`Server running at http://${hostname}:${port}/`);
17+
});

nodejs/readFile.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const fs = require('fs')
2+
// with readFile
3+
fs.readFile('data.txt', 'utf-8', (err, data) =>{
4+
if (err){
5+
console.error(err)
6+
return
7+
}
8+
let array = data.split('\n')
9+
// props are id, first_name, last_name, email, gender
10+
let mapped = array.map(person =>{
11+
/* Map is a type of data structure or data collection
12+
that is used to store the data in the form of key and value pairs
13+
*/
14+
let new_person = person.split(',');
15+
return new Object({
16+
id: new_person[0],
17+
first_name: new_person[1],
18+
last_name: new_person[2],
19+
email: new_person[3],
20+
gender: new_person[4]
21+
22+
})
23+
});
24+
console.log(mapped)
25+
});
26+
console.log('Hit!')

nodejs/readFileSync.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const fs = require('fs')
2+
try{
3+
const data = fs.readFileSync('data.txt', 'utf-8')
4+
let array = data.split('\n')
5+
// props are id, first_name, last_name, email, gender
6+
let mapped = array.map(person =>{
7+
let new_person = person.split(',')
8+
return new Object({
9+
id: new_person[0],
10+
first_name: new_person[1],
11+
last_name: new_person[2],
12+
email: new_person[3],
13+
gender: new_person[4]
14+
})
15+
});
16+
console.log(mapped)
17+
}catch(err){
18+
console.error(err)
19+
}
20+
console.log('Hit!')

react/reactapp/package-lock.json

Lines changed: 62 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

react/reactapp/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"@testing-library/user-event": "^13.5.0",
99
"react": "^18.2.0",
1010
"react-dom": "^18.2.0",
11+
"react-router-dom": "^6.8.2",
1112
"react-scripts": "5.0.1",
1213
"web-vitals": "^2.1.4"
1314
},

react/reactapp/public/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
1616
-->
1717
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
18+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css" integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ==" crossorigin="anonymous" referrerpolicy="no-referrer" />
1819
<!--
1920
Notice the use of %PUBLIC_URL% in the tags above.
2021
It will be replaced with the URL of the `public` folder during the build.
@@ -39,5 +40,6 @@
3940
To begin the development, run `npm start` or `yarn start`.
4041
To create a production bundle, use `npm run build` or `yarn build`.
4142
-->
43+
4244
</body>
4345
</html>

react/reactapp/src/AjaxApi.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* Ajax API call with react hooks */
2+
import './bmi.css';
3+
import {useState, useEffect} from 'react';
4+
function AjaxApi(){
5+
6+
const [error, setError] = useState(null);
7+
const [isLoaded, setIsLoaded] = useState(false);
8+
const [items, setItems] = useState([]);
9+
// Note: the empty deps array [] means
10+
11+
useEffect(()=>{
12+
document.title ='AjaxApi Call';
13+
})
14+
// this useEffect will run once
15+
useEffect(() => {
16+
/* The Fetch API through the fetch() method
17+
allows us to make an HTTP request to the backend.*/
18+
fetch("https://mocki.io/v1/d4867d8b-b5d5-4a48-a4ab-79131b5809b8")
19+
.then(res => res.json())
20+
.then(
21+
(result)=> {
22+
setIsLoaded(true);
23+
setItems(result)
24+
},
25+
/* Note: it is important to handle error here
26+
instead of a catch() block so that we don't swallow
27+
exceptions from actual bugs in components.
28+
*/
29+
(error) => {
30+
setIsLoaded(true);
31+
setError(error);
32+
}
33+
)
34+
},[])
35+
if (error) {
36+
return <div className="container"> Error: {error.message} </div>;
37+
}else if(!isLoaded){
38+
return <div>Loading...</div>;
39+
}else{
40+
return (
41+
<div className="app">
42+
<ul className='container'>
43+
{items.map(item => (
44+
<li key={item.id} className='txtCenter'>
45+
Name:{item.name}, City: {item.city}
46+
</li>
47+
))}
48+
</ul>
49+
</div>
50+
);
51+
}
52+
}
53+
export default AjaxApi;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*JUMP STEP 2 - 6
2+
------------------
3+
2. INSTALL react router with npm in your react project
4+
$ npm install react-router-dom
5+
6+
3.CREATE the following directory in src
7+
src/components
8+
4. CREATE the following components in src/components directory
9+
- src/components/Dashboard.js
10+
- src/components/Preferences.js
11+
5. Go to App.js and route required components
12+
13+
6. After routes are added in App.js, go to index.js
14+
*/

react/reactapp/src/components/Preferences.js

Whitespace-only changes.

0 commit comments

Comments
 (0)