Created
April 28, 2019 18:35
-
-
Save mjrb/a7f16ffddbddd5f6910ce278b2633d14 to your computer and use it in GitHub Desktop.
using firebase for mentorq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import logo from './logo.svg'; | |
import './App.css'; | |
import firebase from "firebase"; | |
import {LcsClient} from "js-lcs-client"; | |
var defaultApp = firebase.initializeApp({ | |
apiKey: "", | |
authDomain: "", | |
projectId: "", | |
databaseURL: "" | |
}); | |
window.db = firebase.database(); | |
console.log(defaultApp.name); | |
window.client = new LcsClient("client"); | |
class App extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
tix: [] | |
}; | |
firebase.database().ref("/").on("value", snapshot => { | |
console.log(snapshot); | |
window.snap = snapshot; | |
this.setState({tix: Object.values(snapshot.val())}); | |
}); | |
} | |
addTicket = () => { | |
const desc = document.querySelector("#desc").value; | |
console.log(desc); | |
firebase.database().ref("/").push().set({ | |
desc, | |
mentee: "user" | |
}); | |
} | |
render() { | |
return ( | |
<div className="App"> | |
<ul> | |
{this.state.tix.map(ticket => <li>{ticket.desc}</li>)} | |
</ul> | |
<div> | |
<input id="desc" type="text"/> | |
<button onClick={this.addTicket}>add ticket</button> | |
</div> | |
</div> | |
); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment