This repository has been archived on 2026-03-31. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
memelee/utils/index.js
2018-04-11 23:16:10 -04:00

35 lines
994 B
JavaScript

/**
* Utils
*
* Various utilities used throughout the app. A kitchen junk drawer, if you will.
*
* @copyright Ryan McGrath 2018
*/
import {Linking} from 'react-native';
export const parseSlugs = (tournament, evt) => {
const evtSlugs = evt && evt.slug.split('/');
const evtSlug = evt && evtSlugs.length > 0 ? evtSlugs[evtSlugs.length - 1] : null;
const tournamentSlug = (
tournament.slug ? tournament.slug :
tournament.slugs && tournament.slugs.length ? tournament.slugs[0] : ''
).replace('tournament/', '');
const slugs = {tournamentSlug: null, evtSlug: null};
if(tournamentSlug && tournamentSlug !== '')
slugs.tournament = tournamentSlug;
if(evtSlug && evtSlug !== '')
slugs.evt = evtSlug;
return slugs;
};
export const openURL = (url) => {
return Linking.canOpenURL(url).then(supported => {
if(supported) Linking.openURL(url);
else console.warn('Cannot open URL: ' + url);
});
};