Skip to content

Commit

Permalink
[CHORE]: Merged from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
rdrnt committed Feb 25, 2018
2 parents db1b069 + 6eef68d commit ff11fef
Show file tree
Hide file tree
Showing 45 changed files with 882 additions and 739 deletions.
47 changes: 47 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"env": {
"node": true,
"es6": true
},

"globals": {
"fetch": false
},

"parserOptions": {
"ecmaVersion": 8,
"ecmaFeatures": {
"arrowFunctions": true,
"blockBindings": true,
"classes": true,
"defaultParameters": true,
"destructuring": true,
"forOf": true,
"generators": true,
"modules": true,
"objectLiteralComputedProperties": true,
"objectLiteralDuplicateProperties": true,
"objectLiteralShorthandMethods": true,
"objectLiteralShorthandProperties": true,
"regexUFlag": true,
"regexYFlag": true,
"restParams": true,
"spread": true,
"superInFunctions": true,
"templateStrings": true,
"unicodeCodePointEscapes": true,
"globalReturn": true
},
"sourceType": "module"
},

"extends": "airbnb",

"rules": {
"arrow-parens": 0,
"no-param-reassign": 0,
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }]
}
}

// https://eslint.org/docs/rules/
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__tests__/data
10 changes: 10 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
tabWidth: 2
useTabs: false
semi: true
singleQuote: true
trailingComma: all
bracketSpacing: true
jsxBracketSameLine: false
arrowParens: avoid
parser: flow
printWidth: 80
33 changes: 33 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Contributing

To contribute to hackd, clone/fork the repository, make changes and open a PR with your changes. Any type of change is welcomed, including bug fixes, new features, documentation or tests.

Opening issues for bugs, features or anything else is also welcomed.

If you are implementing a new feature, or modifying styles, please replace/add screenshot(s) to the [README](README.md).

### Prettier

