Skip to content

Instantly share code, notes, and snippets.

@mjrb
Created April 28, 2019 18:35
Show Gist options
  • Save mjrb/a7f16ffddbddd5f6910ce278b2633d14 to your computer and use it in GitHub Desktop.
Save mjrb/a7f16ffddbddd5f6910ce278b2633d14 to your computer and use it in GitHub Desktop.
using firebase for mentorq
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