@@ -10,8 +10,7 @@ import MaterialIcon from 'react-native-vector-icons/dist/MaterialCommunityIcons'
10
10
// import { processFiles } from '~/src/shared/processFiles';
11
11
import GistFileItem from './components/GistFileItem' ;
12
12
import forOwn from 'lodash/forOwn' ;
13
- import { requestStarGist , checkStarredGist } from '../../api' ;
14
- import { starGist , fetchInitialFavoriteValue } from '../gists.actiontype' ;
13
+ import { starGist , fetchInitialFavoriteValue , UnstarGist } from '../gists.actiontype' ;
15
14
16
15
const HeaderProps = [
17
16
'avatal_url' ,
@@ -29,24 +28,17 @@ const ToolbarContentContainer = styled.View`
29
28
30
29
class GistDetails extends React . Component {
31
30
state = {
32
- iconName : 'star-o' ,
31
+ iconName : this . props . isStarred ? 'star' : 'star-o' ,
33
32
}
34
33
35
34
componentWillMount ( ) {
36
- const data = this . props . checkIfGistIsStarred ( this . props . navigation . getParam ( 'gistData' ) . id ) ;
37
-
38
- console . log ( 'data------------------------------' , data ) ;
35
+ this . props . checkIfGistIsStarred ( this . props . navigation . getParam ( 'gistData' ) . id ) ;
39
36
}
40
37
41
38
componentWillReceiveProps ( nextProps ) {
42
- console . log ( '(((((((((((((((((((((((((((((((' , nextProps ) ;
43
- if ( nextProps . isStarred ) {
44
- this . setState ( {
45
- iconName : 'star' ,
46
- } ) ;
47
- } else {
48
- this . setState ( { iconName : 'star-o' } ) ;
49
- }
39
+ this . setState ( {
40
+ iconName : nextProps . isStarred ? 'star' : 'star-o' ,
41
+ } ) ;
50
42
}
51
43
52
44
handleFileItemPress = fileData => {
@@ -56,11 +48,22 @@ class GistDetails extends React.Component {
56
48
}
57
49
58
50
handleActionButtonClick = ( ) => {
59
- // requestStarGist(this.props.accessToken, this.props.navigation.getParam('gistData').id)
60
- // .then(() => this.setState({ iconName: 'star' }))
61
- // .catch(error => console.log(error));
62
- this . setState ( { iconName : 'star' } ) ;
63
- this . props . starThisGist ( this . props . navigation . getParam ( 'gistData' ) . id ) ;
51
+ const { id } = this . props . navigation . getParam ( 'gistData' ) ;
52
+
53
+ if ( this . state . iconName === 'star' ) {
54
+ this . props . UnstarThisGist ( id ) ;
55
+ this . setState ( {
56
+ iconName : 'star-o' ,
57
+ } ) ;
58
+ } else {
59
+ this . props . starThisGist ( id ) ;
60
+ this . setState ( {
61
+ iconName : 'star' ,
62
+ } ) ;
63
+ }
64
+
65
+ // this.setState({ iconName: 'star' });
66
+ // this.props.starThisGist(this.props.navigation.getParam('gistData').id);
64
67
}
65
68
66
69
processFiles = fileData => {
@@ -82,8 +85,6 @@ class GistDetails extends React.Component {
82
85
) ;
83
86
84
87
renderToobarContent = ( ) => {
85
- console . log ( '777777777777777777777777777777777' , this . state . iconName ) ;
86
-
87
88
return (
88
89
< ToolbarContentContainer >
89
90
< TouchableOpacity onPress = { this . handleActionButtonClick } >
@@ -134,6 +135,7 @@ class GistDetails extends React.Component {
134
135
const mapDispatchToProps = dispatch => ( {
135
136
starThisGist : id => dispatch ( starGist . action ( id ) ) ,
136
137
checkIfGistIsStarred : id => dispatch ( fetchInitialFavoriteValue . action ( id ) ) ,
138
+ UnstarThisGist : id => dispatch ( UnstarGist . action ( id ) ) ,
137
139
} ) ;
138
140
139
141
const mapStateToProps = ( { initialFavoriteValue } ) =>
0 commit comments