[Prettier](https://github.com/prettier/prettier) is used to keep a consistent code style across the project. Before committing, run `npm run prettier` which will transform your code to fit the projects style.

### ESLint

[ESLint](https://github.com/eslint/eslint) is used for code linting inside your IDE/text editor. If you don't have ESLint installed in your editor, you should install it - [https://eslint.org/docs/user-guide/integrations](https://eslint.org/docs/user-guide/integrations).

To find any errors or warnings, either view them in your editor once you've installed the right package, or run `npm run eslint`. Not all errors/warnings can be fixed, and some will be picked up by prettier, so don't worry if you can't fix them.

### Lock Files

All lock files (`package-lock.json`, `yarn.lock`) should be committed.

### Dependencies

Try to keep dependencies to a minimum where possible. If you are pulling a whole library for just one function, try to implement that function as a helper method.

### Testing

[Jest](https://github.com/facebook/jest) is used for testing. Once you've made changes, writing a test case helps to catch any bugs. Feel free to open a PR that just includes more tests.

### Setup

Follow the instructions in the [README](README.md) to get setup. Once hackd is running in the iOS simulator, you can enable debugging and view redux-logger logs in the console.
31 changes: 16 additions & 15 deletions __tests__/tests/actions/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@ import { post } from '../../data/api/post';
const dispatch = jest.fn();

describe('Auth Actions', () => {

it('should login a user', () => {
const getState = () => ({});

actions.login(appUser)(dispatch, getState);
expect(dispatch).toHaveBeenCalledWith({
type: 'UPDATE_USER',
type: 'UPDATE_USER',
user: appUser,
});
});

it('should add a post to the upvoted section of a new users account', () => {
const getState = () => ({
const getState = () => ({
user: appUser,
accounts: {},
});
Expand All @@ -32,13 +31,13 @@ describe('Auth Actions', () => {

actions.addIdToUserAccount(post.id, 'upvoted')(dispatch, getState);
expect(dispatch).toHaveBeenCalledWith({
type: 'SET_ACCOUNTS_DETAILS',
type: 'SET_ACCOUNTS_DETAILS',
accounts: expectedAccounts,
});
});

it('should add a post to the saved section of a new users account', () => {
const getState = () => ({
const getState = () => ({
user: appUser,
accounts: {},
});
Expand All @@ -51,13 +50,13 @@ describe('Auth Actions', () => {

actions.addIdToUserAccount(post.id, 'saved')(dispatch, getState);
expect(dispatch).toHaveBeenCalledWith({
type: 'SET_ACCOUNTS_DETAILS',
type: 'SET_ACCOUNTS_DETAILS',
accounts: expectedAccounts,
});
});

it('should remove a post from the saved section of an existing users account', () => {
const getState = () => ({
const getState = () => ({
user: appUser,
accounts: {
[appUser.username]: {
Expand All @@ -74,13 +73,13 @@ describe('Auth Actions', () => {

actions.removeIdFromUserAccount(post.id, 'saved')(dispatch, getState);
expect(dispatch).toHaveBeenCalledWith({
type: 'SET_ACCOUNTS_DETAILS',
type: 'SET_ACCOUNTS_DETAILS',
accounts: expectedAccounts,
});
});

it('should add a post to the upvotedComments section of a new users account', () => {
const getState = () => ({
const getState = () => ({
user: appUser,
accounts: {},
});
Expand All @@ -93,13 +92,13 @@ describe('Auth Actions', () => {

actions.addIdToUserAccount(post.id, 'upvotedComments')(dispatch, getState);
expect(dispatch).toHaveBeenCalledWith({
type: 'SET_ACCOUNTS_DETAILS',
type: 'SET_ACCOUNTS_DETAILS',
accounts: expectedAccounts,
});
});

it('should remove a post from the upvotedComments section of an existing users account', () => {
const getState = () => ({
const getState = () => ({
user: appUser,
accounts: {
[appUser.username]: {
Expand All @@ -114,11 +113,13 @@ describe('Auth Actions', () => {
},
};

actions.removeIdFromUserAccount(post.id, 'upvotedComments')(dispatch, getState);
actions.removeIdFromUserAccount(post.id, 'upvotedComments')(
dispatch,
getState,
);
expect(dispatch).toHaveBeenCalledWith({
type: 'SET_ACCOUNTS_DETAILS',
type: 'SET_ACCOUNTS_DETAILS',
accounts: expectedAccounts,
});
});

});
});
8 changes: 3 additions & 5 deletions __tests__/tests/actions/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import * as actions from '../../../app/actions/items';
import { posts } from '../../data/api/post';

describe('Items Actions', () => {

it('should set first page posts', () => {
const getState = () => ({});

Expand All @@ -15,7 +14,7 @@ describe('Items Actions', () => {
actions.setPosts(1, posts)(dispatch, getState);

expect(dispatch).toHaveBeenCalledWith({
type: 'SET_POSTS',
type: 'SET_POSTS',
posts,
});
});
Expand All @@ -24,9 +23,8 @@ describe('Items Actions', () => {
const storyType = 'top';

expect(actions.setStoryType(storyType)).toEqual({
type: 'SET_STORY_TYPE',
type: 'SET_STORY_TYPE',
storyType,
});
});

});
});
7 changes: 3 additions & 4 deletions __tests__/tests/utilities/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {
import {
capitalize,
truncate,
addToUserAccount,
Expand Down Expand Up @@ -29,7 +29,7 @@ describe('App Utils', () => {
expect(addToUserAccount(account, appUser, id, type)).toEqual({
[appUser.username]: {
upvoted: [id],
}
},
});
});

Expand All @@ -45,8 +45,7 @@ describe('App Utils', () => {
expect(removeFromUserAccount(account, appUser, id, type)).toEqual({
[appUser.username]: {
upvotedComments: [id2],
}
},
});
});

});
14 changes: 5 additions & 9 deletions app/actions/auth.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import * as types from './types';
import {
addToUserAccount,
removeFromUserAccount
} from '../helpers/utils';
import { logout, upvote, } from '../helpers/api';
import { addToUserAccount, removeFromUserAccount } from '../helpers/utils';
import { logout, upvote } from '../helpers/api';

const setUser = user => {
return {
Expand Down Expand Up @@ -37,12 +34,11 @@ export const removeIdFromUserAccount = (id, type) => {
};
};

export const upvotePost = (id) => {
export const upvotePost = id => {
return (dispatch, getState) => {

// Add upvote initially for immediate feedback
dispatch(addIdToUserAccount(id, 'upvoted'));

upvote(id).then(upvoted => {
if (!upvoted) {
dispatch(removeIdFromUserAccount(id, 'upvoted'));
Expand All @@ -51,7 +47,7 @@ export const upvotePost = (id) => {
};
};

export const savePost = (id) => {
export const savePost = id => {
return (dispatch, getState) => {
dispatch(addIdToUserAccount(id, 'saved'));
};
Expand Down
3 changes: 2 additions & 1 deletion app/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import * as ItemActions from './items';
import * as AuthActions from './auth';
import * as SettingActions from './settings';

export const ActionCreators = Object.assign({},
export const ActionCreators = Object.assign(
{},
ItemActions,
AuthActions,
SettingActions,
Expand Down
2 changes: 1 addition & 1 deletion app/actions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ export const ADD_UPVOTED_POST = 'ADD_UPVOTED_POST';
export const CHANGE_SAVED_POSTS = 'CHANGE_SAVED_POSTS';

// Settings
export const SET_SETTINGS = 'SET_SETTINGS';
export const SET_SETTINGS = 'SET_SETTINGS';
4 changes: 1 addition & 3 deletions app/components/CustomText.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React from 'react';
import {
Text,
} from 'react-native';
import { Text } from 'react-native';

import commonStyles from '../styles/common';

Expand Down
39 changes: 26 additions & 13 deletions app/components/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,47 +36,60 @@ export default class Form extends React.PureComponent {

render() {
return (
<ScrollView
keyboardShouldPersistTaps='always'
<ScrollView
keyboardShouldPersistTaps="always"
scrollEnabled={this.props.scroll ? this.props.scroll : false}
style={commonStyles.backgroundWhite}
>
<View>
<View style={styles.inputContainer}>
{ Object.keys(this.props.inputs).map(key => {
{Object.keys(this.props.inputs).map(key => {
const input = this.props.inputs[key];

return (
<TextInput style={styles.input}
<TextInput
style={styles.input}
key={input.placeholder}
multiline={input.multiline ? input.multiline : false}
secureTextEntry={input.secureTextEntry ? input.secureTextEntry : false}
secureTextEntry={
input.secureTextEntry ? input.secureTextEntry : false
}
placeholder={input.placeholder}
autoCapitalize='none'
autoCapitalize="none"
placeholderTextColor={config.colors.placeholder}
onChangeText={(text) => this.textChanged(input, text)}
onChangeText={text => this.textChanged(input, text)}
/>
);
})}
</View>

<TouchableOpacity
style={[styles.submitButton, { backgroundColor: this.props.color}]}
style={[styles.submitButton, { backgroundColor: this.props.color }]}
activeOpacity={0.8}
onPress={this.submit}>
<CustomText style={styles.submitButtonText}>{this.props.submitText ? this.props.submitText : 'Submit'}</CustomText>
onPress={this.submit}
>
<CustomText style={styles.submitButtonText}>
{this.props.submitText ? this.props.submitText : 'Submit'}
</CustomText>
</TouchableOpacity>

<TouchableOpacity
style={styles.backButton}
activeOpacity={0.8}
onPress={this.back}>
<CustomText style={[styles.backButtonText, { color: this.props.color}]}>Back to {this.props.backText}</CustomText>
onPress={this.back}
>
<CustomText
style={[styles.backButtonText, { color: this.props.color }]}
>
Back to {this.props.backText}
</CustomText>
</TouchableOpacity>
</View>

<View>
<CustomText style={[styles.error, commonStyles.textCenter]}>{this.props.error}</CustomText>
<CustomText style={[styles.error, commonStyles.textCenter]}>
{this.props.error}
</CustomText>
</View>

<View>
Expand Down
Loading

0 comments on commit ff11fef

Please sign in to comment.