File tree Expand file tree Collapse file tree 6 files changed +71
-7
lines changed Expand file tree Collapse file tree 6 files changed +71
-7
lines changed Original file line number Diff line number Diff line change 1
1
.vscode
2
- node_modules
2
+ node_modules
3
+ .env
Original file line number Diff line number Diff line change @@ -21,6 +21,9 @@ The DB of choice for this project will be PostgreSQL. I wanted to learn some SQL
21
21
#### Nice to haves
22
22
23
23
Storybook - UI Component Library
24
+
24
25
Sort by trending - have some sort of trending algorithm
26
+
25
27
Users, authentication, restricting number of upvotes to a single time
28
+
26
29
Editing Tweets by author
Original file line number Diff line number Diff line change 1
1
import React , { Component } from 'react' ;
2
2
import './App.css' ;
3
+ import AddTweet from './containers/AddTweet' ;
3
4
import SortableTweetList from './containers/SortableTweetList' ;
4
5
5
6
class App extends Component {
6
7
render ( ) {
7
8
return (
8
9
< div className = "App" >
10
+ < AddTweet />
9
11
< SortableTweetList />
10
12
</ div >
11
13
) ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import PropTypes from 'prop-types' ;
3
+ import { connect } from 'react-redux' ;
4
+
5
+ import { addTweet } from '../actions/actions' ;
6
+
7
+ const mapDispatchToProps = dispatch => ( {
8
+ onSubmit : tweet => dispatch ( addTweet ( tweet ) )
9
+ } ) ;
10
+
11
+ class AddTweet extends React . Component {
12
+ state = {
13
+ text : ''
14
+ } ;
15
+
16
+ inputRef = React . createRef ( ) ;
17
+
18
+ onInputChange = ( ) => {
19
+ const { value } = this . inputRef . current ;
20
+ this . setState ( {
21
+ text : value
22
+ } ) ;
23
+ } ;
24
+
25
+ onFormSubmit = e => {
26
+ e . preventDefault ( ) ;
27
+
28
+ if ( ! this . inputRef . current . value . trim ( ) ) return ;
29
+
30
+ this . props . onSubmit ( {
31
+ text : this . state . text ,
32
+ createdAt : new Date ( ) ,
33
+ likes : 0 ,
34
+ id : Math . floor ( Math . random ( ) * 1000 )
35
+ } ) ;
36
+
37
+ this . inputRef . current . value = '' ;
38
+ this . setState ( {
39
+ text : ''
40
+ } ) ;
41
+ } ;
42
+
43
+ render ( ) {
44
+ return (
45
+ < div >
46
+ < form onSubmit = { this . onFormSubmit } >
47
+ < input type = "text" ref = { this . inputRef } onChange = { this . onInputChange } />
48
+ < button type = "submit" disabled = { this . state . text . length <= 0 } >
49
+ Submit
50
+ </ button >
51
+ </ form >
52
+ </ div >
53
+ ) ;
54
+ }
55
+ }
56
+
57
+ AddTweet . propTypes = {
58
+ onSubmit : PropTypes . func . isRequired
59
+ } ;
60
+
61
+ export default connect (
62
+ undefined ,
63
+ mapDispatchToProps
64
+ ) ( AddTweet ) ;
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments