Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import fire from './config/Fire';
  3.  
  4. import './App.css';
  5.  
  6. class Conversations extends Component{
  7. constructor(props){
  8. super(props);
  9. this.state = {
  10. thisUser: props.username
  11. }
  12. }
  13.  
  14. loadConversations = () =>{
  15. let collectionRef = fire.firestore().collection('messages');
  16. collectionRef.get().then(function(collection){
  17. collection.forEach(function(doc){
  18. console.log(doc.id, " => ", doc.data());
  19. })
  20.  
  21. }).catch((error)=>{
  22. let errorMessage = error;
  23. console.log(errorMessage);
  24. })
  25. }
  26.  
  27.  
  28. render(){
  29. return(
  30. <div>
  31. <button type = "submit" onClick = {this.loadConversations}>Load</button>
  32. </div>
  33. )
  34. }
  35. }
  36.  
  37. class Messages extends Component{
  38. constructor(props){
  39. super(props);
  40. this.state = {
  41. msg: "",
  42. otherUser: "",
  43. thisUser: props.username
  44. }
  45. }
  46.  
  47. loadMessages = (other) =>{
  48.  
  49. }
  50.  
  51. writeMessage = (other) =>{
  52.  
  53. }
  54.  
  55. handleChange = (e) =>{
  56. this.setState({[e.target.name]: e.target.value});
  57. }
  58.  
  59. render(){
  60. return(
  61. //html
  62. <div>
  63.  
  64. <form>
  65. <label>Type a message:
  66. <input type = "text" name = "msg" id= "msg" value = {this.state.msg} onChange = {this.handleChange}/>
  67. <button type = "submit" onClick = {this.loadMessages}>Send</button>
  68. </label>
  69.  
  70. </form>
  71.  
  72.  
  73. </div>
  74.  
  75. )
  76. }
  77.  
  78.  
  79.  
  80. }
  81.  
  82. export default Conversations;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement