More fixes/patches

This commit is contained in:
Ryan McGrath 2018-04-11 23:16:10 -04:00
parent 1f90ca2575
commit c02ad19f2b
No known key found for this signature in database
GPG key ID: 811674B62B666830
18 changed files with 582 additions and 239 deletions

35
utils/index.js Normal file
View file

@ -0,0 +1,35 @@
/**
* 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);
});
};