Skip to content

Commit d5d0b6f

Browse files
authored
Merge pull request #1 from AndrewGable/tgolen-report-port
Some initial fixes and code style updates
2 parents c859882 + cbeeb55 commit d5d0b6f

21 files changed

+625
-583
lines changed

.editorconfig

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
3+
# Howto with your editor:
4+
# Sublime: https://github.com/sindresorhus/editorconfig-sublime
5+
6+
# top-most EditorConfig file
7+
root = true
8+
9+
# Unix-style newlines with a newline ending every file
10+
[**]
11+
end_of_line = lf
12+
insert_final_newline = true
13+
indent_style = space
14+
indent_size = 4
15+
16+
# Standard at: https://github.com/felixge/node-style-guide
17+
[**.js, **.json]
18+
trim_trailing_whitespace = true
19+
quote_type = single
20+
curly_bracket_next_line = false
21+
spaces_around_operators = true
22+
space_after_control_statements = true
23+
space_after_anonymous_functions = false
24+
spaces_in_brackets = false
25+
26+
# No Standard. Please document a standard if different from .js
27+
[**.yml, **.html, **.css]
28+
trim_trailing_whitespace = true
29+
30+
# No standard. Please document a standard if different from .js
31+
[**.md]
32+
33+
# Standard at:
34+
[Makefile]
35+
36+
[package*]
37+
indent_style = space
38+
indent_size = 2

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* @format
33
*/
44

5-
import {AppRegistry} from 'react-native';
5+
import { AppRegistry } from 'react-native';
66
import App from './js/App';
7-
import {name as appName} from './app.json';
7+
import { name as appName } from './app.json';
88

99
AppRegistry.registerComponent(appName, () => App);

js/Expensify.js

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,64 @@
1-
import {init as StoreInit} from './store/Store.js';
1+
import { init as StoreInit } from './store/Store.js';
22
import SignInPage from './page/SignInPage.js';
33
import HomePage from './page/HomePage/HomePage.js';
44
import * as Store from './store/Store.js';
55
import * as ActiveClientManager from './lib/ActiveClientManager.js';
6-
import {verifyAuthToken} from './store/actions/SessionActions.js';
6+
import { verifyAuthToken } from './store/actions/SessionActions.js';
77
import STOREKEYS from './store/STOREKEYS.js';
8-
import React, {Component} from 'react';
9-
import {Route, Router, Redirect, Switch} from './lib/Router';
8+
import React, { Component } from 'react';
9+
import { Route, Router, Redirect, Switch } from './lib/Router';
1010

1111
// Initialize the store when the app loads for the first time
1212
StoreInit();
1313

1414
export default class Expensify extends Component {
15-
constructor(props) {
16-
super(props);
15+
constructor(props) {
16+
super(props);
1717

18-
this.sessionChanged = this.sessionChanged.bind(this);
18+
this.sessionChanged = this.sessionChanged.bind(this);
1919

20-
this.state = {
21-
redirectTo: null,
22-
};
23-
}
20+
this.state = {
21+
redirectTo: null,
22+
};
23+
}
2424

25-
async componentDidMount() {
26-
// Listen for when the app wants to redirect to a specific URL
27-
Store.subscribe(STOREKEYS.APP_REDIRECT_TO, (redirectTo) => {
28-
this.setState({redirectTo});
29-
});
25+
async componentDidMount() {
26+
// Listen for when the app wants to redirect to a specific URL
27+
Store.subscribe(STOREKEYS.APP_REDIRECT_TO, (redirectTo) => {
28+
this.setState({ redirectTo });
29+
});
3030

31-
// Verify that our authToken is OK to use
32-
verifyAuthToken();
31+
// Verify that our authToken is OK to use
32+
verifyAuthToken();
3333

34-
// Initialize this client as being an active client
35-
await ActiveClientManager.init();
36-
//TODO: Refactor window events
37-
// window.addEventListener('beforeunload', () => {
38-
// ActiveClientManager.removeClient();
39-
// });
40-
}
34+
// Initialize this client as being an active client
35+
await ActiveClientManager.init();
36+
//TODO: Refactor window events
37+
// window.addEventListener('beforeunload', () => {
38+
// ActiveClientManager.removeClient();
39+
// });
40+
}
4141

42-
/**
43-
* When the session changes, change which page the user sees
44-
*
45-
* @param {object} newSession
46-
*/
47-
sessionChanged(newSession) {
48-
this.setState({isAuthTokenValid: newSession && newSession.authToken});
49-
}
42+
/**
43+
* When the session changes, change which page the user sees
44+
*
45+
* @param {object} newSession
46+
*/
47+
sessionChanged(newSession) {
48+
this.setState({ isAuthTokenValid: newSession && newSession.authToken });
49+
}
5050

51-
render() {
52-
return (
53-
<Router>
54-
{/* If there is ever a property for redirecting, we do the redirect here */}
55-
{this.state.redirectTo && <Redirect to={this.state.redirectTo} />}
51+
render() {
52+
return (
53+
<Router>
54+
{/* If there is ever a property for redirecting, we do the redirect here */}
55+
{this.state.redirectTo && <Redirect to={this.state.redirectTo} />}
5656

57-
<Switch>
58-
<Route path="/signin" component={SignInPage} />
59-
<Route path="/" component={HomePage} />
60-
</Switch>
61-
</Router>
62-
);
63-
}
57+
<Switch>
58+
<Route path="/signin" component={SignInPage} />
59+
<Route path="/" component={HomePage} />
60+
</Switch>
61+
</Router>
62+
);
63+
}
6464
}

