Skip to content

Commit

Permalink
Merge pull request #3573 from dklymenk/3272-update-message-date-overn…
Browse files Browse the repository at this point in the history
…ight

3272 update message date overnight
  • Loading branch information
francoisl authored Jun 14, 2021
2 parents d0e5fb1 + 1a13dc6 commit 892b546
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 1 deletion.
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

/**
* 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();
}

0 comments on commit 892b546

Please sign in to comment.