diff --git a/.eslintrc b/.eslintrc index 8551c203..b0f06a7b 100644 --- a/.eslintrc +++ b/.eslintrc @@ -8,6 +8,9 @@ "import" ], "rules": { + "arrow-parens": "off", + "implicit-arrow-linebreak": "off", + "react/no-unused-prop-types": "off", "import/prefer-default-export": "off", "react/require-default-props": "off", "object-curly-newline": "off", diff --git a/.flowconfig b/.flowconfig index 1043c82d..644866b7 100644 --- a/.flowconfig +++ b/.flowconfig @@ -19,6 +19,9 @@ ; Ignore metro .*/node_modules/metro/.* +; Ignore redux +.*/app/actions/* + [include] [libs] diff --git a/App.js b/App.js deleted file mode 100644 index 5d4d0924..00000000 --- a/App.js +++ /dev/null @@ -1,22 +0,0 @@ -// @flow - -import React, { Component } from 'react'; - -import { createBottomTabNavigator } from 'react-navigation'; - -// ui -import { Personal, Group, Settings, Availability } from './HomeTabs'; -import Login from './Login'; - -const Home = createBottomTabNavigator({ - Personal, - Group, - Settings, - Availability, -}); - -export default class App extends Component { - render() { - return ; - } -} diff --git a/app/redux/actions/login.js b/app/actions/login.js similarity index 100% rename from app/redux/actions/login.js rename to app/actions/login.js diff --git a/app/redux/actions/posts.js b/app/actions/posts.js similarity index 100% rename from app/redux/actions/posts.js rename to app/actions/posts.js diff --git a/app/actions/shifts.js b/app/actions/shifts.js new file mode 100644 index 00000000..8a4b2c4a --- /dev/null +++ b/app/actions/shifts.js @@ -0,0 +1,78 @@ +// @flow + +import crud from './utils/crud'; + +const getAllShifts = () => + crud({ + dispatch: { + begin: 'BEGIN_GET_SHIFTS', + end: 'END_GET_SHIFTS', + fail: 'FAILED_GET_SHIFTS', + }, + method: 'GET', + url: '/api/v1/shifts', + }); + +const updateShift = (id, data) => + crud({ + dispatch: { + begin: 'BEGIN_PUT_SHIFT', + end: 'END_PUT_SHIFT', + fail: 'FAILED_PUT_SHIFT', + }, + method: 'PUT', + url: `/api/v1/shifts/${id}`, + data, + }); + +const createShift = data => + crud({ + dispatch: { + begin: 'BEGIN_POST_SHIFT', + end: 'END_POST_SHIFT', + fail: 'FAILED_POST_SHIFT', + }, + method: 'POST', + url: '/api/v1/shifts', + data, + }); + +const deleteShift = id => + crud({ + dispatch: { + begin: 'BEGIN_DELETE_SHIFT', + end: 'END_DELETE_SHIFT', + fail: 'FAILED_DELETE_SHIFT', + }, + method: 'DELETE', + url: `/api/v1/shifts/${id}`, + }); + +const addUserToShift = (userID, shiftID) => + crud({ + dispatch: { + begin: 'BEGIN_POST_SHIFT', + end: 'END_POST_SHIFT', + fail: 'FAILED_POST_SHIFT', + }, + method: 'POST', + url: '/api/v1/user/shifts', + data: { + user_id: userID, + shift_id: shiftID, + }, + }); + +const dragDropUpdate = (oldShifts, newShift) => { + // NOTE: There is both a oldShift and oldShifts variable and the same for newShift and newShifts + const oldShift = oldShifts.find(shift => shift.id === newShift.id); + const index = oldShifts.indexOf(oldShift); + const newShifts = [...oldShifts]; + newShifts.splice(index, 1, newShift); + return { + type: 'DRAG_DROP', + payload: newShifts, + }; +}; + +export { getAllShifts, updateShift, createShift, deleteShift, addUserToShift, dragDropUpdate }; diff --git a/app/redux/actions/team.js b/app/actions/team.js similarity index 100% rename from app/redux/actions/team.js rename to app/actions/team.js diff --git a/app/redux/actions/user.js b/app/actions/user.js similarity index 100% rename from app/redux/actions/user.js rename to app/actions/user.js diff --git a/app/redux/actions/utils/crud.js b/app/actions/utils/crud.js similarity index 100% rename from app/redux/actions/utils/crud.js rename to app/actions/utils/crud.js diff --git a/HomeTabs/Availabilty/index.js b/app/components/HomeTabs/Availabilty/index.js similarity index 100% rename from HomeTabs/Availabilty/index.js rename to app/components/HomeTabs/Availabilty/index.js diff --git a/HomeTabs/Calendar/Group.js b/app/components/HomeTabs/Calendar/Group.js similarity index 100% rename from HomeTabs/Calendar/Group.js rename to app/components/HomeTabs/Calendar/Group.js diff --git a/HomeTabs/Calendar/Personal.js b/app/components/HomeTabs/Calendar/Personal.js similarity index 100% rename from HomeTabs/Calendar/Personal.js rename to app/components/HomeTabs/Calendar/Personal.js diff --git a/HomeTabs/Settings/index.js b/app/components/HomeTabs/Settings/index.js similarity index 100% rename from HomeTabs/Settings/index.js rename to app/components/HomeTabs/Settings/index.js diff --git a/HomeTabs/index.js b/app/components/HomeTabs/index.js similarity index 100% rename from HomeTabs/index.js rename to app/components/HomeTabs/index.js diff --git a/Login/LoginForm.js b/app/components/Login/LoginForm.js similarity index 75% rename from Login/LoginForm.js rename to app/components/Login/LoginForm.js index 615a3d7b..ebe3ef86 100644 --- a/Login/LoginForm.js +++ b/app/components/Login/LoginForm.js @@ -3,9 +3,11 @@ import React, { Component } from 'react'; import { View, StyleSheet } from 'react-native'; -import { EditText, Button } from '../UI'; +import { EditText, Button } from '../general'; -export default class LoginForm extends Component { +type Props = {}; // TODO: Add props + +export default class LoginForm extends Component { render() { return ( diff --git a/UI/Button.js b/app/components/general/Button.js similarity index 100% rename from UI/Button.js rename to app/components/general/Button.js diff --git a/UI/EditText.js b/app/components/general/EditText.js similarity index 88% rename from UI/EditText.js rename to app/components/general/EditText.js index 36aecf03..8c13a267 100644 --- a/UI/EditText.js +++ b/app/components/general/EditText.js @@ -3,9 +3,8 @@ import React, { Component } from 'react'; import { TextInput, StyleSheet } from 'react-native'; -type Props = { +type Props = TextInput.propTypes & { placeholder: string, - keyboardType?: boolean, secureTextEntry?: boolean, }; @@ -16,7 +15,7 @@ export default class EditText extends Component { this.passwordInput.focus()} + // onSubmitEditing={() => this.passwordInput.focus()} autoCorrect={false} keyboardType={keyboardType || 'default'} returnKeyType="next" diff --git a/UI/index.js b/app/components/general/index.js similarity index 100% rename from UI/index.js rename to app/components/general/index.js diff --git a/app/containers/App.js b/app/containers/App.js new file mode 100644 index 00000000..aabf6e0a --- /dev/null +++ b/app/containers/App.js @@ -0,0 +1,24 @@ +// @flow + +import React, { Component } from 'react'; + +// import { createBottomTabNavigator } from 'react-navigation'; + +// ui +// import { Personal, Group, Settings, Availability } from '../components/HomeTabs'; +import Login from './Login'; + +// const Home = createBottomTabNavigator({ +// Personal, +// Group, +// Settings, +// Availability, +// }); + +type Props = {}; // TODO: Add props + +export default class App extends Component { + render() { + return ; + } +} diff --git a/Login/index.js b/app/containers/Login.js similarity index 73% rename from Login/index.js rename to app/containers/Login.js index 38e923d2..33cc0e8e 100644 --- a/Login/index.js +++ b/app/containers/Login.js @@ -3,20 +3,24 @@ import React, { Component } from 'react'; import { KeyboardAvoidingView, View, StyleSheet, Image } from 'react-native'; -// ui -import LoginForm from './LoginForm'; +// components +import LoginForm from '../components/Login/LoginForm'; + +// images +import * as logo from '../images/logo.png'; type Props = { // TODO(anesu): Add more accurate types - login: any, - user: any, - loginUser: any, - clearError: any, + login?: any, + user?: any, + loginUser?: any, + clearError?: any, }; export default class Login extends Component { render() { - const { login, user, loginUser, clearError } = this.props; + // TODO: Use variables below + // const { login, user, loginUser, clearError } = this.props; return ( @@ -25,11 +29,11 @@ export default class Login extends Component { resizeMode="contain" style={styles.logo} // eslint-disable-next-line global-require - source={require('../assets/images/logo.png')} + source={logo} /> - + diff --git a/assets/images/logo.png b/app/images/logo.png similarity index 100% rename from assets/images/logo.png rename to app/images/logo.png diff --git a/Home.js b/app/index.js similarity index 66% rename from Home.js rename to app/index.js index 000f9b2f..e3f1e4fe 100644 --- a/Home.js +++ b/app/index.js @@ -7,14 +7,16 @@ import { Provider } from 'react-redux'; import { createStore, combineReducers } from 'redux'; // reducers -import * as allReducers from './app/redux/reducers'; +import * as allReducers from './reducers'; // ui -import App from './App'; +import App from './containers/App'; const store = createStore(combineReducers(allReducers)); -export default class Home extends Component { +type Props = {}; // TODO: Add props + +export default class GTHC extends Component { render() { return ( diff --git a/app/redux/reducers/index.js b/app/reducers/index.js similarity index 95% rename from app/redux/reducers/index.js rename to app/reducers/index.js index 4b34ea11..3108692d 100644 --- a/app/redux/reducers/index.js +++ b/app/reducers/index.js @@ -1,5 +1,3 @@ -// @flow - export { default as user } from './user'; export { default as login } from './login'; export { default as shifts } from './shifts'; diff --git a/app/redux/reducers/login.js b/app/reducers/login.js similarity index 99% rename from app/redux/reducers/login.js rename to app/reducers/login.js index 863efd04..43e98edd 100644 --- a/app/redux/reducers/login.js +++ b/app/reducers/login.js @@ -1,5 +1,3 @@ -// @flow - const initialState = { type: 'login', // login or signup signUpData: { diff --git a/app/redux/reducers/posts.js b/app/reducers/posts.js similarity index 98% rename from app/redux/reducers/posts.js rename to app/reducers/posts.js index 9a641b06..2f7b171e 100644 --- a/app/redux/reducers/posts.js +++ b/app/reducers/posts.js @@ -1,5 +1,3 @@ -// @flow - const initialState = { data: [], isLoading: false, diff --git a/app/redux/reducers/shifts.js b/app/reducers/shifts.js similarity index 99% rename from app/redux/reducers/shifts.js rename to app/reducers/shifts.js index 230db6f9..3b78bf06 100644 --- a/app/redux/reducers/shifts.js +++ b/app/reducers/shifts.js @@ -1,5 +1,3 @@ -// @flow - const initialState = { team_shifts: [], user_shifts: [], diff --git a/app/redux/reducers/team.js b/app/reducers/team.js similarity index 99% rename from app/redux/reducers/team.js rename to app/reducers/team.js index c115831d..0d0a5031 100644 --- a/app/redux/reducers/team.js +++ b/app/reducers/team.js @@ -1,5 +1,3 @@ -// @flow - const initialState = { data: {}, isLoading: false, diff --git a/app/redux/reducers/user.js b/app/reducers/user.js similarity index 99% rename from app/redux/reducers/user.js rename to app/reducers/user.js index 66511a7e..375a621c 100644 --- a/app/redux/reducers/user.js +++ b/app/reducers/user.js @@ -1,5 +1,3 @@ -// @flow - const initialState = { data: {}, isLoggedIn: false, diff --git a/app/redux/actions/shifts.js b/app/redux/actions/shifts.js deleted file mode 100644 index 258e0542..00000000 --- a/app/redux/actions/shifts.js +++ /dev/null @@ -1,73 +0,0 @@ -// @flow - -import crud from './utils/crud'; - -const getAllShifts = () => crud({ - dispatch: { - begin: 'BEGIN_GET_SHIFTS', - end: 'END_GET_SHIFTS', - fail: 'FAILED_GET_SHIFTS', - }, - method: 'GET', - url: '/api/v1/shifts', -}); - -const updateShift = (id, data) => crud({ - dispatch: { - begin: 'BEGIN_PUT_SHIFT', - end: 'END_PUT_SHIFT', - fail: 'FAILED_PUT_SHIFT', - }, - method: 'PUT', - url: `/api/v1/shifts/${id}`, - data, -}); - -const createShift = data => crud({ - dispatch: { - begin: 'BEGIN_POST_SHIFT', - end: 'END_POST_SHIFT', - fail: 'FAILED_POST_SHIFT', - }, - method: 'POST', - url: '/api/v1/shifts', - data, -}); - -const deleteShift = id => crud({ - dispatch: { - begin: 'BEGIN_DELETE_SHIFT', - end: 'END_DELETE_SHIFT', - fail: 'FAILED_DELETE_SHIFT', - }, - method: 'DELETE', - url: `/api/v1/shifts/${id}`, -}); - -const addUserToShift = (userID, shiftID) => crud({ - dispatch: { - begin: 'BEGIN_POST_SHIFT', - end: 'END_POST_SHIFT', - fail: 'FAILED_POST_SHIFT', - }, - method: 'POST', - url: '/api/v1/user/shifts', - data: { - user_id: userID, - shift_id: shiftID, - }, -}); - -const dragDropUpdate = (oldShifts, newShift) => { - // NOTE: There is both a oldShift and oldShifts variable and the same for newShift and newShifts - const oldShift = oldShifts.find(shift => shift.id === newShift.id); - const index = oldShifts.indexOf(oldShift); - const newShifts = [...oldShifts]; - newShifts.splice(index, 1, newShift); - return { - type: 'DRAG_DROP', - payload: newShifts, - }; -}; - -export { getAllShifts, updateShift, createShift, deleteShift, addUserToShift, dragDropUpdate }; diff --git a/index.js b/index.js index e06bb94a..ac58196d 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,6 @@ /** @format */ - import { AppRegistry } from 'react-native'; -import Home from './Home'; -import Login from './Login'; -AppRegistry.registerComponent('GTHC', () => Home); -AppRegistry.registerComponent('Login', () => Login); +import GTHC from './app'; + +AppRegistry.registerComponent('GTHC', () => GTHC);