js/ROUTES.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
* This is a file containing constants for all of the routes we want to be able to go to
33
*/
44
export default {
5-
SIGNIN: '/signin',
6-
HOME: '/',
5+
SIGNIN: '/signin',
6+
HOME: '/',
77
};

js/config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const CONFIG = {
2-
PUSHER: {
3-
APP_KEY: '829fd8fd2a6036568469',
4-
CLUSTER: 'us3',
5-
},
2+
PUSHER: {
3+
APP_KEY: '829fd8fd2a6036568469',
4+
CLUSTER: 'us3',
5+
},
66
};

js/lib/ActiveClientManager.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ const clientID = Guid();
88
* Add our client ID to the list of active IDs
99
*/
1010
const init = async () => {
11-
const activeClientIDs = (await Store.get(STOREKEYS.ACTIVE_CLIENT_IDS)) || [];
12-
activeClientIDs.push(clientID);
13-
Store.set(STOREKEYS.ACTIVE_CLIENT_IDS, activeClientIDs);
11+
const activeClientIDs = (await Store.get(STOREKEYS.ACTIVE_CLIENT_IDS)) || [];
12+
activeClientIDs.push(clientID);
13+
Store.set(STOREKEYS.ACTIVE_CLIENT_IDS, activeClientIDs);
1414
};
1515

1616
/**
1717
* Remove this client ID from the array of active client IDs when this client is exited
1818
*/
1919
function removeClient() {
20-
const activeClientIDs = Store.get(STOREKEYS.ACTIVE_CLIENT_IDS) || [];
21-
const newActiveClientIDs = activeClientIDs.filter(
22-
(activeClientID) => activeClientID !== clientID,
23-
);
24-
Store.set(STOREKEYS.ACTIVE_CLIENT_IDS, newActiveClientIDs);
20+
const activeClientIDs = Store.get(STOREKEYS.ACTIVE_CLIENT_IDS) || [];
21+
const newActiveClientIDs = activeClientIDs.filter(
22+
(activeClientID) => activeClientID !== clientID,
23+
);
24+
Store.set(STOREKEYS.ACTIVE_CLIENT_IDS, newActiveClientIDs);
2525
}
2626

2727
/**
@@ -30,11 +30,11 @@ function removeClient() {
3030
* @returns {boolean}
3131
*/
3232
function isClientTheLeader() {
33-
const activeClientIDs = Store.get(STOREKEYS.ACTIVE_CLIENT_IDS) || [];
34-
if (!activeClientIDs.length) {
35-
return false;
36-
}
37-
return activeClientIDs[0] === clientID;
33+
const activeClientIDs = Store.get(STOREKEYS.ACTIVE_CLIENT_IDS) || [];
34+
if (!activeClientIDs.length) {
35+
return false;
36+
}
37+
return activeClientIDs[0] === clientID;
3838
}
3939

40-
export {init, removeClient, isClientTheLeader};
40+
export { init, removeClient, isClientTheLeader };

js/lib/DateUtils.js

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Str from './Str.js';
1111
* @private
1212
*/
1313
function getTimezone() {
14-
return 'America/Los_Angeles';
14+
return 'America/Los_Angeles';
1515
}
1616

