Skip to content

Commit c206eb3

Browse files
authored
Merge pull request #2076 from StoDevX/globals
Use Globals and Global Functions for Constant URLs
2 parents 69b920d + fdaf175 commit c206eb3

File tree

13 files changed

+41
-29
lines changed

13 files changed

+41
-29
lines changed

source/globals.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @flow
2+
3+
export const GH_PAGES_URL = (relativePath: string) => {
4+
return `https://stodevx.github.io/AAO-React-Native/${relativePath}`
5+
}
6+
7+
export const GH_NEW_ISSUE_URL =
8+
'https://github.com/StoDevX/AAO-React-Native/issues/new'

source/views/building-hours/report/submit.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import jsYaml from 'js-yaml'
44
import type {BuildingType} from '../types'
55
import {email} from 'react-native-communications'
66
import querystring from 'querystring'
7+
import {GH_NEW_ISSUE_URL} from '../../../globals'
78

89
export function submitReport(current: BuildingType, suggestion: BuildingType) {
910
// calling trim() on these to remove the trailing newlines
@@ -64,7 +65,7 @@ function makeIssueLink(before: string, after: string, title: string): string {
6465
title: `Building hours update for ${title}`,
6566
body: makeMarkdownBody(before, after),
6667
})
67-
return `https://github.com/StoDevX/AAO-React-Native/issues/new?${q}`
68+
return `${GH_NEW_ISSUE_URL}?${q}`
6869
}
6970

