Advertisement
Guest User

Untitled

a guest
Apr 26th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. // var client = new ImapClient('mail.yatekii.ch', 143, {
  2. // auth: {
  3. // user: 'yatekii@yatekii.ch',
  4. // pass: 'VERYSECRET'
  5. // }
  6. // }
  7. // )
  8. // client.onerror = function(error){console.log(error);}
  9. // client.connect().then(() => { console.log('wrks'); });
  10.  
  11. import React from 'react';
  12. import ReactDOM from 'react-dom';
  13.  
  14. var Mailbox = React.createClass({
  15.  
  16. getInitialState: function () {
  17. return {
  18. name: this.props.name,
  19. emails: {
  20. length: 0,
  21. },
  22. };
  23. },
  24.  
  25. getData: function () {
  26. // Set state (number of emails e.g.)
  27. },
  28.  
  29. shouldComponentUpdate: function (nextProps, nextState) {
  30. return true
  31. },
  32.  
  33. render: function () {
  34. return (
  35. <a className={ "mailbox " + (this.props.selected ? 'active ' : '') + "item" } onClick={ this.props.onClick }>
  36. <i className="inbox icon"></i>
  37. {this.state.name}
  38. <div className="ui red label">{this.state.emails.length}</div>
  39. </a>
  40. );
  41. }
  42. });
  43.  
  44. var Mail = React.createClass({
  45.  
  46. getInitialState: function () {
  47. return {
  48. _id: this.props._id,
  49. content: {
  50. from: this.props.content.from,
  51. subject: this.props.content.subject,
  52. body: this.props.content.body,
  53. },
  54. };
  55. },
  56.  
  57. getData: function () {
  58. // Set state (number of emails e.g.)
  59. },
  60.  
  61. shouldComponentUpdate: function (nextProps, nextState) {
  62. return true
  63. },
  64.  
  65. render: function () {
  66. return (
  67. <div className={"item" + ( this.props.selected ? ' active' : ' card' )} onClick={ this.props.onClick }>
  68. <img className="ui avatar image" src="helen.jpg" />
  69. <div className="content">
  70. <div className="header">{ this.state.content.from }</div>
  71. { this.state.content.subject }<br/>
  72. { this.state.content.body }
  73. </div>
  74. </div>
  75. );
  76. }
  77. });
  78.  
  79. var App = React.createClass({
  80.  
  81. getInitialState() {
  82. return {
  83. value: null,
  84. selectedMailbox: null,
  85. selectedMail: null,
  86. };
  87. },
  88.  
  89. componentDidMount() {
  90. $('.ui.sidebar')
  91. .sidebar('setting', 'transition', 'push')
  92. .sidebar('setting', 'dimPage', false)
  93. .sidebar('setting', 'closeable', true);
  94.  
  95. $('button#toggleMailboxes').click(function(event){
  96. $('.ui.sidebar')
  97. .sidebar('toggle');
  98. });
  99. this.selected
  100. },
  101.  
  102. componentDidUpdate() {
  103. },
  104.  
  105. onMailboxClick(i){
  106. this.setState({selectedMailbox: i});
  107. },
  108.  
  109. getMailboxes() {
  110. return [
  111. { _id: 1, name: 'Inbox' },
  112. { _id: 2, name: 'Sent' },
  113. { _id: 3, name: 'Junk' },
  114. ];
  115. },
  116.  
  117. renderMailboxes() {
  118. return this.getMailboxes().map((mailbox, i) => (
  119. <Mailbox key={ mailbox._id } name={ mailbox.name } selected={ this.state.selectedMailbox === mailbox._id } onClick={ this.onMailboxClick.bind(this, mailbox._id) }/>
  120. ));
  121. },
  122.  
  123. onMailClick(i){
  124. this.setState({selectedMail: i});
  125. },
  126.  
  127. getMails() {
  128. return [
  129. { _id: 1, content: { from: 'doedelhoch42@gmail.com', subject: 'An excellent companion', body: 'This is a first test.' }},
  130. { _id: 2, content: { from: 'doedelhoch42@gmail.com', subject: 'An excellent companion', body: 'This is a first test.' }},
  131. { _id: 3, content: { from: 'doedelhoch42@gmail.com', subject: 'An excellent companion', body: 'This is a first test.' }},
  132. ];
  133. },
  134.  
  135. renderMails() {
  136. return this.getMails().map((mail, i) => (
  137. <Mail key={mail._id} content={ mail.content } selected={ this.state.selectedMail === mail._id } onClick={ this.onMailClick.bind(this, mail._id) }/>
  138. ));
  139. },
  140.  
  141. render() {
  142. return (
  143. <div>
  144. <div id="sidebar_mailboxes" className="ui sidebar vertical menu">
  145. <div className="item header">
  146. Mailboxes
  147. </div>
  148. { this.renderMailboxes() }
  149. </div>
  150. <div className="pusher">
  151. <div className="ui divided grid" id="main-grid">
  152. <div className="ui four wide column" id="mail-menu">
  153. <div className="ui divided vertical centered list">
  154. { this.renderMails() }
  155. <div className="item">
  156. <button className="ui grey basic button align center" id="toggleMailboxes">Toggle Mailboxes</button>
  157. </div>
  158. </div>
  159. </div>
  160. <div className="ui twelve wide column">
  161. From: doedelhoch42@gmail.com<br />
  162. Subject: An excellent companion<br />
  163. Body: Blabla this is some content!
  164. </div>
  165. </div>
  166. </div>
  167. </div>
  168. );
  169. }
  170. });
  171.  
  172. // $(document).ready(function() {
  173. // ReactDOM.render(<Container />, document.getElementById('container'));
  174. // }, false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement