blob: a2f88e8ba1c1e4533260dac4547241e34cf43d6e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
import moment from 'moment';
import {Linking} from 'react-native';
import {BROWSABLE_SOCIAL_URLS, TOGGLE_BUTTON_TYPE} from '../constants';
export const getToggleButtonText: (
buttonType: string,
state: boolean,
) => string | null = (buttonType, state) => {
switch (buttonType) {
case TOGGLE_BUTTON_TYPE.FRIEND_UNFRIEND:
return state ? 'Unfriend' : 'Add Friend';
case TOGGLE_BUTTON_TYPE.BLOCK_UNBLOCK:
return state ? 'Unblock' : 'Block';
default:
return null;
}
};
export const handleOpenSocialUrlOnBrowser = (
handle: string | undefined,
social: string,
) => {
if (handle && social in BROWSABLE_SOCIAL_URLS) {
Linking.openURL(BROWSABLE_SOCIAL_URLS[social] + `${handle}/`);
}
};
//Returns university class just like we would like to display on profile page
export const getUniversityClass = (universityClass: number) => {
return `Class of ${(universityClass % 2000).toString()}'`;
};
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';
}
};
|