Skip to content
This repository has been archived by the owner on Sep 24, 2020. It is now read-only.

Merge button for PR screen #60

Open
wants to merge 4 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
Binary file added assets/threeDots.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 5 additions & 4 deletions components/Button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ import { UIText } from 'components';
type Props = {
children: Object,
onPress: () => any,
style?: ComponentStyles
style?: ComponentStyles,
textStyle: ComponentStyles
};

export default class Button extends PureComponent<Props> {
render() {
const { style, children, onPress } = this.props;
const { style, children, textStyle, onPress } = this.props;

return (
<TouchableOpacity onPress={onPress} style={[styles.button, style]}>
<UIText style={styles.text}>
<UIText style={[styles.text, textStyle]}>
{children}
</UIText>
</TouchableOpacity>
Expand All @@ -32,7 +33,7 @@ const styles = StyleSheet.create({
padding: 10,
},
text: {
color: '#fff',
color: 'black',
fontSize: 18,
fontWeight: '600',
textAlign: 'center',
Expand Down
45 changes: 45 additions & 0 deletions components/ImageButton/ImageButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

import React, { PureComponent } from 'react';
import { TouchableOpacity, StyleSheet } from 'react-native';
import Icon from 'react-native-vector-icons/FontAwesome';
import { connect } from 'react-redux';
import { addModal } from 'actions';

type Props = {
children: React$Element,
onPress: () => any,
style?: ComponentStyles,
addModal: typeof addModal
};

class ImageButton extends PureComponent<Props> {
render() {
const { onPress } = this.props;
const image = 'ellipsis-h';
return (
<TouchableOpacity
onPress={onPress}
style={styles.imageBackground}>
<Icon name={image} size={20} />
</TouchableOpacity>
);
}
}

export default connect(
null,
{ addModal }
)(ImageButton);
Copy link

@firec0der firec0der Oct 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

connecting a component to the redux store w/o props passing is the wrong way.
Bind dispatch to addModal where you're rendering this component and pass it as a prop here. But seems like you don't use it here, so remove connecting at all.


const styles = StyleSheet.create({
imageBackground: {
width:50,
height: 20,
marginTop: 10,
borderColor: '#edf1f5',
borderWidth: 1,
backgroundColor: '#edf1f5',
justifyContent: 'center',
alignItems: 'center'
}
});
2 changes: 2 additions & 0 deletions components/ImageButton/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, remove this unnecessary empty line

export { default as ImageButton } from './ImageButton';
1 change: 1 addition & 0 deletions components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ export * from './Badge';
export * from './UIText';
export * from './ModalPicker';
export * from './TextIcon';
export * from './ImageButton';
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

import React, { PureComponent } from 'react';
import { connect } from 'react-redux';
import { View, StyleSheet, ScrollView, FlatList } from 'react-native';
import { ErrorView, Spinner, Badge, UIText, ReactionGroup, Blank, Comment, CommitRow, RowSeparator } from 'components';
import { View, StyleSheet, ScrollView, FlatList, Text, TouchableOpacity } from 'react-native';
import { ErrorView, Spinner, Badge, UIText, ReactionGroup, Blank, Comment, CommitRow, RowSeparator, ImageButton, ModalPicker, Button } from 'components';
import { IndicatorViewPager, PagerTitleIndicator } from 'rn-viewpager';
import { fetchPullRequest, showRepositoryCommit } from 'actions';
import { fetchPullRequest, showRepositoryCommit, addModal, closeModal } from 'actions';
import { normalizeFont } from 'utils/helpers';

// import flow types
Expand All @@ -23,6 +23,12 @@ type Props = {
},
fetchPullRequest: typeof fetchPullRequest,
showRepositoryCommit: typeof showRepositoryCommit,
addModal: typeof addModal,
closeModal: typeof closeModal
}

type ModalState = {
modalVisible: boolean,
}

const TITLE_COMMITS_INDEX = 1;
Expand All @@ -40,7 +46,11 @@ function getStateColor(state: string): string {
}
}

class RepositoryPullRequestScreen extends PureComponent<Props> {
class RepositoryPullRequestScreen extends PureComponent<Props, ModalState> {
state: ModalState = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

modalVisible: false
};

componentWillMount() {
this.fetchPullRequest();
}
Expand Down Expand Up @@ -88,6 +98,10 @@ class RepositoryPullRequestScreen extends PureComponent<Props> {
];
}

setModalVisible(visible) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

this.setState({ modalVisible: visible });
}

renderOverView(pullRequest: Object): React.Element<any> {
return (
<ScrollView style={styles.overview}>
Expand All @@ -101,6 +115,36 @@ class RepositoryPullRequestScreen extends PureComponent<Props> {
</View>
</View>
<UIText style={styles.body}>{pullRequest.body}</UIText>
<ImageButton
style={styles.button}
onPress={() => this.props.addModal(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such kind of function passing is the anti-pattern.
Related reading

<ModalPicker
data={[{ type: 'merge' }]}
renderOption={
({ item }) => {
return (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can omit it.

renderOption={({ item }) => (
    <TouchableOpacity
         key={item.type}
         style={styles.modalContent}
         onPress={() => { // <- remove this arrow function passing
             closeModal();
         }}
    >
        <Text style={styles.modalTitle}>Merge this pull request?</Text>
        <Button
            style={styles.deletePr}
            textStyle={styles.deletePrText}
            onPress={() => this.props.closeModal()} // <- remove this arrow function passing
        >
            Merge
        </Button>
    </TouchableOpacity>
)}

But, I do prefer extract this rendering to a separate function.

<TouchableOpacity
key={item.type}
style={styles.modalContent}
onPress={() => {
closeModal();
}}
>
<Text style={styles.modalTitle}>Merge this pull request?</Text>
<Button
style={styles.deletePr}
textStyle={styles.deletePrText}
onPress={() => this.props.closeModal()}>
Merge
</Button>
</TouchableOpacity>
);
}
}
/>
)}
styleText={styles.buttonText}>
</ImageButton>
<ReactionGroup reactions={pullRequest.reactionGroups} />
<FlatList
style={styles.commentsList}
Expand Down Expand Up @@ -216,6 +260,40 @@ const styles = StyleSheet.create({
flex: 1,
paddingHorizontal: 10
},
button: {
width: 80, height: 30,
backgroundColor: '#edf1f5',
},
deletePr: {
width: 70, marginTop: 10,
backgroundColor: '#52c245',
},
deletePrText: {
color: '#fff',
fontSize: 14,
fontWeight: 'bold',
textAlign: 'center',
},
buttonText: {
color: 'black',
fontSize: 14,
fontWeight: '600',
textAlign: 'center',
backgroundColor: 'transparent'
},
modalTitle: {
color: 'black',
fontSize: 14, marginTop: 8,
fontWeight: '600',
textAlign: 'center',
},
modalContent: {
flex:1, borderRadius: 10,
backgroundColor: '#fff',
flexDirection: 'column',
alignItems: 'center',
marginBottom: 10
},
wrapper: {
flex: 1
},
Expand Down Expand Up @@ -263,5 +341,5 @@ export default connect(
state: state.repositoryPullRequest
};
},
{ fetchPullRequest, showRepositoryCommit }
{ fetchPullRequest, showRepositoryCommit, addModal, closeModal }
)(RepositoryPullRequestScreen);
154 changes: 77 additions & 77 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,80 +1,80 @@
{
"name": "ghubber",
"version": "0.9.0",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start --reset-cache",
"start:ios": "concurrently -r 'npm run start' 'npm run ios && google-chrome http://localhost:8081/debugger-ui'",
"start:android": "concurrently -r 'npm run start' 'npm run android && google-chrome http://localhost:8081/debugger-ui'",
"ios": "node node_modules/react-native/local-cli/cli.js run-ios",
"android": "node node_modules/react-native/local-cli/cli.js run-android",
"flow": "flow check",
"test": "jest",
"lint": "eslint --cache .",
"lint:staged": "staged-files '**/*.js' -- $(npm bin)/eslint",
"postversion": "react-native-version"
},
"pre-commit": {
"run": "lint:staged"
},
"dependencies": {
"babel-plugin-module-resolver": "^2.7.1",
"babel-plugin-transform-define": "^1.3.0",
"babel-plugin-transform-remove-console": "^6.8.5",
"base-64": "^0.1.0",
"commonmark": "^0.28.1",
"commonmark-react-renderer": "^4.3.3",
"github-flow-js": "^0.18.2",
"i18n-js": "^3.0.1",
"lodash": "^4.17.4",
"moment": "^2.18.1",
"query-string": "^5.0.0",
"react": "16.0.0-alpha.12",
"react-native": "^0.48.4",
"react-native-device-info": "^0.11.0",
"react-native-htmlview": "^0.12.0",
"react-native-sentry": "^0.25.0",
"react-native-side-menu": "^1.1.3",
"react-native-swiper": "^1.5.12",
"react-native-vector-icons": "^4.4.0",
"react-navigation": "^1.0.0-beta.12",
"react-redux": "^5.0.6",
"redux": "^3.7.2",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.2.0",
"rn-viewpager": "^1.2.4"
},
"devDependencies": {
"babel-eslint": "^8.0.1",
"babel-jest": "21.2.0",
"babel-preset-react-native": "4.0.0",
"concurrently": "^3.5.0",
"eslint": "^4.8.0",
"eslint-plugin-flowtype": "^2.37.0",
"eslint-plugin-react": "^7.4.0",
"eslint-plugin-react-native": "^3.1.0",
"flow-bin": "^0.56.0",
"jest": "21.2.1",
"pre-commit": "^1.2.2",
"react-native-version": "^2.3.1",
"react-test-renderer": "16.0.0-alpha.12",
"sentry-cli-binary": "^1.20.0",
"staged-files": "^0.1.2"
},
"jest": {
"preset": "react-native"
},
"contributes": {
"languages": [
{
"id": "flow",
"aliases": [
"Flow"
],
"extensions": [
".js"
]
}
"name": "ghubber",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert ident for this file
Thanks!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what to revert here?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, not needed to change this file (code indentation - spaces)

"version": "0.9.0",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start --reset-cache",
"start:ios": "concurrently -r 'npm run start' 'npm run ios && google-chrome http://localhost:8081/debugger-ui'",
"start:android": "concurrently -r 'npm run start' 'npm run android && google-chrome http://localhost:8081/debugger-ui'",
"ios": "node node_modules/react-native/local-cli/cli.js run-ios",
"android": "node node_modules/react-native/local-cli/cli.js run-android",
"flow": "flow check",
"test": "jest",
"lint": "eslint --cache .",
"lint:staged": "staged-files '**/*.js' -- $(npm bin)/eslint",
"postversion": "react-native-version"
},
"pre-commit": {
"run": "lint:staged"
},
"dependencies": {
"babel-plugin-module-resolver": "^2.7.1",
"babel-plugin-transform-define": "^1.3.0",
"babel-plugin-transform-remove-console": "^6.8.5",
"base-64": "^0.1.0",
"commonmark": "^0.28.1",
"commonmark-react-renderer": "^4.3.3",
"github-flow-js": "^0.18.2",
"i18n-js": "^3.0.1",
"lodash": "^4.17.4",
"moment": "^2.18.1",
"query-string": "^5.0.0",
"react": "16.0.0-alpha.12",
"react-native": "^0.48.4",
"react-native-device-info": "^0.11.0",
"react-native-htmlview": "^0.12.0",
"react-native-sentry": "^0.25.0",
"react-native-side-menu": "^1.1.3",
"react-native-swiper": "^1.5.12",
"react-native-vector-icons": "^4.4.0",
"react-navigation": "^1.0.0-beta.12",
"react-redux": "^5.0.6",
"redux": "^3.7.2",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.2.0",
"rn-viewpager": "^1.2.4"
},
"devDependencies": {
"babel-eslint": "^8.0.1",
"babel-jest": "21.2.0",
"babel-preset-react-native": "4.0.0",
"concurrently": "^3.5.0",
"eslint": "^4.8.0",
"eslint-plugin-flowtype": "^2.37.0",
"eslint-plugin-react": "^7.4.0",
"eslint-plugin-react-native": "^3.1.0",
"flow-bin": "^0.56.0",
"jest": "21.2.1",
"pre-commit": "^1.2.2",
"react-native-version": "^2.3.1",
"react-test-renderer": "16.0.0-alpha.12",
"sentry-cli-binary": "^1.20.0",
"staged-files": "^0.1.2"
},
"jest": {
"preset": "react-native"
},
"contributes": {
"languages": [
{
"id": "flow",
"aliases": [
"Flow"
],
"extensions": [
".js"
]
}
}
]
}
}