aboutsummaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorIvan Chen <ivan@thetaggid.com>2020-12-29 20:21:24 -0500
committerGitHub <noreply@github.com>2020-12-29 20:21:24 -0500
commitbd2f89805d0bb1c2f1d08fe8d91099aa4f109d35 (patch)
treeac7219e034a0c4035096c6df8dbe6b92446b5111 /src/utils
parentec478d4981c726856485b49b49ac33b0d9e6a903 (diff)
[TMA-461] Notifications Screen (#151)
* renamed ProfileStack to MainStack, created initial notifications data type * cleaned up code * added notifications to redux * finished sectioned list * updated types to make more sense * finished sectioned notifications by date * updated notification type and tested mock backend integration * finished read or unread logic * minor changes * another minor fix * finished integration * moved stuff * added ability to navigate to user profile Co-authored-by: Husam Salhab <47015061+hsalhab@users.noreply.github.com>
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()),