aboutsummaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/common.ts19
-rw-r--r--src/utils/users.ts14
2 files changed, 27 insertions, 6 deletions
diff --git a/src/utils/common.ts b/src/utils/common.ts
index ae83ad9c..27411149 100644
--- a/src/utils/common.ts
+++ b/src/utils/common.ts
@@ -1,3 +1,4 @@
+import moment from 'moment';
import {Linking} from 'react-native';
import {BROWSABLE_SOCIAL_URLS, TOGGLE_BUTTON_TYPE} from '../constants';
@@ -23,3 +24,21 @@ export const handleOpenSocialUrlOnBrowser = (
Linking.openURL(BROWSABLE_SOCIAL_URLS[social] + `${handle}/`);
}
};
+
+export const getDateAge: (
+ date: moment.Moment,
+) => 'today' | 'yesterday' | 'thisWeek' | 'unknown' = (date: moment.Moment) => {
+ const today = moment().startOf('day');
+ const yesterday = moment().subtract(1, 'days').startOf('day');
+ const weekOld = moment().subtract(7, 'days').startOf('day');
+ if (date.isSame(today, 'd')) {
+ return 'today';
+ } else if (date.isSame(yesterday, 'd')) {
+ return 'yesterday';
+ } else if (date.isAfter(weekOld)) {
+ return 'thisWeek';
+ } else {
+ // this can be longer than a week or in the future
+ return 'unknown';
+ }
+};
diff --git a/src/utils/users.ts b/src/utils/users.ts
index 4f93347d..be92d184 100644
--- a/src/utils/users.ts
+++ b/src/utils/users.ts
@@ -1,10 +1,6 @@
-import {loadUserMomentCategories} from './../store/actions/momentCategories';
-import {loadUserX} from './../store/actions/userX';
-import {RootState} from './../store/rootReducer';
import AsyncStorage from '@react-native-community/async-storage';
-import {AppDispatch} from './../store/configureStore';
-import {UserType, ScreenType} from './../types/types';
import {INTEGRATED_SOCIAL_LIST} from '../constants';
+import {loadSocialPosts} from '../services';
import {
loadAllSocials,
loadBlockedList,
@@ -12,10 +8,15 @@ import {
loadRecentlySearched,
loadUserData,
loadUserMoments,
+ loadUserNotifications,
} from '../store/actions';
import {NO_SOCIAL_ACCOUNTS} from '../store/initialStates';
-import {loadSocialPosts} from '../services';
import {userLoggedIn} from '../store/reducers';
+import {loadUserMomentCategories} from './../store/actions/momentCategories';
+import {loadUserX} from './../store/actions/userX';
+import {AppDispatch} from './../store/configureStore';
+import {RootState} from './../store/rootReducer';
+import {ScreenType, UserType} from './../types/types';
const loadData = async (dispatch: AppDispatch, user: UserType) => {
await Promise.all([
@@ -23,6 +24,7 @@ const loadData = async (dispatch: AppDispatch, user: UserType) => {
dispatch(loadFollowData(user.userId)),
dispatch(loadUserMomentCategories(user.userId)),
dispatch(loadUserMoments(user.userId)),
+ dispatch(loadUserNotifications()),
dispatch(loadAllSocials(user.userId)),
dispatch(loadBlockedList(user.userId)),
dispatch(loadRecentlySearched()),