Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d7abfb5

Browse files
committedApr 18, 2016
Add doc for last components
1 parent b1cdf83 commit d7abfb5

File tree

3 files changed

+78
-117
lines changed

3 files changed

+78
-117
lines changed
 

‎step-8/readme.md

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,11 +388,85 @@ La liste de sélection des vins pourrait également afficher une miniature de la
388388

389389
### Fiche de détail d'un vin
390390

391-
// TODO
391+
La fiche de détail d'un vin est laissée à votre imagination, n'hésitez pas a consulter [la documentation `react-native`](https://facebook.github.io/react-native/docs/getting-started.html) pour voir les possibilités offertes par le framework.
392+
393+
La structure technique du composant `src/components/wine.js` est cependant la suivante :
394+
395+
```javascript
396+
import React, { PropTypes, Image, View, Text, ScrollView, TouchableWithoutFeedback } from 'react-native';
397+
import { connect } from 'react-redux';
398+
import { fetchWine, fetchWineLiked, setTitle, toggleWineLiked } from '../actions';
399+
import { styles } from './style';
400+
import { apiHost } from '../actions';
401+
402+
const mapStateToProps = (state) => {
403+
return {
404+
currentWine: state.currentWine.wine,
405+
liked: state.currentWine.liked
406+
};
407+
}
408+
409+
export const Wine = connect(mapStateToProps)(React.createClass({
410+
componentDidMount() {
411+
this.props.dispatch(fetchWine(this.props.wine.id)).then(() => {
412+
this.props.dispatch(fetchWineLiked(this.props.wine.id));
413+
});
414+
},
415+
416+
handleToggleLike() {
417+
this.props.dispatch(toggleWineLiked(this.props.wine.id));
418+
},
419+
420+
render() {
421+
const { wine, liked } = this.props;
422+
return (
423+
...
424+
);
425+
}
426+
}));
427+
```
392428

393429
### Commentaires
394430

395-
// TODO
431+
Le composant de commentaire est extrêment similaire à la version web, vous avez à votre disposition le composant `<TexInput />` offert par `react-native` et un composant `<Button />` dans le dossier `src/components`
432+
433+
```javascript
434+
import React, { PropTypes, View, Text, TextInput } from 'react-native';
435+
import moment from 'moment';
436+
import { connect } from 'react-redux';
437+
import { addComment, fetchComments, postComment } from '../actions';
438+
import { styles } from './style';
439+
import { Button } from './button';
440+
441+
const mapStateToProps = (state) => {
442+
return {
443+
comments: state.currentWine.comments
444+
};
445+
}
446+
447+
export const Comments = connect(mapStateToProps)(React.createClass({
448+
getInitialState() {
449+
return {
450+
commentTitle: '',
451+
commentBody: ''
452+
};
453+
},
454+
455+
handlePostComment() {
456+
const payload = { title: this.state.commentTitle, content: this.state.commentBody };
457+
this.props.dispatch(postComment(this.props.wineId, payload)).then(() => {
458+
...
459+
this.setState({ commentTitle: '', commentBody: '' });
460+
});
461+
},
462+
463+
render() {
464+
return (
465+
...
466+
);
467+
}
468+
}));
469+
```
396470

397471
## A vous de jouer !
398472

‎step-8/src/components/comments.js

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -14,74 +14,23 @@ const mapStateToProps = (state) => {
1414
}
1515

1616
export const Comments = connect(mapStateToProps)(React.createClass({
17-
18-
propTypes: {
19-
comments: PropTypes.array,
20-
dispatch: PropTypes.func.isRequired,
21-
wineId: PropTypes.string.isRequired
22-
},
23-
2417
getInitialState() {
2518
return {
2619
commentTitle: '',
2720
commentBody: ''
2821
};
2922
},
3023

31-
componentDidMount() {
32-
this.updateComments();
33-
},
34-
35-
updateComments() {
36-
this.props.dispatch(fetchComments(this.props.wineId));
37-
},
38-
39-
handleCommentTitleChange(commentTitle) {
40-
this.setState({ commentTitle });
41-
},
42-
43-
handleCommentBodyChange(commentBody) {
44-
this.setState({ commentBody });
45-
},
46-
4724
handlePostComment() {
4825
const payload = { title: this.state.commentTitle, content: this.state.commentBody };
4926
this.props.dispatch(postComment(this.props.wineId, payload)).then(() => {
50-
this.updateComments();
51-
this.props.dispatch(addComment());
5227
this.setState({ commentTitle: '', commentBody: '' });
5328
});
5429
},
5530

5631
render() {
5732
return (
58-
<View>
59-
<Text style={styles.commentsTitle}>Comments</Text>
60-
{
61-
this.props.comments.map(comment =>
62-
<View key={comment.date.toString()} style={styles.comment}>
63-
<Text style={styles.commentTitle}>{comment.title} (le {moment(comment.date).format('DD/MM/YYYY à HH:mm:ss')})</Text>
64-
<Text>{comment.content}</Text>
65-
</View>
66-
)
67-
}
68-
<View style={styles.commentForm}>
69-
<TextInput
70-
style={styles.inputText}
71-
onChangeText={this.handleCommentTitleChange}
72-
placeholder="Titre du commentaire"
73-
value={this.state.commentTitle} />
74-
<TextInput
75-
style={styles.inputText}
76-
onChangeText={this.handleCommentBodyChange}
77-
placeholder="Commentaire"
78-
multiline={true}
79-
value={this.state.commentBody} />
80-
<Button
81-
action={this.handlePostComment}
82-
style={styles.commentButton}>Commenter</Button>
83-
</View>
84-
</View>
33+
<Text>comments</Text>
8534
);
8635
}
8736
}));

‎step-8/src/components/wine.js

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -14,47 +14,9 @@ const mapStateToProps = (state) => {
1414
};
1515
}
1616

