Files
notesnook/apps/mobile/src/utils/utils.js

77 lines
2.0 KiB
JavaScript
Raw Normal View History

2020-01-18 01:04:33 +05:00
import {DeviceEventEmitter, Dimensions} from 'react-native';
2019-11-17 02:48:19 +05:00
export const getElevation = elevation => {
return {
elevation,
shadowColor: 'black',
2019-11-27 21:44:52 +05:00
shadowOffset: {width: 0.3 * elevation, height: 0.5 * elevation},
shadowOpacity: 0.2,
shadowRadius: 0.7 * elevation,
2019-11-17 02:48:19 +05:00
};
};
2019-11-28 21:40:37 +05:00
export function timeSince(date) {
var seconds = Math.floor((new Date() - date) / 1000);
var interval = Math.floor(seconds / 31536000);
2020-01-17 10:56:52 +05:00
if (interval > 0.9) {
2019-11-28 21:40:37 +05:00
return interval < 2 ? interval + ' year ago' : interval + ' years ago';
}
interval = Math.floor(seconds / 2592000);
2020-01-17 10:56:52 +05:00
if (interval > 0.9) {
2019-11-28 21:40:37 +05:00
return interval < 2 ? interval + ' month ago' : interval + ' months ago';
}
interval = Math.floor(seconds / 86400);
2020-01-17 10:56:52 +05:00
if (interval > 0.9) {
2019-11-28 21:40:37 +05:00
return interval < 2 ? interval + ' day ago' : interval + ' days ago';
}
interval = Math.floor(seconds / 3600);
2020-01-17 10:56:52 +05:00
if (interval > 0.9) {
2019-11-28 21:40:37 +05:00
return interval < 2 ? interval + ' hour ago' : interval + ' hours ago';
}
interval = Math.floor(seconds / 60);
2020-01-17 10:56:52 +05:00
if (interval > 0.9) {
2019-11-28 21:40:37 +05:00
return interval < 2 ? interval + ' min ago' : interval + ' min ago';
}
return Math.floor(seconds) + ' secs ago';
}
2019-11-29 11:31:43 +05:00
export const w = Dimensions.get('window').width;
export const h = Dimensions.get('window').height;
2019-12-04 11:29:40 +05:00
export const ToastEvent = {
2019-12-05 17:40:09 +05:00
show: (message, type, duration = 10000, func = null, actionText = 'Ok') => {
DeviceEventEmitter.emit('showToast', {
message,
type,
duration,
func,
actionText,
});
2019-12-04 11:29:40 +05:00
},
2019-12-05 17:40:09 +05:00
hide: (message, type, duration = 1000, func = null, actionText = 'Ok') => {
DeviceEventEmitter.emit('hideToast', {
message,
type,
duration,
func,
actionText,
});
2019-12-04 11:29:40 +05:00
},
};
2019-12-04 19:38:19 +05:00
export const SideMenuEvent = {
open: () => {
DeviceEventEmitter.emit('openSidebar');
},
close: () => {
DeviceEventEmitter.emit('closeSidebar');
},
disable: () => {
DeviceEventEmitter.emit('disableGesture');
},
enable: () => {
DeviceEventEmitter.emit('enableGesture');
},
};