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

Commit

Permalink
[Refactoring] Up code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
ovr committed Jul 14, 2017
1 parent faa6aed commit b6f6c0f
Show file tree
Hide file tree
Showing 13 changed files with 58 additions and 42 deletions.
1 change: 1 addition & 0 deletions .eslintignore
@@ -0,0 +1 @@
__tests__
9 changes: 7 additions & 2 deletions .eslintrc
Expand Up @@ -5,7 +5,8 @@
},
"plugins": [
"react",
"react-native"
"react-native",
"flowtype"
],
"extends": [
"eslint:recommended",
Expand All @@ -15,6 +16,10 @@
// overrides
},
"globals": {
"__DEV__": true
"__DEV__": true,
// @todo flow
"State": true,
"Promise": true,
"ThunkAction": true
}
}
2 changes: 1 addition & 1 deletion App.js
Expand Up @@ -2,7 +2,7 @@
// @flow

import React, { Component } from 'react';
import { View, Text, AppRegistry } from 'react-native';
import { AppRegistry } from 'react-native';
import { Provider } from 'react-redux';
import { Sentry } from 'react-native-sentry';
import { before } from 'github-flow-js/Client';
Expand Down
7 changes: 3 additions & 4 deletions Navigator.js
@@ -1,14 +1,13 @@
// @author Dmitry Patsura <talk@dmtry.me> https://github.com/ovr

import React from 'react';
import { View, Text, BackHandler } from 'react-native';
import { BackHandler } from 'react-native';
import { connect } from 'react-redux';
import { SideMenuButton } from 'containers';
import { addNavigationHelpers, StackNavigator, DrawerNavigator, NavigationActions } from 'react-navigation';
import I18n from 'utils/i18n';