7071
function stringifyBuilding(building: BuildingType): string {

source/views/building-hours/stateful-list.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import {reportNetworkProblem} from '../../lib/report-network-problem'
1313
import toPairs from 'lodash/toPairs'
1414
import groupBy from 'lodash/groupBy'
1515
import delay from 'delay'
16-
1716
import {CENTRAL_TZ} from './lib'
18-
const githubBaseUrl =
19-
'https://stodevx.github.io/AAO-React-Native/building-hours.json'
17+
import {GH_PAGES_URL} from '../../globals'
18+
19+
const buildingHoursUrl = GH_PAGES_URL('building-hours.json')
2020

2121
const groupBuildings = (buildings: BuildingType[], favorites: string[]) => {
2222
const favoritesGroup = {
@@ -109,7 +109,7 @@ export class BuildingHoursView extends React.PureComponent<Props, State> {
109109
}
110110

111111
fetchData = async () => {
112-
let {data: buildings} = await fetchJson(githubBaseUrl).catch(err => {
112+
let {data: buildings} = await fetchJson(buildingHoursUrl).catch(err => {
113113
reportNetworkProblem(err)
114114
return defaultData
115115
})

source/views/contacts/contact-detail.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import {tracker} from '../../analytics'
1010
import {Button} from '../components/button'
1111
import openUrl from '../components/open-url'
1212
import type {ContactType} from './types'
13-
14-
const AAO_URL = 'https://github.com/StoDevX/AAO-React-Native/issues/new'
13+
import {GH_NEW_ISSUE_URL} from '../../globals'
1514

1615
const Title = glamorous.text({
1716
fontSize: 36,
@@ -93,7 +92,7 @@ export class ContactsDetailView extends React.PureComponent<Props> {
9392
<Button onPress={this.onPress} title={contact.buttonText} />
9493

9594
<ListFooter
96-
href={AAO_URL}
95+
href={GH_NEW_ISSUE_URL}
9796
title="Collected by the humans of All About Olaf"
9897
/>
9998
</Container>

source/views/contacts/contact-list.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import toPairs from 'lodash/toPairs'
1313
import * as c from '../components/colors'
1414
import type {ContactType} from './types'
1515
import type {TopLevelViewPropsType} from '../types'
16+
import {GH_PAGES_URL} from '../../globals'
1617

17-
const GITHUB_URL =
18-
'https://stodevx.github.io/AAO-React-Native/contact-info.json'
18+
const contactInfoUrl = GH_PAGES_URL('contact-info.json')
1919

2020
const groupContacts = (contacts: ContactType[]) => {
2121
const grouped = groupBy(contacts, c => c.category)
@@ -70,7 +70,7 @@ export class ContactsListView extends React.PureComponent<Props, State> {
7070
}
7171

7272
fetchData = async () => {
73-
let {data: contacts} = await fetchJson(GITHUB_URL).catch(err => {
73+
let {data: contacts} = await fetchJson(contactInfoUrl).catch(err => {
7474
reportNetworkProblem(err)
7575
return defaultData
7676
})

source/views/dictionary/detail.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import {Markdown} from '../components/markdown'
55
import {ListFooter} from '../components/list'
66
import glamorous from 'glamorous-native'
77
import type {WordType} from './types'
8+
import {GH_NEW_ISSUE_URL} from '../../globals'
89

910
// TODO: This doesn't point at the SA dictionary because they don't have an
1011
// overview page.
11-
const STO_SA_DICT_URL = 'https://github.com/StoDevX/AAO-React-Native/issues/new'
12+
const STO_SA_DICT_URL = GH_NEW_ISSUE_URL
1213

1314
const Term = glamorous.text({
1415
fontSize: 36,

source/views/dictionary/list.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ import uniq from 'lodash/uniq'
2121
import words from 'lodash/words'
2222
import deburr from 'lodash/deburr'
2323
import * as defaultData from '../../../docs/dictionary.json'
24+
import {GH_PAGES_URL} from '../../globals'
25+
26+
const dictionaryUrl = GH_PAGES_URL('dictionary.json')
2427

25-
const GITHUB_URL = 'https://stodevx.github.io/AAO-React-Native/dictionary.json'
2628
const ROW_HEIGHT = Platform.OS === 'ios' ? 76 : 89
2729
const SECTION_HEADER_HEIGHT = Platform.OS === 'ios' ? 33 : 41
2830

@@ -83,7 +85,7 @@ export class DictionaryView extends React.PureComponent<Props, State> {
8385
}
8486

8587
fetchData = async () => {
86-
let {data: allTerms} = await fetchJson(GITHUB_URL).catch(err => {
88+
let {data: allTerms} = await fetchJson(dictionaryUrl).catch(err => {
8789
reportNetworkProblem(err)
8890
return defaultData
8991
})

source/views/faqs/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import {reportNetworkProblem} from '../../lib/report-network-problem'
77
import LoadingView from '../components/loading'
88
import * as defaultData from '../../../docs/faqs.json'
99
import delay from 'delay'
10+
import {GH_PAGES_URL} from '../../globals'
1011

11-
const faqsUrl = 'https://stodevx.github.io/AAO-React-Native/faqs.json'
12+
const faqsUrl = GH_PAGES_URL('faqs.json')
1213

1314
type Props = {}
1415

source/views/menus/menu-github.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import {upgradeMenuItem, upgradeStation} from './lib/process-menu-shorthands'
2020
import {data as fallbackMenu} from '../../../docs/pause-menu.json'
2121
import {tracker} from '../../analytics'
2222
import bugsnag from '../../bugsnag'
23-
const CENTRAL_TZ = 'America/Winnipeg'
23+
import {GH_PAGES_URL} from '../../globals'
2424

25-
const githubMenuBaseUrl = 'https://stodevx.github.io/AAO-React-Native'
25+
const CENTRAL_TZ = 'America/Winnipeg'
2626

2727
type Props = TopLevelViewPropsType & {
2828
name: string,
@@ -59,7 +59,7 @@ export class GitHubHostedMenu extends React.PureComponent<Props, State> {
5959
let stationMenus: StationMenuType[] = []
6060
let corIcons: MasterCorIconMapType = {}
6161
try {
62-
let container = await fetchJson(`${githubMenuBaseUrl}/pause-menu.json`)
62+
let container = await fetchJson(GH_PAGES_URL('pause-menu.json'))
6363
let data = container.data
6464
foodItems = data.foodItems || []
6565
stationMenus = data.stationMenus || []

source/views/streaming/webcams/list.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import {Column} from '../../components/layout'
1010
import {partitionByIndex} from '../../../lib/partition-by-index'
1111
import type {Webcam} from './types'
1212
import {StreamThumbnail} from './thumbnail'
13+
import {GH_PAGES_URL} from '../../../globals'
1314

14-
const GITHUB_URL = 'https://stodevx.github.io/AAO-React-Native/webcams.json'
15+
const webcamsUrl = GH_PAGES_URL('webcams.json')
1516

1617
type Props = {}
1718

@@ -66,7 +67,7 @@ export class WebcamsView extends React.PureComponent<Props, State> {
6667
fetchData = async () => {
6768
this.setState(() => ({loading: true}))
6869

69-
let {data: webcams} = await fetchJson(GITHUB_URL).catch(err => {
70+
let {data: webcams} = await fetchJson(webcamsUrl).catch(err => {
7071
reportNetworkProblem(err)
7172
return defaultData
7273
})

0 commit comments

Comments
 (0)