Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added es6 syntax to api.js #30

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 38 additions & 39 deletions app/CommentItem.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,55 @@
"use strict";

var React = require("react-native");
var {
import React, {
Component,
Image,
StyleSheet,
PixelRatio,
Text,
TouchableHighlight,
View,
Component,
Dimensions
} = React;
} from 'react-native';

var Icon = require("react-native-vector-icons/FontAwesome"),
getImage = require("./helpers/getImage"),
HTML = require("react-native-htmlview"),
screen = Dimensions.get('window');
import * as getImage from './helpers/getImage';
import { Icon } from 'react-native-vector-icons/FontAwesome';
import HTML from 'react-native-htmlview';
const screen = Dimensions.get('window');

var CommentItem = React.createClass({
getDefaultProps: function() {
return {
comments: []
}
},
export default class CommentItem extends Component {
constructor(props) {
super(props);
}//constructor

render: function() {
return <View>
<TouchableHighlight onPress={this.props.onSelect.bind(this, this.props.comment)}
underlayColor={"#f3f3f3"}>
<View>
<View style={styles.commentContent}>
<Image source={getImage.authorAvatar(this.props.comment.user)}
style={styles.avatar}/>
<View style={styles.commentBody}>
<Text style={styles.userName}>
{this.props.comment.user.name}
</Text>
<Text style={styles.commentText}>
<HTML value={this.props.comment.body} />
</Text>
render() {
return (
<View>
<TouchableHighlight
onPress={this.props.onSelect.bind(this, this.props.comment)}
underlayColor={"#f3f3f3"}>
<View>
<View style={styles.commentContent}>
<Image source={getImage.authorAvatar(this.props.comment.user)}
style={styles.avatar}/>
<View style={styles.commentBody}>
<Text style={styles.userName}>
{this.props.comment.user.name}
</Text>
<Text style={styles.commentText}>
<HTML value={this.props.comment.body} />
</Text>
</View>
</View>
<View style={styles.cellBorder} />
</View>
<View style={styles.cellBorder} />
</View>
</TouchableHighlight>
</View>;
}
});
</TouchableHighlight>
</View>
)//return
}//render
}//class
CommentItem.propTypes = {comments: React.PropTypes.array.isRequired};
CommentItem.defaultProps = {comments: []};

var styles = StyleSheet.create({
const styles = StyleSheet.create({
commentContent: {
padding: 10,
flex: 1,
Expand Down Expand Up @@ -80,5 +81,3 @@ var styles = StyleSheet.create({
marginRight: 10
}
});

module.exports = CommentItem;
27 changes: 14 additions & 13 deletions app/ShotCell.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
"use strict";

var React = require("react-native");
var {
import React, {
Component,
Image,
PixelRatio,
StyleSheet,
Text,
TouchableHighlight,
View,
Dimensions
} = React;
} from 'react-native';

var getImage = require("./helpers/getImage"),
screen = Dimensions.get('window');
import * as getImage from "./helpers/getImage";
const screen = Dimensions.get('window');

var ShotCell = React.createClass({
render: function() {
export default class ShotCell extends Component {
constructor(props) {
super(props);
}
render() {
return (
<View>
<TouchableHighlight onPress={this.props.onSelect}>
Expand All @@ -29,11 +32,11 @@ var ShotCell = React.createClass({
</TouchableHighlight>
<View style={styles.cellBorder} />
</View>
);
}
});
)//return
}//render
};//class

var styles = StyleSheet.create({
const styles = StyleSheet.create({
textContainer: {
flex: 1,
},
Expand All @@ -54,5 +57,3 @@ var styles = StyleSheet.create({
marginLeft: 4,
},
});

module.exports = ShotCell;
25 changes: 12 additions & 13 deletions app/helpers/api.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

var API_URL = "https://api.dribbble.com/v1/",
const API_URL = "https://api.dribbble.com/v1/",
ACCESS_TOKEN = "7a22f910dcdff63bd3ebbe48d022f05e8268c67249709b5489d923f97bcf96ec";

function fetchData(URL) {
Expand All @@ -11,16 +11,15 @@ function fetchData(URL) {
}).then((response) => response.json())
}

module.exports = {
getShotsByType: function(type: string, pageNumber: ?number): ?Object {
var URL = API_URL + "shots/?list=" + type;
if (pageNumber) {
URL += "&per_page=10&page=" + pageNumber;
}

return fetchData(URL);
},
getResources: function(url: ?string): ?Object {
return fetchData(url);
export function getShotsByType(type: string, pageNumber: ?number): ?Object {
var URL = API_URL + "shots/?list=" + type;
if (pageNumber) {
URL += "&per_page=10&page=" + pageNumber;
}
};

return fetchData(URL);
}

export function getResources(url: ?string): ?Object {
return fetchData(url);
}
25 changes: 12 additions & 13 deletions app/helpers/getImage.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
'use strict';

module.exports = {
shotImage: function(shot: Object): {uri: ?string} {
var uri = shot.images.normal ? shot.images.normal : shot.images.teaser;
export function shotImage(shot: Object): {uri: ?string} {
var uri = shot.images.normal ? shot.images.normal : shot.images.teaser;
return {uri};
}

export function authorAvatar(player: Object): {uri: ?string} {
var uri;
if (player) {
uri = player.avatar_url;
return {uri};
},
authorAvatar: function(player: Object): {uri: ?string} {
var uri;
if (player) {
uri = player.avatar_url;
return {uri};
} else {
uri = require('../../img/AuthorAvatar.png');
return uri;
}
} else {
uri = require('../../img/AuthorAvatar.png');
return uri;
}
}
42 changes: 21 additions & 21 deletions index.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,30 @@
* Github url: https://github.com/catalinmiron/react-native-dribbble-app
*/
"use strict";

var React = require("react-native");
var {
import React, {
Component,
AppRegistry,
NavigatorIOS,
StyleSheet,
TabBarIOS,
View,
Text
} = React;
} from 'react-native';

var ShotList = require("./app/ShotList"),
Icon = require("react-native-vector-icons/FontAwesome");
import ShotList from "./app/ShotList";
const Icon = require("react-native-vector-icons/FontAwesome");

var DribbbleApp = React.createClass({
getInitialState: function() {
return {
selectedTab: "default"
};
},
export default class DribbbleApp extends Component {
constructor(props) {
super(props);

_renderContent: function(category: string, title: ?string) {
this.state = {
selectedTab: "default"
}
}//constructor

//_renderContent(category: string, title: ?string) {
_renderContent(category, title) {
return (
<NavigatorIOS style={styles.wrapper}
initialRoute={{
Expand All @@ -34,9 +36,9 @@ var DribbbleApp = React.createClass({
}}
/>
);
},
};

render: function() {
render() {
return (
<TabBarIOS tintColor={"#ea4c89"}>
<Icon.TabBarItem
Expand Down Expand Up @@ -88,11 +90,11 @@ var DribbbleApp = React.createClass({
{this._renderContent("rebounds", "Rebounds")}
</Icon.TabBarItem>
</TabBarIOS>
);
}
});
) //return
} //render
}//class

var styles = StyleSheet.create({
const styles = StyleSheet.create({
tabContent: {
flex: 1,
alignItems: "center",
Expand All @@ -107,5 +109,3 @@ var styles = StyleSheet.create({
});

AppRegistry.registerComponent("DribbbleApp", () => DribbbleApp);

module.exports = DribbbleApp;