Youtube music and video downloader

App.jsx 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import React, { Component, PropTypes } from 'react';
  2. import ReactDOM from 'react-dom';
  3. import { Meteor } from 'meteor/meteor';
  4. import { createContainer } from 'meteor/react-meteor-data';
  5. import { Links } from '../api/links.js';
  6. import Link from './Link.jsx';
  7. import AccountsUIWrapper from './AccountsUIWrapper.jsx';
  8. // App component - represents the whole app
  9. class App extends Component {
  10. constructor(props) {
  11. super(props);
  12. this.state = { };
  13. }
  14. renderLinks() {
  15. return this.props.links.map((link) => {
  16. return (
  17. <Link key={link._id} link={link} />
  18. )
  19. });
  20. }
  21. handleSubmit(event) {
  22. event.preventDefault();
  23. // Find the text field via the React ref
  24. const text = ReactDOM.findDOMNode(this.refs.textInput).value.trim();
  25. Meteor.call('links.insert', text);
  26. // Clear form
  27. ReactDOM.findDOMNode(this.refs.textInput).value = '';
  28. }
  29. render() {
  30. return (
  31. <div className="container">
  32. <h1 className="logo">SoundWave</h1>
  33. <div className="box-container">
  34. <header>
  35. <AccountsUIWrapper />
  36. <form className="new-link" onSubmit={this.handleSubmit.bind(this)}>
  37. <input type="text" ref="textInput" placeholder="Search a video" />
  38. </form>
  39. </header>
  40. <ul>{ this.renderLinks() }</ul>
  41. </div>
  42. </div>
  43. );
  44. }
  45. }
  46. App.propTypes = {
  47. links: PropTypes.array.isRequired,
  48. currentUser: PropTypes.object,
  49. };
  50. export default createContainer(() => {
  51. Meteor.subscribe('links');
  52. return {
  53. links: Links.find({}, {sort: {createdAt: -1}}).fetch(),
  54. currentUser: Meteor.user(),
  55. };
  56. }, App);