-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathotherstuff.js
90 lines (83 loc) · 2.21 KB
/
otherstuff.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import React from 'react';
import ReactDOM from 'react-dom';
import {
BrowserRouter as Router,
NavLink as Link,
Route
} from 'react-router-dom';
var config = {
apiKey: "AIzaSyCIhiU_oFNeLMKBknUiFwmCgFY9lPPOGWk",
authDomain: "makeupstash-a40d9.firebaseapp.com",
databaseURL: "https://makeupstash-a40d9.firebaseio.com",
projectId: "makeupstash-a40d9",
storageBucket: "makeupstash-a40d9.appspot.com",
messagingSenderId: "797334375717"
};
firebase.initializeApp(config);
const database = firebase.database().ref('/makeupStash');
class App extends React.Component {
constructor() {
super();
this.state = {
inventoryListItem: []
}
this.handleSubmit = this.handleSubmit.bind(this);
this.handleChange = this.handleChange.bind(this);
}
// Remove onChange. Not necessary for site's functionality
handleChange(e) {
this.setState({
[e.target.name]: e.target.value
});
}
handleSubmit(e) {
e.preventDefault();
console.log(database);
const {inventoryListItem} = this.state;
inventoryListItem.push(this.state.inventoryListItem);
this.setState({
inventoryListItem: []
});
}
componentDidMount() {
database.on('value', (snapshot) => {
const databaseListItems = snapshot.val();
const newListItems = [];
for (let key in databaseListItems) {
// Console.log so you know what's going on
// console.log('key', key);
// console.log('todos', dbTodos[key]);
newListItems.push({
key: key,
description: databaseListItems[key]
});
}
// console.log(newTodos);
this.setState({
inventoryListItem: newListItems
});
});
}
render() {
return(
<main>
<h1>Makeup Stash</h1>
<form onSubmit={this.handleSubmit}>
<h2>Personal Inventory</h2>
<input name="inventoryListItem" type="text" placeholder="Enter Makeup Product"/>
<input type="submit" onChange={this.handleChange} value={this.state.inventoryListItem} value="Add to Inventory"/>
<ul>
</ul>
</form>
<form>
<h2>Wishlist</h2>
<input name="wishListItem" type="text" placeholder="Enter Makeup Product"/>
<input type="submit" value="Add to Wishlist"/>
</form>
<ul>
</ul>
</main>
)
}
}
ReactDOM.render(<App/>, document.getElementById('app'));