Skip to content

Commit c2bcaee

Browse files
committed
Update
1 parent b899f7b commit c2bcaee

File tree

9 files changed

+113
-5
lines changed

9 files changed

+113
-5
lines changed

package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"auto-bind": "^1.2.1",
2828
"react": "^16.5.0",
2929
"react-dom": "^16.5.0",
30+
"react-file-reader": "^1.1.4",
3031
"react-router-dom": "^4.3.1"
3132
}
3233
}

src/components/App.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import React from 'react'
2-
import Header from './Header'
3-
import Main from './Main'
1+
import React from 'react';
2+
import Header from './Header';
3+
import Main from './Main';
44

55
export default class App extends React.Component {
66
render() {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React from 'react';
2+
import UrlVisualizer from './UrlVisualizer';
3+
const autoBind = require('auto-bind');
4+
5+
export default class Assignment2 extends React.Component {
6+
constructor(props) {
7+
super(props);
8+
autoBind(this);
9+
this.state = {
10+
urls: []
11+
};
12+
}
13+
14+
openFile(e) {
15+
let input = e.target;
16+
let reader = new FileReader();
17+
reader.onload = () => {
18+
let str = reader.result;
19+
let arr = str.split(/[\r\n]+/g);
20+
this.setState({urls: arr});
21+
console.log(this.state.urls);
22+
};
23+
reader.readAsText(input.files[0]);
24+
}
25+
26+
render() {
27+
let url_array = this.state.urls;
28+
console.log("url_array: " + url_array);
29+
let msg = "hi";
30+
return (
31+
<div>
32+
<input type='file' accept='text/plain'
33+
onChange={e => this.openFile(e)} />
34+
<UrlVisualizer urls={url_array} />
35+
</div>
36+
)
37+
}
38+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react';
2+
3+
const ImportFromFileBodyComponent = () => {
4+
let fileReader;
5+
6+
const handleFileReader = (e) => {
7+
const content = fileReader.result;
8+
console.log(content);
9+
};
10+
11+
const handleFileChosen = (file) => {
12+
fileReader = new FileReader();
13+
fileReader.onloadend = handleFileRead;
14+
fileReader.readAsText(file);
15+
};
16+
17+
return
18+
<div className="upload-expense">
19+
<input type="file" id="file" className="input-file"
20+
onChange={e => handleFileChosen(e.target.files[0])} />
21+
</div>
22+
}
23+
24+
export default ImportFromFileBodyComponent;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react';
2+
const autoBind = require('auto-bind');
3+
4+
export default class UrlVisualizer extends React.Component {
5+
constructor(props) {
6+
super(props);
7+
autoBind(this);
8+
}
9+
10+
11+
12+
render() {
13+
return (
14+
<div>
15+
<h3>Current time: {new Date().toLocaleTimeString()}</h3>
16+
<h4>Urls length: {this.props.urls.length}</h4>
17+
</div>
18+
)
19+
}
20+
}

src/components/Header.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ export default class Header extends React.Component {
3232
<ul class="dropdown-menu">
3333
<li><a href="https://www.zybooks.com/" target="_blanks">Zybooks</a></li>
3434
<li><Link to="/">Assignment 1</Link></li>
35+
<li>
36+
<Link to="/Assignment2">
37+
Assignment 2
38+
</Link>
39+
</li>
3540
</ul>
3641
</li>
3742
<li><Link to="/UserInfo">User Info</Link>

src/components/Main.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import React from 'react'
2-
import { Switch, Route } from 'react-router-dom'
1+
import React from 'react';
2+
import { Switch, Route } from 'react-router-dom';
33
import Home from './Home';
44
import UserInfo from './UserInfo';
5+
import Assignment2 from './Assignment2/Assignment2';
56

67
// The Main component renders one of the provided
78
// Routes (provided that one matches).
@@ -13,6 +14,7 @@ export default class Main extends React.Component {
1314
<Switch>
1415
<Route exact path="/" component={Home} />
1516
<Route path="/UserInfo" component={UserInfo} />
17+
<Route path="/Assignment2" component={Assignment2} />
1618
</Switch>
1719
</main>
1820
)

urls.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
https://www.youtube.com/watch?v=QZl3ohphHSE&t=8341s
2+
https://developer.mozilla.org/en-US/docs/Web/API/URL
3+
https://www.cs.qc.cuny.edu/
4+
https://www.google.com/

0 commit comments

Comments
 (0)