1717
/**
@@ -25,9 +25,9 @@ function getTimezone() {
2525
* @private
2626
*/
2727
function getLocalMomentFromTimestamp(timestamp) {
28-
// We need a default here for flows where we may not have initialized the TIME_ZONE NVP like generatng PDFs in printablereport.php
29-
const timezone = getTimezone();
30-
return moment.unix(timestamp).tz(timezone);
28+
// We need a default here for flows where we may not have initialized the TIME_ZONE NVP like generatng PDFs in printablereport.php
29+
const timezone = getTimezone();
30+
return moment.unix(timestamp).tz(timezone);
3131
}
3232

3333
/**
@@ -44,15 +44,15 @@ function getLocalMomentFromTimestamp(timestamp) {
4444
* @returns {String}
4545
*/
4646
function timestampToDateTime(timestamp, includeTimeZone = false) {
47-
const date = getLocalMomentFromTimestamp(timestamp);
48-
let format =
49-
moment().year() !== date.get('year')
50-
? 'MMM D, YYYY [at] LT'
51-
: 'MMM D [at] LT';
52-
if (includeTimeZone) {
53-
format = `${format} [UTC]Z`;
54-
}
55-
return date.format(format);
47+
const date = getLocalMomentFromTimestamp(timestamp);
48+
let format =
49+
moment().year() !== date.get('year')
50+
? 'MMM D, YYYY [at] LT'
51+
: 'MMM D [at] LT';
52+
if (includeTimeZone) {
53+
format = `${format} [UTC]Z`;
54+
}
55+
return date.format(format);
5656
}
5757

5858
/**
@@ -73,44 +73,44 @@ function timestampToDateTime(timestamp, includeTimeZone = false) {
7373
* @returns {String}
7474
*/
7575
function timestampToRelative(timestamp) {
76-
const date = getLocalMomentFromTimestamp(timestamp);
77-
const durationFromLocalNow = moment.duration(
78-
date.diff(getLocalMomentFromTimestamp(moment().unix())),
79-
);
80-
const round = (num) => Math.floor(Math.abs(num));
76+
const date = getLocalMomentFromTimestamp(timestamp);
77+
const durationFromLocalNow = moment.duration(
78+
date.diff(getLocalMomentFromTimestamp(moment().unix())),
79+
);
80+
const round = (num) => Math.floor(Math.abs(num));
8181

82-
if (date.isAfter(moment().subtract(60, 'seconds'))) {
83-
return '< 1 minute ago';
84-
}
82+
if (date.isAfter(moment().subtract(60, 'seconds'))) {
83+
return '< 1 minute ago';
84+
}
8585

86-
if (date.isAfter(moment().subtract(60, 'minutes'))) {
87-
const minutes = round(durationFromLocalNow.asMinutes());
88-
return `${minutes} ${Str.pluralize('minute', 'minutes', minutes)} ago`;
89-
}
86+
if (date.isAfter(moment().subtract(60, 'minutes'))) {
87+
const minutes = round(durationFromLocalNow.asMinutes());
88+
return `${minutes} ${Str.pluralize('minute', 'minutes', minutes)} ago`;
89+
}
9090

91-
if (date.isAfter(moment().subtract(24, 'hours'))) {
92-
const hours = round(durationFromLocalNow.asHours());
93-
return `${hours} ${Str.pluralize('hour', 'hours', hours)} ago`;
94-
}
91+
if (date.isAfter(moment().subtract(24, 'hours'))) {
92+
const hours = round(durationFromLocalNow.asHours());
93+
return `${hours} ${Str.pluralize('hour', 'hours', hours)} ago`;
94+
}
9595

96-
if (date.isAfter(moment().subtract(30, 'days'))) {
97-
const days = round(durationFromLocalNow.asDays());
98-
return `${days} ${Str.pluralize('day', 'days', days)} ago`;
99-
}
96+
if (date.isAfter(moment().subtract(30, 'days'))) {
97+
const days = round(durationFromLocalNow.asDays());
98+
return `${days} ${Str.pluralize('day', 'days', days)} ago`;
99+
}
100100

101-
if (date.isAfter(moment().subtract(1, 'year'))) {
102-
return date.format('MMM D');
103-
}
101+
if (date.isAfter(moment().subtract(1, 'year'))) {
102+
return date.format('MMM D');
103+
}
104104

105-
return date.format('MMM D, YYYY');
105+
return date.format('MMM D, YYYY');
106106
}
107107

108108
/**
109109
* @namespace DateUtils
110110
*/
111111
const DateUtils = {
112-
timestampToRelative,
113-
timestampToDateTime,
112+
timestampToRelative,
113+
timestampToDateTime,
114114
};
115115

116116
export default DateUtils;

0 commit comments

Comments
 (0)