Skip to content
Merged
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
3 changes: 3 additions & 0 deletions src/ONYXKEYS.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export default {
// What the active route is for our navigator. Global route that determines what views to display.
CURRENT_URL: 'currentURL',

// Stores current date
CURRENT_DATE: 'currentDate',

// Currently viewed reportID
CURRENTLY_VIEWED_REPORTID: 'currentlyViewedReportID',

Expand Down
19 changes: 19 additions & 0 deletions src/libs/DateUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,31 @@ function timestampToRelative(locale, timestamp) {
return moment(date).fromNow();
}

/**
* A throttled version of a function that updates the current date in Onyx store
*/
const updateCurrentDate = _.throttle(() => {
const currentDate = moment().format('YYYY-MM-DD');
Onyx.set(ONYXKEYS.CURRENT_DATE, currentDate);
}, 1000 * 60 * 60 * 3); // 3 hours
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, why 3 hours?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah nevermind, I see the context in the issue :)


/**
* Initialises the event listeners that trigger the current date update
*/
function startCurrentDateUpdater() {
const trackedEvents = ['mousemove', 'touchstart', 'keydown', 'scroll'];
trackedEvents.forEach((eventName) => {
document.addEventListener(eventName, updateCurrentDate);
});
}

/**
* @namespace DateUtils
*/
const DateUtils = {
timestampToRelative,
timestampToDateTime,
startCurrentDateUpdater,
};

export default DateUtils;
13 changes: 12 additions & 1 deletion src/pages/home/report/ReportActionItemDate.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import React, {memo} from 'react';
import PropTypes from 'prop-types';
import {Text} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import styles from '../../../styles/styles';
import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize';
import compose from '../../../libs/compose';
import ONYXKEYS from '../../../ONYXKEYS';

const propTypes = {
/** UTC timestamp for when the action was created */
Expand All @@ -19,4 +22,12 @@ const ReportActionItemDate = props => (
ReportActionItemDate.propTypes = propTypes;
ReportActionItemDate.displayName = 'ReportActionItemDate';

export default withLocalize(memo(ReportActionItemDate));
export default compose(
withLocalize,
withOnyx({
currentDate: {
key: ONYXKEYS.CURRENT_DATE,
},
}),
memo,
)(ReportActionItemDate);
4 changes: 4 additions & 0 deletions src/setup/index.desktop.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {AppRegistry} from 'react-native';
import {ipcRenderer} from 'electron';
import Config from '../CONFIG';
import LocalNotification from '../libs/Notification/LocalNotification';
import DateUtils from '../libs/DateUtils';


export default function () {
Expand All @@ -12,4 +13,7 @@ export default function () {
ipcRenderer.on('update-downloaded', () => {
LocalNotification.showUpdateAvailableNotification();
});

// Start current date updater
DateUtils.startCurrentDateUpdater();
}
4 changes: 4 additions & 0 deletions src/setup/index.website.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {AppRegistry} from 'react-native';
import checkForUpdates from '../libs/checkForUpdates';
import Config from '../CONFIG';
import HttpUtils from '../libs/HttpUtils';
import DateUtils from '../libs/DateUtils';
import {version as currentVersion} from '../../package.json';
import Visibility from '../libs/Visibility';

Expand Down Expand Up @@ -56,4 +57,7 @@ export default function () {
if (Config.IS_IN_PRODUCTION) {
checkForUpdates(webUpdater());
}

// Start current date updater
DateUtils.startCurrentDateUpdater();
}