17-
const Label = React.createClass({
18-
propTypes: {
19-
children: PropTypes.string
20-
},
21-
render() {
22-
return (
23-
<Text style={styles.label}>{this.props.children}</Text>
24-
);
25-
}
26-
});
27-
28-
const LabelValue = React.createClass({
29-
propTypes: {
30-
children: PropTypes.string
31-
},
32-
render() {
33-
return (
34-
<Text style={styles.labelValue}>{this.props.children}</Text>
35-
);
36-
}
37-
});
38-
3917
export const Wine = connect(mapStateToProps)(React.createClass({
40-
propTypes: {
41-
dispatch: PropTypes.func.isRequired,
42-
liked: PropTypes.bool,
43-
region: PropTypes.string,
44-
wine: PropTypes.shape({
45-
id: PropTypes.string,
46-
name: PropTypes.string,
47-
type: PropTypes.oneOf(['Rouge', 'Blanc', 'Rosé', 'Effervescent', 'Moelleux']),
48-
appellation: PropTypes.shape({
49-
name: PropTypes.string,
50-
region: PropTypes.string
51-
}),
52-
grapes: PropTypes.arrayOf(PropTypes.string)
53-
})
54-
},
5518
componentDidMount() {
5619
this.props.dispatch(fetchWine(this.props.wine.id)).then(() => {
57-
this.props.dispatch(setTitle(this.props.wine.name));
5820
this.props.dispatch(fetchWineLiked(this.props.wine.id));
5921
});
6022
},
@@ -66,31 +28,7 @@ export const Wine = connect(mapStateToProps)(React.createClass({
6628
render() {
6729
const { wine, liked } = this.props;
6830
return (
69-
<ScrollView style={styles.scene}>
70-
<View style={styles.container}>
71-
<Image style={styles.winePic} source={{ uri: `http://${apiHost}:3000/api/wines/${this.props.wine.id}/image` }} />
72-
<View style={styles.flexColumn}>
73-
<View style={styles.bottomSpaced}>
74-
<Text style={styles.wineTitle}>{wine.name}</Text>
75-
</View>
76-
<Label>Type</Label>
77-
<LabelValue>{wine.type}</LabelValue>
78-
<Label>Région</Label>
79-
<LabelValue>{wine.appellation.region}</LabelValue>
80-
<Label>Appellation</Label>
81-
<LabelValue>{wine.appellation.name}</LabelValue>
82-
<Label>Cépages</Label>
83-
<LabelValue>{wine.grapes.join(', ')}</LabelValue>
84-
<TouchableWithoutFeedback onPress={this.handleToggleLike}>
85-
<View onPress={this.handleToggleLike} style={styles.likeView}>
86-
<Image onPress={this.handleToggleLike} style={styles.likePic} source={liked ? require('./liked.png') : require('./unliked.png')} />
87-
<Text onPress={this.handleToggleLike} style={styles.likeTitle}>{liked ? 'Unlike' : 'Like'}</Text>
88-
</View>
89-
</TouchableWithoutFeedback>
90-
</View>
91-
</View>
92-
<Comments wineId={this.props.wine.id} />
93-
</ScrollView>
31+
<Text>Wine</Text>
9432
);
9533
}
9634
}));

0 commit comments

Comments
 (0)
Please sign in to comment.