import {
Home,
FeedScreen,
FeedSettingsScreen,
LoginScreen,
Expand All @@ -29,7 +28,7 @@ export const HomeScreeDrawer = DrawerNavigator({
}, {
drawerWidth: 300,
drawerPosition: 'left',
contentComponent: props => <SideMenu />,
contentComponent: () => <SideMenu />,
initialRouteName: 'Home'
})

Expand Down Expand Up @@ -101,7 +100,7 @@ class AppWithNavigationState extends React.Component {
if (navigation.index === 0) {
return false;
}

dispatch(NavigationActions.back());

return true;
Expand Down
4 changes: 2 additions & 2 deletions actions/flow-types.js
Expand Up @@ -42,11 +42,11 @@ export type State = {|
accountPullRequests: AccountPullRequestsState,
app: AppState,
login: LoginState,
login: NavigationState,
navigation: NavigationState,
profile: ProfileState,
profileOrganizations: ProfileRepositoriesState,
profileRepositories: ProfileOrganizationsState,
repository: RepositoryState,
repository: RepositoryState
|};

export type Dispatch = (action: Action | ThunkAction | PromiseAction) => any;
Expand Down
2 changes: 1 addition & 1 deletion actions/navigation.js
Expand Up @@ -2,7 +2,7 @@
// @flow

import { NavigationActions } from 'react-navigation';
import { NAVIGATION_SET_TITLE, NAVIGATION_HOME, NAVIGATION_LOGIN } from 'constants';
import { NAVIGATION_SET_TITLE } from 'constants';
import { setupRepository } from './repository';

// import flow types
Expand Down
4 changes: 3 additions & 1 deletion containers/ProfileRepositories/ProfileRepositories.js
Expand Up @@ -2,7 +2,7 @@
// @flow

import React, { PureComponent } from 'react';
import { View, Text, StyleSheet, FlatList, RefreshControl } from 'react-native';
import { View, Text, StyleSheet, FlatList } from 'react-native';
import { connect } from 'react-redux';
import { RepositoryRow, RowSeparator } from 'components';
import { fetchRepositories, fetchMoreRepositories, showRepository } from 'actions';
Expand All @@ -14,6 +14,8 @@ import type { RepositoryEntity } from 'github-flow-js';
import type { ProfileRepositoriesState } from 'reducers/profile-repositories';

type Props = {
// @todo
navigation: Object,
state: ProfileRepositoriesState,
fetchRepositories: typeof fetchRepositories,
fetchMoreRepositories: typeof fetchMoreRepositories,
Expand Down
4 changes: 2 additions & 2 deletions containers/SideMenu/SideMenu.js
Expand Up @@ -2,7 +2,7 @@
// @flow

import React, { PureComponent } from 'react';
import { Image, View, StyleSheet, Text, ScrollView, Platform, TouchableOpacity } from 'react-native';
import { View, StyleSheet, Text, ScrollView, Platform, TouchableOpacity } from 'react-native';
import { Avatar, OrganizationAvatar, Button } from 'components';
import { connect } from 'react-redux';
import { hideSideMenu, logout, showAccount, showAbout } from 'actions';
Expand All @@ -21,7 +21,7 @@ type Props = {

class SideMenu extends PureComponent<void, Props, void> {
render() {
const { hideSideMenu, app, logout, showAccount, showAbout } = this.props;
const { app, logout, showAccount, showAbout } = this.props;

if (app.user === null) {
return null;
Expand Down
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Expand Up @@ -37,6 +37,7 @@
"babel-jest": "20.0.3",
"babel-preset-react-native": "2.1.0",
"eslint": "^4.2.0",
"eslint-plugin-flowtype": "^2.35.0",
"eslint-plugin-react": "^7.1.0",
"eslint-plugin-react-native": "^2.3.2",
"flow-bin": "^0.49.1",
Expand Down
52 changes: 27 additions & 25 deletions reducers/navigation.js
Expand Up @@ -2,7 +2,7 @@
// @flow

import { AppNavigator } from '../Navigator';
import { NAVIGATION_SET_TITLE, NAVIGATION_HOME, NAVIGATION_LOGIN } from 'constants';
// import { NAVIGATION_SET_TITLE, NAVIGATION_HOME, NAVIGATION_LOGIN } from 'constants';

export type NavigationState = {
params?: any
Expand All @@ -13,7 +13,29 @@ const initialState = AppNavigator.router.getStateForAction(
);

export default (state: NavigationState = initialState, action: Object): NavigationState => {
switch (action.type) {
let nextState = AppNavigator.router.getStateForAction(action, state);

// @todo Fix or ask related question inside react-navigation project, because I cannot explain
// how to get route params inside state, not route
if (nextState && nextState.index) {
const route = nextState.routes[nextState.index];

if (route.params) {
nextState = {
...nextState,
params: route.params
}
} else {
nextState = {
...nextState,
params: null
}
}
}

return nextState || state;

// switch (action.type) {
// case NAVIGATION_LOGIN:
// // Reset whole Stack by new State
// return AppNavigator.router.getStateForAction(
Expand All @@ -24,27 +46,7 @@ export default (state: NavigationState = initialState, action: Object): Navigati
// return AppNavigator.router.getStateForAction(
// AppNavigator.router.getActionForPathAndParams('Home')
// );
default:
let nextState = AppNavigator.router.getStateForAction(action, state);

// @todo Fix or ask related question inside react-navigation project, because I cannot explain
// how to get route params inside state, not route
if (nextState && nextState.index) {
const route = nextState.routes[nextState.index];

if (route.params) {
nextState = {
...nextState,
params: route.params
}
} else {
nextState = {
...nextState,
params: null
}
}
}

return nextState || state;
}
// default:
//
// }
}
2 changes: 1 addition & 1 deletion utils/filter-concat.js
@@ -1,6 +1,6 @@
// @flow

import { last } from 'lodash';
// import { last } from 'lodash';

/**
* Why is it needed?
Expand Down
3 changes: 0 additions & 3 deletions utils/team.js
@@ -1,9 +1,6 @@
// @author Dmitry Patsura <talk@dmtry.me> https://github.com/ovr
// @flow

// import flow types
import type { UserEntity } from 'github-flow-js';

export const team = [
{
login: "ovr",
Expand Down

0 comments on commit b6f6c0f

Please sign in to comment.