|
@@ -1,10 +1,10 @@
|
|
import { useState } from "react";
|
|
import { useState } from "react";
|
|
-import { screenWidth } from "./metrics";
|
|
|
|
import { Share } from "react-native";
|
|
import { Share } from "react-native";
|
|
|
|
|
|
-
|
|
|
|
-/*
|
|
|
|
- Executes before Render
|
|
|
|
|
|
+/**
|
|
|
|
+* Custom Hook to only be executed at Initial Mount. Similar to componentDidMount Lifecycle Method.
|
|
|
|
+* @param {Function} callBack - Callback Function to be executed
|
|
|
|
+* @return {null}
|
|
*/
|
|
*/
|
|
export const useConstructor = (callBack = () => { }) => {
|
|
export const useConstructor = (callBack = () => { }) => {
|
|
const [hasBeenCalled, setHasBeenCalled] = useState(false);
|
|
const [hasBeenCalled, setHasBeenCalled] = useState(false);
|
|
@@ -13,6 +13,9 @@ export const useConstructor = (callBack = () => { }) => {
|
|
setHasBeenCalled(true);
|
|
setHasBeenCalled(true);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * Datetime Constants
|
|
|
|
+ */
|
|
const _MS_PER_SECOND = 1000;
|
|
const _MS_PER_SECOND = 1000;
|
|
const _MS_PER_MINUTE = _MS_PER_SECOND * 60;
|
|
const _MS_PER_MINUTE = _MS_PER_SECOND * 60;
|
|
const _MS_PER_HOUR = _MS_PER_MINUTE * 60;
|
|
const _MS_PER_HOUR = _MS_PER_MINUTE * 60;
|
|
@@ -20,8 +23,19 @@ const _MS_PER_DAY = _MS_PER_HOUR * 24;
|
|
const _MS_PER_MONTH = _MS_PER_DAY * 31;
|
|
const _MS_PER_MONTH = _MS_PER_DAY * 31;
|
|
const _MS_PER_YEAR = _MS_PER_MONTH * 12;
|
|
const _MS_PER_YEAR = _MS_PER_MONTH * 12;
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+* Capitilize String.
|
|
|
|
+* @param {string} str - Text String
|
|
|
|
+* @return {string} Capitalized String.
|
|
|
|
+*/
|
|
export const capitalize = (str) => str.charAt(0).toUpperCase() + str.substring(1, str.length).toLowerCase()
|
|
export const capitalize = (str) => str.charAt(0).toUpperCase() + str.substring(1, str.length).toLowerCase()
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+* Get Difference betweenn two dates.
|
|
|
|
+* @param {Date} startDate - Start Date
|
|
|
|
+* @param {Date} endDate - End Date
|
|
|
|
+* @return {object} Returns differences in years,months, days, hours, minutes and seconds .
|
|
|
|
+*/
|
|
export const getDifferenceInDates = (startDate, endDate) => {
|
|
export const getDifferenceInDates = (startDate, endDate) => {
|
|
var diff = Math.floor(startDate.getTime() - endDate.getTime());
|
|
var diff = Math.floor(startDate.getTime() - endDate.getTime());
|
|
return {
|
|
return {
|
|
@@ -35,8 +49,13 @@ export const getDifferenceInDates = (startDate, endDate) => {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-export const getTimestamp = (iso_date_str) => {
|
|
|
|
- let diffObj = getDifferenceInDates(new Date(), new Date(iso_date_str))
|
|
|
|
|
|
+/**
|
|
|
|
+* get Humanized Timestamp.
|
|
|
|
+* @param {string} isoTimestamp - ISO String for Timestamp
|
|
|
|
+* @return {string} Humanized Timestamp
|
|
|
|
+*/
|
|
|
|
+export const getTimestamp = (isoTimestamp) => {
|
|
|
|
+ let diffObj = getDifferenceInDates(new Date(), new Date(isoTimestamp))
|
|
var result = "Timestamp Not Found"
|
|
var result = "Timestamp Not Found"
|
|
for (const key of Object.keys(diffObj)) {
|
|
for (const key of Object.keys(diffObj)) {
|
|
if (diffObj[key] > 0) {
|
|
if (diffObj[key] > 0) {
|
|
@@ -48,6 +67,11 @@ export const getTimestamp = (iso_date_str) => {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+* Get Month Name.
|
|
|
|
+* @param {string} index - Month Index Number.
|
|
|
|
+* @return {string} Month Name
|
|
|
|
+*/
|
|
const _getMonth = (index) => {
|
|
const _getMonth = (index) => {
|
|
const months = {
|
|
const months = {
|
|
0: "January",
|
|
0: "January",
|
|
@@ -70,56 +94,66 @@ const _getMonth = (index) => {
|
|
return "Month Not Found"
|
|
return "Month Not Found"
|
|
}
|
|
}
|
|
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-export const getDate = (iso_date_str) => {
|
|
|
|
- let date = new Date(iso_date_str)
|
|
|
|
|
|
+/**
|
|
|
|
+* Get Humanized DateTime.
|
|
|
|
+* @param {string} isoTimestamp - ISO String for Timestamp.
|
|
|
|
+* @return {string} Humanized Date String
|
|
|
|
+*/}
|
|
|
|
+export const getDate = (isoTimestamp) => {
|
|
|
|
+ let date = new Date(isoTimestamp)
|
|
return `${date.getDate()} ${_getMonth(date.getMonth())} ${date.getFullYear()}`
|
|
return `${date.getDate()} ${_getMonth(date.getMonth())} ${date.getFullYear()}`
|
|
}
|
|
}
|
|
|
|
|
|
-const MOBILE_SCREEN_BREAKPOINT = 480;
|
|
|
|
-const TABLET_SCREEN_BREAKPOINT = 768;
|
|
|
|
-const LARGE_SCREEN_BREAKPOINT = 1180;
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-export const MOBILE_SCREEN = "Mobile"
|
|
|
|
-export const TABLET_SCREEN = "Tablet"
|
|
|
|
-export const DESKTOP_SCREEN = "Desktop"
|
|
|
|
-
|
|
|
|
-export const getScreenType = () => {
|
|
|
|
- let screenType;
|
|
|
|
- if (screenWidth <= MOBILE_SCREEN_BREAKPOINT) {
|
|
|
|
- screenType = MOBILE_SCREEN
|
|
|
|
- } else if (screenWidth <= TABLET_SCREEN_BREAKPOINT) {
|
|
|
|
- screenType = TABLET_SCREEN
|
|
|
|
- } else {
|
|
|
|
- screenType = DESKTOP_SCREEN
|
|
|
|
- }
|
|
|
|
- return screenType
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
|
|
+/**
|
|
|
|
+* Checks if Email is valid or not.
|
|
|
|
+* @param {string} email - Email to be Validated
|
|
|
|
+* @return {boolean}.
|
|
|
|
+* For the Email Regex, Refer: {@link https://regex101.com/r/sI6yF5/1}
|
|
|
|
+*/
|
|
export const validateEmail = (email) => {
|
|
export const validateEmail = (email) => {
|
|
- const emailRegex = "^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*$"
|
|
|
|
|
|
+ const emailRegex = "/^([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x22([^\x0d\x22\x5c\x80-\xff]|\x5c[\x00-\x7f])*\x22))*\x40([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d)(\x2e([^\x00-\x20\x22\x28\x29\x2c\x2e\x3a-\x3c\x3e\x40\x5b-\x5d\x7f-\xff]+|\x5b([^\x0d\x5b-\x5d\x80-\xff]|\x5c[\x00-\x7f])*\x5d))*$/"
|
|
return String(email).match(emailRegex)
|
|
return String(email).match(emailRegex)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+* Navigate to News Detail Page.
|
|
|
|
+* @param {any} navigation - Navigation Prop
|
|
|
|
+* @param {String} article_id - Article ID
|
|
|
|
+* @param {String} article_slug - Article Slug
|
|
|
|
+* @return {null}.
|
|
|
|
+*/
|
|
export const navigateToArticle = (navigation, article_id, article_slug) => {
|
|
export const navigateToArticle = (navigation, article_id, article_slug) => {
|
|
- // navigation.navigate("HomePageNav",{screen:"MainNav",params:{screen:'NewsDetailPage',params:{slug: article_slug, id: article_id}}})
|
|
|
|
-
|
|
|
|
navigation.push("NewsDetailPage", { slug: article_slug, id: article_id })
|
|
navigation.push("NewsDetailPage", { slug: article_slug, id: article_id })
|
|
navigation.navigate("NewsDetailPage", { slug: article_slug, id: article_id })
|
|
navigation.navigate("NewsDetailPage", { slug: article_slug, id: article_id })
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
+/**
|
|
|
|
+* Navigate to List View Page with Topic Type and Type.
|
|
|
|
+* @param {any} navigation - Navigation Prop
|
|
|
|
+* @param {any} topic_type - Topic Type
|
|
|
|
+* @param {any} topic - Topic
|
|
|
|
+* @return {null}.
|
|
|
|
+*/
|
|
export const navigateToListViewPage = (navigation, topic_type, topic) => {
|
|
export const navigateToListViewPage = (navigation, topic_type, topic) => {
|
|
navigation.navigate("NewsListPage", { type: topic_type, title: topic } )
|
|
navigation.navigate("NewsListPage", { type: topic_type, title: topic } )
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+* Navigate to Home Page.
|
|
|
|
+* @param {any} navigation - Navigation Prop
|
|
|
|
+* @return {null}.
|
|
|
|
+*/
|
|
export const navigateToHomePage = (navigation) => {
|
|
export const navigateToHomePage = (navigation) => {
|
|
navigation.navigate("MainPage")
|
|
navigation.navigate("MainPage")
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+* Sharing Function to share data across other apps.
|
|
|
|
+* @param {object} myOptions - Parameters for Sharing Modal.
|
|
|
|
+* @return {null}.
|
|
|
|
+*/
|
|
export const onShare = async (myOptions) => {
|
|
export const onShare = async (myOptions) => {
|
|
try {
|
|
try {
|
|
await Share.share(myOptions);
|
|
await Share.share(myOptions);
|