Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { PROD_URL, DEV_URL } from 'src/constants'
- const setTrueState = (thisisthis) => {
- thisisthis.setState({ isOnline: true })
- }
- const setFalseState = (thisisthis) => {
- thisisthis.setState({ isOnline: false })
- }
- export const isOnline = (thisisthis) => {
- if (typeof window !== 'undefined') {
- window.addEventListener('online', () => setTrueState(thisisthis))
- window.addEventListener('offline', () => setFalseState(thisisthis))
- }
- }
- export const removeListeners = () => {
- if (typeof window !== 'undefined') {
- window.removeEventListener('online', () => setTrueState())
- window.removeEventListener('offline', () => setFalseState())
- }
- }
- export const getUrl = (templateKey, slug) => {
- switch (templateKey) {
- case 'Interview':
- return `interview/${slug}`
- case 'News':
- return `news/${slug}`
- case 'Podcast':
- return `podcast/${slug}`
- case 'Video':
- return `video/${slug}`
- default:
- break
- }
- }
- export const getLink = (locale, path = '') => {
- return locale === 'ru' ? `/${path}` : `/en/${path}`
- }
- export const handleSortByDuration = (arr) => {
- return arr.sort((a, b) => a.sec - b.sec)
- }
- export const handleSortByDate = (arr) => {
- return [].concat(arr).sort((a, b) => (a.publishDate > b.publishDate ? 1 : b.publishDate > a.publishDate ? -1 : 0))
- }
- export const handleSortByOldDate = (arr) => {
- return arr.sort((a, b) => a.node.dateToTime - b.node.dateToTime)
- }
- export const handleSortByNewDate = (arr) => {
- return arr.sort((a, b) => b.node.dateToTime - a.node.dateToTime)
- }
- export const transformDurationInSeconds = (arr) => {
- return arr.map((item) => {
- let secondsDuration = item.duration
- .split(':')
- .map((item, index) => (index === 0 ? item * 60 : +item))
- .reduce((a, b) => a + b, 0)
- return (item.sec = secondsDuration)
- })
- }
- export const formateDate = (arr, publishdate) => {
- return arr.map((i) => {
- const tempArr = i.node[publishdate].split('/')
- let temp = tempArr[1]
- tempArr[1] = tempArr[0]
- tempArr[0] = temp
- const tempDate = tempArr.join('/')
- let dateToTime = Date.parse(tempDate)
- i.node.dateToTime = dateToTime
- return i
- })
- }
- export const shuffle = (array) => {
- let currentIndex = array.length
- let temporaryValue
- let randomIndex = 0
- // While there remain elements to shuffle...
- while (0 !== currentIndex) {
- // Pick a remaining element...
- randomIndex = Math.floor(Math.random() * currentIndex)
- currentIndex -= 1
- // And swap it with the current element.
- temporaryValue = array[currentIndex]
- array[currentIndex] = array[randomIndex]
- array[randomIndex] = temporaryValue
- }
- return array
- }
- export const getBaseUrl = (locale) => {
- switch (locale) {
- case 'ru': {
- if (process.env.NODE_ENV === 'development') {
- return `${DEV_URL}/`
- }
- return `${PROD_URL}/`
- }
- case 'en':
- if (process.env.NODE_ENV === 'development') {
- return `${DEV_URL}/en/`
- }
- return `${PROD_URL}/en/`
- default:
- return PROD_URL
- }
- }
- let counter = 0
- export const getStyles = (array, length) => {
- if (counter >= length - 1) {
- counter = 0
- }
- counter++
- // return array[Math.floor(Math.random() * length)]
- return array[counter]
- }
- export const colors = [
- { color: '#353533', bg: '#8AD3FB' },
- { color: '#353533', bg: '#E06C6C' },
- { color: '#353533', bg: '#4AAFB5' },
- { color: '#353533', bg: '#ECCB52' },
- { color: '#fff', bg: '#3F72AF' },
- { color: '#2D4059', bg: '#F07B3F' },
- { color: '#353533', bg: '#4AAFB5' },
- { color: '#00ADB5', bg: '#393E46' },
- ]
- export const blobPositions = [
- { top: '-120px', left: '60%' },
- { top: '80px', left: '75%' },
- { top: '-100px', left: '80%' },
- { top: '-240px', left: '70%' },
- { top: '-150px', left: '50%' },
- ]
Advertisement
Add Comment
Please, Sign In to add comment