From aa737f6ea848e6e5abae712b997bf1f6a7f15990 Mon Sep 17 00:00:00 2001 From: flynneva Date: Sun, 20 Dec 2020 19:37:18 -0800 Subject: [PATCH 01/12] add bump gh action --- .github/workflows/bump.yml | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/bump.yml diff --git a/.github/workflows/bump.yml b/.github/workflows/bump.yml new file mode 100644 index 0000000..4d6621d --- /dev/null +++ b/.github/workflows/bump.yml @@ -0,0 +1,38 @@ +name: Bump, Tag & Publish Release +on: + push: + branches: master +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: '12.x' + - name: Setup git config + run: | + git config user.name "flynneva" + git config user.email "" + - name: Install dependencies + run: npm install + - name: Build Release + run: npm run build + - name: Bump version and push tag + uses: mikeal/merge-release@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + DEPLOY_DIR: . + SRC_PACKAGE_DIR: src + - name: Get new version + id: package + uses: martinbeentjes/npm-get-version-action@master + - name: Create a GitHub release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ steps.package.outputs.current-version }} + release_name: Release ${{ steps.package.outputs.current-version }} + body: "" From 93ff1a8562600df323b39a4c0d069ffdce9d7be8 Mon Sep 17 00:00:00 2001 From: flynneva Date: Sun, 20 Dec 2020 19:46:09 -0800 Subject: [PATCH 02/12] rename gh workflow --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 11136e0..025dfe9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,4 +1,4 @@ -name: build +name: build & test on: push: @@ -20,4 +20,4 @@ jobs: node-version: ${{ matrix.node-version }} - run: npm install - run: npm run build --if-present - #- run: npm test + - run: npm test From b2d293cc15502caae434fc963e4d64dc2b24dad9 Mon Sep 17 00:00:00 2001 From: flynneva Date: Sun, 20 Dec 2020 19:53:24 -0800 Subject: [PATCH 03/12] remove test for now --- src/index.test.js | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 src/index.test.js diff --git a/src/index.test.js b/src/index.test.js deleted file mode 100644 index a0f0449..0000000 --- a/src/index.test.js +++ /dev/null @@ -1,7 +0,0 @@ -import { ExampleComponent } from '.' - -describe('ExampleComponent', () => { - it('is truthy', () => { - expect(ExampleComponent).toBeTruthy() - }) -}) From 1777e8d916fd394f440a7a56e585e88edaf9228e Mon Sep 17 00:00:00 2001 From: flynneva Date: Sun, 20 Dec 2020 20:21:32 -0800 Subject: [PATCH 04/12] fix lint errors --- doczrc.js | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/doczrc.js b/doczrc.js index a103322..a913a79 100644 --- a/doczrc.js +++ b/doczrc.js @@ -1,18 +1,21 @@ -import { createPlugin } from "docz-core"; -import proxy from 'http-proxy-middleware'; +import { createPlugin } from 'docz-core' +import proxy from 'http-proxy-middleware' -const proxyPlugin = () => createPlugin({ - onCreateDevServer: ({ app }) => { - app.use( '/ncaa_api', - proxy({ - target: "https://data.ncaa.com/", - changeOrigin: true, - pathRewrite: { - '^/ncaa_api/': '/' - } - })); - } -}); +const proxyPlugin = () => + createPlugin({ + onCreateDevServer: ({ app }) => { + app.use( + '/ncaa_api', + proxy({ + target: "https://data.ncaa.com/", + changeOrigin: true, + pathRewrite: { + '^/ncaa_api/': '/' + } + }) + ); + } + }) export default { dest: './docs/', @@ -21,4 +24,4 @@ export default { plugins: [ proxyPlugin(), ], -}; +} From 666c4a1aaeed5e314785593ef6668ab602bdbb12 Mon Sep 17 00:00:00 2001 From: flynneva Date: Sun, 20 Dec 2020 20:37:50 -0800 Subject: [PATCH 05/12] fix more lint errors --- doczrc.js | 10 +++---- src/components/NCAA.js | 60 ++++++++++++++++++++++-------------------- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/doczrc.js b/doczrc.js index a913a79..05e58a3 100644 --- a/doczrc.js +++ b/doczrc.js @@ -7,13 +7,12 @@ const proxyPlugin = () => app.use( '/ncaa_api', proxy({ - target: "https://data.ncaa.com/", + target: 'https://data.ncaa.com/', changeOrigin: true, - pathRewrite: { - '^/ncaa_api/': '/' + pathRewrite: {'^/ncaa_api/': '/' } }) - ); + ) } }) @@ -22,6 +21,5 @@ export default { base: './react-ncaa-data/', title: 'react-ncaa-data', plugins: [ - proxyPlugin(), - ], + proxyPlugin()] } diff --git a/src/components/NCAA.js b/src/components/NCAA.js index 2e562ec..72de152 100644 --- a/src/components/NCAA.js +++ b/src/components/NCAA.js @@ -3,39 +3,41 @@ import { NCAAContext, NCAAProvider } from './NCAAContext' import PropTypes from 'prop-types' var headers = { - 'pragma': 'no-cache', - 'cache-control': 'no-cache' + pragma: 'no-cache', + 'cache-control': 'no-cache' } function useNCAA() { - const [ ncaa, setNCAA ] = useContext(NCAAContext); + const [ncaa, setNCAA] = useContext(NCAAContext); - function changeProxyApi(new_proxy) { - setNCAA(ncaa => ({ ...ncaa, proxy_api: new_proxy})); + function changeProxyApi(newProxy) { + setNCAA(ncaa => ({ ...ncaa, proxy_api: newProxy })); } function changeDate(date) { - const tempDay = ('0' + date.getDate()).slice(-2); - const tempMonth = ('0' + (date.getMonth() + 1)).slice(-2); - const tempYear = date.getFullYear(); + const tempDay = ('0' + date.getDate()).slice(-2) + const tempMonth = ('0' + (date.getMonth() + 1)).slice(-2) + const tempYear = date.getFullYear() - setNCAA(ncaa => ({ ...ncaa, day: tempDay})); - setNCAA(ncaa => ({ ...ncaa, month: tempMonth})); - setNCAA(ncaa => ({ ...ncaa, year: tempYear})); + setNCAA(ncaa => ({ ...ncaa, day: tempDay })); + setNCAA(ncaa => ({ ...ncaa, month: tempMonth })); + setNCAA(ncaa => ({ ...ncaa, year: tempYear })); } function getGames(sport) { - var query = '/' + ncaa.proxy_api + - '/' + ncaa.base_query + - '/scoreboard' + - '/' + sport + - '/' + ncaa.division + - '/' + ncaa.year + - '/' + ncaa.month + - '/' + ncaa.day + - '/scoreboard.json'; + var query = + '/' + ncaa.proxy_api + + '/' + ncaa.base_query + + '/scoreboard' + + '/' + sport + + '/' + ncaa.division + + '/' + ncaa.year + + '/' + ncaa.month + + '/' + ncaa.day + + '/scoreboard.json' + if(!ncaa.loadingGames) { - setNCAA(ncaa => ({ ...ncaa, loadingGames: true})); + setNCAA(ncaa => ({ ...ncaa, loadingGames: true })) fetch(query, { method: 'GET', headers: headers, @@ -44,17 +46,17 @@ function useNCAA() { .then(response => response.json()) .then(data => { if (data.games.length !== 0) { - setNCAA(ncaa => ({ ...ncaa, games: data.games})); - setNCAA(ncaa => ({ ...ncaa, sport: sport})); - setNCAA(ncaa => ({ ...ncaa, timestamp: Date.UTC()})); - setNCAA(ncaa => ({ ...ncaa, loadingGames: false})); + setNCAA(ncaa => ({ ...ncaa, games: data.games })) + setNCAA(ncaa => ({ ...ncaa, sport: sport })) + setNCAA(ncaa => ({ ...ncaa, timestamp: Date.UTC() })) + setNCAA(ncaa => ({ ...ncaa, loadingGames: false })) } }) .catch(error => { - console.log(error); - setNCAA(ncaa => ({ ...ncaa, games: [] })); - setNCAA(ncaa => ({ ...ncaa, sport: 'none'})); - setNCAA(ncaa => ({ ...ncaa, loadingGames: false})); + console.log(error) + setNCAA(ncaa => ({ ...ncaa, games: [] })) + setNCAA(ncaa => ({ ...ncaa, sport: 'none' })); + setNCAA(ncaa => ({ ...ncaa, loadingGames: false })) }); } } From ef0c948687d4950f62198141bd70eaa0371702ca Mon Sep 17 00:00:00 2001 From: flynneva Date: Tue, 22 Dec 2020 20:00:13 -0800 Subject: [PATCH 06/12] fix more lint errors --- doczrc.js | 5 ++--- src/components/NCAA.js | 18 +++++++++--------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/doczrc.js b/doczrc.js index 05e58a3..fd3c09d 100644 --- a/doczrc.js +++ b/doczrc.js @@ -9,7 +9,7 @@ const proxyPlugin = () => proxy({ target: 'https://data.ncaa.com/', changeOrigin: true, - pathRewrite: {'^/ncaa_api/': '/' + pathRewrite: { '^/ncaa_api/': '/' } }) ) @@ -20,6 +20,5 @@ export default { dest: './docs/', base: './react-ncaa-data/', title: 'react-ncaa-data', - plugins: [ - proxyPlugin()] + plugins: [proxyPlugin()] } diff --git a/src/components/NCAA.js b/src/components/NCAA.js index 72de152..6c92442 100644 --- a/src/components/NCAA.js +++ b/src/components/NCAA.js @@ -8,10 +8,10 @@ var headers = { } function useNCAA() { - const [ncaa, setNCAA] = useContext(NCAAContext); + const [ncaa, setNCAA] = useContext(NCAAContext) function changeProxyApi(newProxy) { - setNCAA(ncaa => ({ ...ncaa, proxy_api: newProxy })); + setNCAA(ncaa => ({ ...ncaa, proxy_api: newProxy })) } function changeDate(date) { @@ -19,17 +19,17 @@ function useNCAA() { const tempMonth = ('0' + (date.getMonth() + 1)).slice(-2) const tempYear = date.getFullYear() - setNCAA(ncaa => ({ ...ncaa, day: tempDay })); - setNCAA(ncaa => ({ ...ncaa, month: tempMonth })); - setNCAA(ncaa => ({ ...ncaa, year: tempYear })); + setNCAA(ncaa => ({ ...ncaa, day: tempDay })) + setNCAA(ncaa => ({ ...ncaa, month: tempMonth })) + setNCAA(ncaa => ({ ...ncaa, year: tempYear })) } function getGames(sport) { var query = - '/' + ncaa.proxy_api + - '/' + ncaa.base_query + - '/scoreboard' + - '/' + sport + + '/' + ncaa.proxy_api + + '/' + ncaa.base_query + + '/scoreboard' + + '/' + sport + '/' + ncaa.division + '/' + ncaa.year + '/' + ncaa.month + From 7b62a6d216eb585121c8d651465658337835105f Mon Sep 17 00:00:00 2001 From: flynneva Date: Tue, 22 Dec 2020 20:30:04 -0800 Subject: [PATCH 07/12] more fixes --- doczrc.js | 3 +- src/components/NCAA.js | 64 +++++++++++++++++++++--------------------- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/doczrc.js b/doczrc.js index fd3c09d..e0d32c4 100644 --- a/doczrc.js +++ b/doczrc.js @@ -9,8 +9,7 @@ const proxyPlugin = () => proxy({ target: 'https://data.ncaa.com/', changeOrigin: true, - pathRewrite: { '^/ncaa_api/': '/' - } + pathRewrite: { '^/ncaa_api/': '/' } }) ) } diff --git a/src/components/NCAA.js b/src/components/NCAA.js index 6c92442..afd2244 100644 --- a/src/components/NCAA.js +++ b/src/components/NCAA.js @@ -11,7 +11,7 @@ function useNCAA() { const [ncaa, setNCAA] = useContext(NCAAContext) function changeProxyApi(newProxy) { - setNCAA(ncaa => ({ ...ncaa, proxy_api: newProxy })) + setNCAA((ncaa) => ({ ...ncaa, proxy_api: newProxy })) } function changeDate(date) { @@ -19,17 +19,17 @@ function useNCAA() { const tempMonth = ('0' + (date.getMonth() + 1)).slice(-2) const tempYear = date.getFullYear() - setNCAA(ncaa => ({ ...ncaa, day: tempDay })) - setNCAA(ncaa => ({ ...ncaa, month: tempMonth })) - setNCAA(ncaa => ({ ...ncaa, year: tempYear })) + setNCAA((ncaa) => ({ ...ncaa, day: tempDay })) + setNCAA((ncaa) => ({ ...ncaa, month: tempMonth })) + setNCAA((ncaa) => ({ ...ncaa, year: tempYear })) } function getGames(sport) { var query = - '/' + ncaa.proxy_api - + '/' + ncaa.base_query - + '/scoreboard' - + '/' + sport + + '/' + ncaa.proxy_api + + '/' + ncaa.base_query + + '/scoreboard' + + '/' + sport + '/' + ncaa.division + '/' + ncaa.year + '/' + ncaa.month + @@ -46,17 +46,17 @@ function useNCAA() { .then(response => response.json()) .then(data => { if (data.games.length !== 0) { - setNCAA(ncaa => ({ ...ncaa, games: data.games })) - setNCAA(ncaa => ({ ...ncaa, sport: sport })) - setNCAA(ncaa => ({ ...ncaa, timestamp: Date.UTC() })) - setNCAA(ncaa => ({ ...ncaa, loadingGames: false })) + setNCAA((ncaa) => ({ ...ncaa, games: data.games })) + setNCAA((ncaa) => ({ ...ncaa, sport: sport })) + setNCAA((ncaa) => ({ ...ncaa, timestamp: Date.UTC() })) + setNCAA((ncaa) => ({ ...ncaa, loadingGames: false })) } }) .catch(error => { console.log(error) - setNCAA(ncaa => ({ ...ncaa, games: [] })) - setNCAA(ncaa => ({ ...ncaa, sport: 'none' })); - setNCAA(ncaa => ({ ...ncaa, loadingGames: false })) + setNCAA((ncaa) => ({ ...ncaa, games: [] })) + setNCAA((ncaa) => ({ ...ncaa, sport: 'none' })); + setNCAA((ncaa) => ({ ...ncaa, loadingGames: false })) }); } } @@ -68,7 +68,7 @@ function useNCAA() { '/' + gameID + '/boxscore.json'; if(!ncaa.loadingBoxScore) { - setNCAA(ncaa => ({ ...ncaa, loadingBoxScore: true})); + setNCAA((ncaa) => ({ ...ncaa, loadingBoxScore: true})); fetch(query, { method: 'GET', headers: headers, @@ -76,12 +76,12 @@ function useNCAA() { }) .then(response => response.json()) .then(data => { - setNCAA(ncaa => ({ ...ncaa, boxscore: data})); - setNCAA(ncaa => ({ ...ncaa, gameID: gameID})); - setNCAA(ncaa => ({ ...ncaa, loadingBoxScore: false})); + setNCAA((ncaa) => ({ ...ncaa, boxscore: data})); + setNCAA((ncaa) => ({ ...ncaa, gameID: gameID})); + setNCAA((ncaa) => ({ ...ncaa, loadingBoxScore: false})); }) .catch(error => { - setNCAA(ncaa => ({ ...ncaa, loadingBoxScore: false})); + setNCAA((ncaa) => ({ ...ncaa, loadingBoxScore: false})); console.log(error); }) } @@ -94,7 +94,7 @@ function useNCAA() { '/' + gameID + '/gameInfo.json'; if(!ncaa.loadingGameInfo) { - setNCAA(ncaa => ({ ...ncaa, loadingGameInfo: true})); + setNCAA((ncaa) => ({ ...ncaa, loadingGameInfo: true})); fetch(query, { method: 'GET', headers: headers, @@ -102,12 +102,12 @@ function useNCAA() { }) .then(response => response.json()) .then(data => { - setNCAA(ncaa => ({ ...ncaa, gameInfo: data})); - setNCAA(ncaa => ({ ...ncaa, gameID: gameID})); - setNCAA(ncaa => ({ ...ncaa, loadingGameInfo: false})); + setNCAA((ncaa) => ({ ...ncaa, gameInfo: data})); + setNCAA((ncaa) => ({ ...ncaa, gameID: gameID})); + setNCAA((ncaa) => ({ ...ncaa, loadingGameInfo: false})); }) .catch(error => { - setNCAA(ncaa => ({ ...ncaa, loadingGameInfo: false})); + setNCAA((ncaa) => ({ ...ncaa, loadingGameInfo: false})); console.log(error); }) } @@ -120,7 +120,7 @@ function useNCAA() { '/' + gameID + '/pbp.json'; if(!ncaa.loadingPbp) { - setNCAA(ncaa => ({ ...ncaa, loadingPbp: true})); + setNCAA((ncaa) => ({ ...ncaa, loadingPbp: true})); fetch(query, { method: 'GET', headers: headers, @@ -128,12 +128,12 @@ function useNCAA() { }) .then(response => response.json()) .then(data => { - setNCAA(ncaa => ({ ...ncaa, pbp: data})); - setNCAA(ncaa => ({ ...ncaa, gameID: gameID})); - setNCAA(ncaa => ({ ...ncaa, loadingPbp: false})); + setNCAA((ncaa) => ({ ...ncaa, pbp: data})); + setNCAA((ncaa) => ({ ...ncaa, gameID: gameID})); + setNCAA((ncaa) => ({ ...ncaa, loadingPbp: false})); }) .catch(error => { - setNCAA(ncaa => ({ ...ncaa, loadingPbp: false})); + setNCAA((ncaa) => ({ ...ncaa, loadingPbp: false})); console.log(error); }) } @@ -141,9 +141,9 @@ function useNCAA() { function toggleGender() { if ( ncaa.gender == 'men' ) { - setNCAA(ncaa => ({ ...ncaa, gender: 'women'})); + setNCAA((ncaa) => ({ ...ncaa, gender: 'women'})); } else if (ncaa.gender == 'women') { - setNCAA(ncaa => ({ ...ncaa, gender: 'men'})); + setNCAA((ncaa) => ({ ...ncaa, gender: 'men'})); } } From fa27b60aa3a1e2adf9cd075ccd2df5c0567de3fe Mon Sep 17 00:00:00 2001 From: flynneva Date: Tue, 22 Dec 2020 20:39:33 -0800 Subject: [PATCH 08/12] more fixes --- src/components/NCAA.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/components/NCAA.js b/src/components/NCAA.js index afd2244..10fe68c 100644 --- a/src/components/NCAA.js +++ b/src/components/NCAA.js @@ -26,18 +26,25 @@ function useNCAA() { function getGames(sport) { var query = - '/' + ncaa.proxy_api + - '/' + ncaa.base_query + + '/' + + ncaa.proxy_api + + '/' + + ncaa.base_query + '/scoreboard' + - '/' + sport + - '/' + ncaa.division + - '/' + ncaa.year + - '/' + ncaa.month + - '/' + ncaa.day + + '/' + + sport + + '/' + + ncaa.division + + '/' + + ncaa.year + + '/' + + ncaa.month + + '/' + + ncaa.day + '/scoreboard.json' if(!ncaa.loadingGames) { - setNCAA(ncaa => ({ ...ncaa, loadingGames: true })) + setNCAA((ncaa) => ({ ...ncaa, loadingGames: true })) fetch(query, { method: 'GET', headers: headers, From ec707776f83c0ed470bd147ff095dcaf080a5e88 Mon Sep 17 00:00:00 2001 From: flynneva Date: Wed, 23 Dec 2020 16:16:01 -0800 Subject: [PATCH 09/12] eslint fixes --- .eslintrc | 3 ++- src/components/NCAA.js | 38 +++++++++++++++++++------------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/.eslintrc b/.eslintrc index 530000c..72a0fef 100644 --- a/.eslintrc +++ b/.eslintrc @@ -8,7 +8,8 @@ "prettier/react" ], "env": { - "node": true + "node": true, + "browser": true }, "parserOptions": { "ecmaVersion": 2020, diff --git a/src/components/NCAA.js b/src/components/NCAA.js index 10fe68c..be800d9 100644 --- a/src/components/NCAA.js +++ b/src/components/NCAA.js @@ -43,28 +43,28 @@ function useNCAA() { ncaa.day + '/scoreboard.json' - if(!ncaa.loadingGames) { - setNCAA((ncaa) => ({ ...ncaa, loadingGames: true })) + if (!ncaa.loadingGames) { + setNCAA((ncaa) => ({ ...ncaa, loadingGames: true })) fetch(query, { - method: 'GET', - headers: headers, - body: JSON.stringify() + method: 'GET', + headers: headers, + body: JSON.stringify() }) - .then(response => response.json()) - .then(data => { - if (data.games.length !== 0) { - setNCAA((ncaa) => ({ ...ncaa, games: data.games })) - setNCAA((ncaa) => ({ ...ncaa, sport: sport })) - setNCAA((ncaa) => ({ ...ncaa, timestamp: Date.UTC() })) + .then(response => response.json()) + .then(data => { + if (data.games.length !== 0) { + setNCAA((ncaa) => ({ ...ncaa, games: data.games })) + setNCAA((ncaa) => ({ ...ncaa, sport: sport })) + setNCAA((ncaa) => ({ ...ncaa, timestamp: Date.UTC() })) + setNCAA((ncaa) => ({ ...ncaa, loadingGames: false })) + } + }) + .catch(error => { + console.log(error) + setNCAA((ncaa) => ({ ...ncaa, games: [] })) + setNCAA((ncaa) => ({ ...ncaa, sport: 'none' })); setNCAA((ncaa) => ({ ...ncaa, loadingGames: false })) - } - }) - .catch(error => { - console.log(error) - setNCAA((ncaa) => ({ ...ncaa, games: [] })) - setNCAA((ncaa) => ({ ...ncaa, sport: 'none' })); - setNCAA((ncaa) => ({ ...ncaa, loadingGames: false })) - }); + }); } } From fe19057cfbc9e0a451cededd39f7423a32d24ff8 Mon Sep 17 00:00:00 2001 From: flynneva Date: Wed, 23 Dec 2020 16:26:39 -0800 Subject: [PATCH 10/12] more fixes --- src/components/NCAA.js | 114 ++++++++++++++++++++++------------------- 1 file changed, 62 insertions(+), 52 deletions(-) diff --git a/src/components/NCAA.js b/src/components/NCAA.js index be800d9..988b010 100644 --- a/src/components/NCAA.js +++ b/src/components/NCAA.js @@ -50,107 +50,117 @@ function useNCAA() { headers: headers, body: JSON.stringify() }) - .then(response => response.json()) - .then(data => { + .then((response) => response.json()) + .then((data) => { if (data.games.length !== 0) { setNCAA((ncaa) => ({ ...ncaa, games: data.games })) setNCAA((ncaa) => ({ ...ncaa, sport: sport })) setNCAA((ncaa) => ({ ...ncaa, timestamp: Date.UTC() })) - setNCAA((ncaa) => ({ ...ncaa, loadingGames: false })) - } + setNCAA((ncaa) => ({ ...ncaa, loadingGames: false })) + } }) - .catch(error => { + .catch((error) => { console.log(error) setNCAA((ncaa) => ({ ...ncaa, games: [] })) - setNCAA((ncaa) => ({ ...ncaa, sport: 'none' })); - setNCAA((ncaa) => ({ ...ncaa, loadingGames: false })) - }); + setNCAA((ncaa) => ({ ...ncaa, sport: 'none' })) + setNCAA((ncaa) => ({ ...ncaa, loadingGames: false })) + }) } } function getBoxScore(gameID) { - var query = '/' + ncaa.proxy_api + - '/' + ncaa.base_query + - '/game' + - '/' + gameID + - '/boxscore.json'; + var query = + '/' + + ncaa.proxy_api + + '/' + ncaa.base_query + + '/game' + + '/' + gameID + + '/boxscore.json' if(!ncaa.loadingBoxScore) { - setNCAA((ncaa) => ({ ...ncaa, loadingBoxScore: true})); + setNCAA((ncaa) => ({ ...ncaa, loadingBoxScore: true})) fetch(query, { method: 'GET', headers: headers, body: JSON.stringify() }) - .then(response => response.json()) - .then(data => { - setNCAA((ncaa) => ({ ...ncaa, boxscore: data})); - setNCAA((ncaa) => ({ ...ncaa, gameID: gameID})); - setNCAA((ncaa) => ({ ...ncaa, loadingBoxScore: false})); + .then((response) => response.json()) + .then((data) => { + setNCAA((ncaa) => ({ ...ncaa, boxscore: data})) + setNCAA((ncaa) => ({ ...ncaa, gameID: gameID})) + setNCAA((ncaa) => ({ ...ncaa, loadingBoxScore: false})) }) - .catch(error => { - setNCAA((ncaa) => ({ ...ncaa, loadingBoxScore: false})); - console.log(error); + .catch((error) => { + setNCAA((ncaa) => ({ ...ncaa, loadingBoxScore: false})) + console.log(error) }) } } function getGameInfo(gameID) { - var query = '/' + ncaa.proxy_api + - '/' + ncaa.base_query + - '/game' + - '/' + gameID + - '/gameInfo.json'; + var query = + '/' + + ncaa.proxy_api + + '/' + + ncaa.base_query + + '/game' + + '/' + + gameID + + '/gameInfo.json' if(!ncaa.loadingGameInfo) { - setNCAA((ncaa) => ({ ...ncaa, loadingGameInfo: true})); + setNCAA((ncaa) => ({ ...ncaa, loadingGameInfo: true})) fetch(query, { method: 'GET', headers: headers, body: JSON.stringify() }) - .then(response => response.json()) - .then(data => { - setNCAA((ncaa) => ({ ...ncaa, gameInfo: data})); - setNCAA((ncaa) => ({ ...ncaa, gameID: gameID})); - setNCAA((ncaa) => ({ ...ncaa, loadingGameInfo: false})); + .then((response) => response.json()) + .then((data) => { + setNCAA((ncaa) => ({ ...ncaa, gameInfo: data})) + setNCAA((ncaa) => ({ ...ncaa, gameID: gameID})) + setNCAA((ncaa) => ({ ...ncaa, loadingGameInfo: false})) }) - .catch(error => { - setNCAA((ncaa) => ({ ...ncaa, loadingGameInfo: false})); - console.log(error); + .catch((error) => { + setNCAA((ncaa) => ({ ...ncaa, loadingGameInfo: false})) + console.log(error) }) } } function getPbP(gameID) { - var query = '/' + ncaa.proxy_api + - '/' + ncaa.base_query + - '/game' + - '/' + gameID + - '/pbp.json'; + var query = + '/' + + ncaa.proxy_api + + '/' + + ncaa.base_query + + '/game' + + '/' + + gameID + + '/pbp.json' if(!ncaa.loadingPbp) { - setNCAA((ncaa) => ({ ...ncaa, loadingPbp: true})); + setNCAA((ncaa) => ({ ...ncaa, loadingPbp: true})) fetch(query, { method: 'GET', headers: headers, body: JSON.stringify() }) - .then(response => response.json()) - .then(data => { - setNCAA((ncaa) => ({ ...ncaa, pbp: data})); - setNCAA((ncaa) => ({ ...ncaa, gameID: gameID})); - setNCAA((ncaa) => ({ ...ncaa, loadingPbp: false})); + .then((response) => response.json()) + .then((data) => { + setNCAA((ncaa) => ({ ...ncaa, pbp: data})) + setNCAA((ncaa) => ({ ...ncaa, gameID: gameID})) + setNCAA((ncaa) => ({ ...ncaa, loadingPbp: false})) }) - .catch(error => { - setNCAA((ncaa) => ({ ...ncaa, loadingPbp: false})); - console.log(error); + .catch((error) => { + setNCAA((ncaa) => ({ ...ncaa, loadingPbp: false})) + console.log(error }) } } function toggleGender() { if ( ncaa.gender == 'men' ) { - setNCAA((ncaa) => ({ ...ncaa, gender: 'women'})); + setNCAA((ncaa) => ({ ...ncaa, gender: 'women'})) } else if (ncaa.gender == 'women') { - setNCAA((ncaa) => ({ ...ncaa, gender: 'men'})); + setNCAA((ncaa) => ({ ...ncaa, gender: 'men'})) } } From d5c10a41df3124b0126b3ad081f84a8c8514043e Mon Sep 17 00:00:00 2001 From: flynneva Date: Wed, 23 Dec 2020 16:28:46 -0800 Subject: [PATCH 11/12] whoops --- src/components/NCAA.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/NCAA.js b/src/components/NCAA.js index 988b010..4da5223 100644 --- a/src/components/NCAA.js +++ b/src/components/NCAA.js @@ -151,7 +151,7 @@ function useNCAA() { }) .catch((error) => { setNCAA((ncaa) => ({ ...ncaa, loadingPbp: false})) - console.log(error + console.log(error) }) } } From 13080881b46325ce0b9c09125189f582397acf05 Mon Sep 17 00:00:00 2001 From: flynneva Date: Wed, 23 Dec 2020 18:16:30 -0800 Subject: [PATCH 12/12] fix lint errors --- src/components/NCAA.js | 116 ++++++++++++------------ src/components/NCAAContext.js | 15 ++- src/components/examples/ShowBoxScore.js | 39 ++++---- src/components/examples/ShowGames.js | 85 +++++++++++------ src/index.js | 2 +- 5 files changed, 144 insertions(+), 113 deletions(-) diff --git a/src/components/NCAA.js b/src/components/NCAA.js index 4da5223..34701d6 100644 --- a/src/components/NCAA.js +++ b/src/components/NCAA.js @@ -72,27 +72,29 @@ function useNCAA() { var query = '/' + ncaa.proxy_api + - '/' + ncaa.base_query + + '/' + + ncaa.base_query + '/game' + - '/' + gameID + + '/' + + gameID + '/boxscore.json' - if(!ncaa.loadingBoxScore) { - setNCAA((ncaa) => ({ ...ncaa, loadingBoxScore: true})) + if (!ncaa.loadingBoxScore) { + setNCAA((ncaa) => ({ ...ncaa, loadingBoxScore: true })) fetch(query, { - method: 'GET', - headers: headers, - body: JSON.stringify() - }) - .then((response) => response.json()) - .then((data) => { - setNCAA((ncaa) => ({ ...ncaa, boxscore: data})) - setNCAA((ncaa) => ({ ...ncaa, gameID: gameID})) - setNCAA((ncaa) => ({ ...ncaa, loadingBoxScore: false})) - }) - .catch((error) => { - setNCAA((ncaa) => ({ ...ncaa, loadingBoxScore: false})) - console.log(error) + method: 'GET', + headers: headers, + body: JSON.stringify() }) + .then((response) => response.json()) + .then((data) => { + setNCAA((ncaa) => ({ ...ncaa, boxscore: data })) + setNCAA((ncaa) => ({ ...ncaa, gameID: gameID })) + setNCAA((ncaa) => ({ ...ncaa, loadingBoxScore: false })) + }) + .catch((error) => { + setNCAA((ncaa) => ({ ...ncaa, loadingBoxScore: false })) + console.log(error) + }) } } @@ -106,23 +108,23 @@ function useNCAA() { '/' + gameID + '/gameInfo.json' - if(!ncaa.loadingGameInfo) { - setNCAA((ncaa) => ({ ...ncaa, loadingGameInfo: true})) + if (!ncaa.loadingGameInfo) { + setNCAA((ncaa) => ({ ...ncaa, loadingGameInfo: true })) fetch(query, { - method: 'GET', - headers: headers, - body: JSON.stringify() - }) - .then((response) => response.json()) - .then((data) => { - setNCAA((ncaa) => ({ ...ncaa, gameInfo: data})) - setNCAA((ncaa) => ({ ...ncaa, gameID: gameID})) - setNCAA((ncaa) => ({ ...ncaa, loadingGameInfo: false})) - }) - .catch((error) => { - setNCAA((ncaa) => ({ ...ncaa, loadingGameInfo: false})) - console.log(error) + method: 'GET', + headers: headers, + body: JSON.stringify() }) + .then((response) => response.json()) + .then((data) => { + setNCAA((ncaa) => ({ ...ncaa, gameInfo: data })) + setNCAA((ncaa) => ({ ...ncaa, gameID: gameID })) + setNCAA((ncaa) => ({ ...ncaa, loadingGameInfo: false })) + }) + .catch((error) => { + setNCAA((ncaa) => ({ ...ncaa, loadingGameInfo: false })) + console.log(error) + }) } } @@ -136,31 +138,31 @@ function useNCAA() { '/' + gameID + '/pbp.json' - if(!ncaa.loadingPbp) { - setNCAA((ncaa) => ({ ...ncaa, loadingPbp: true})) + if (!ncaa.loadingPbp) { + setNCAA((ncaa) => ({ ...ncaa, loadingPbp: true })) fetch(query, { - method: 'GET', - headers: headers, - body: JSON.stringify() - }) - .then((response) => response.json()) - .then((data) => { - setNCAA((ncaa) => ({ ...ncaa, pbp: data})) - setNCAA((ncaa) => ({ ...ncaa, gameID: gameID})) - setNCAA((ncaa) => ({ ...ncaa, loadingPbp: false})) - }) - .catch((error) => { - setNCAA((ncaa) => ({ ...ncaa, loadingPbp: false})) - console.log(error) + method: 'GET', + headers: headers, + body: JSON.stringify() }) + .then((response) => response.json()) + .then((data) => { + setNCAA((ncaa) => ({ ...ncaa, pbp: data })) + setNCAA((ncaa) => ({ ...ncaa, gameID: gameID })) + setNCAA((ncaa) => ({ ...ncaa, loadingPbp: false })) + }) + .catch((error) => { + setNCAA((ncaa) => ({ ...ncaa, loadingPbp: false })) + console.log(error) + }) } } function toggleGender() { - if ( ncaa.gender == 'men' ) { - setNCAA((ncaa) => ({ ...ncaa, gender: 'women'})) - } else if (ncaa.gender == 'women') { - setNCAA((ncaa) => ({ ...ncaa, gender: 'men'})) + if (ncaa.gender === 'men') { + setNCAA((ncaa) => ({ ...ncaa, gender: 'women' })) + } else if (ncaa.gender === 'women') { + setNCAA((ncaa) => ({ ...ncaa, gender: 'men' })) } } @@ -187,20 +189,16 @@ function useNCAA() { timestamp: ncaa.timestamp, day: ncaa.day, month: ncaa.month, - year: ncaa.year, + year: ncaa.year } } function NCAA(props) { - return ( - - {props.children} - - ); + return {props.children} } NCAA.propTypes = { - children: PropTypes.node.isRequired, + children: PropTypes.node.isRequired } -export { useNCAA, NCAA }; +export { useNCAA, NCAA } diff --git a/src/components/NCAAContext.js b/src/components/NCAAContext.js index 25f679d..b41c7d7 100644 --- a/src/components/NCAAContext.js +++ b/src/components/NCAAContext.js @@ -1,7 +1,7 @@ import React, { createContext, useState } from 'react' import PropTypes from 'prop-types' -const today = new Date(); +const today = new Date() const ncaaObj = { proxy_api: 'ncaa_api', @@ -21,23 +21,22 @@ const ncaaObj = { loadingPbp: false, gameInfo: [], boxscore: [], - pbp: [], + pbp: [] } -const NCAAContext = createContext([{}, () => {}]); +const NCAAContext = createContext([{}, () => {}]) const NCAAProvider = (props) => { - const [ ncaa, setNCAA ] = useState(ncaaObj); + const [ncaa, setNCAA] = useState(ncaaObj) return ( {props.children} - ); + ) } NCAAProvider.propTypes = { - children: PropTypes.node.isRequired, + children: PropTypes.node.isRequired } -export { NCAAContext, NCAAProvider }; - +export { NCAAContext, NCAAProvider } diff --git a/src/components/examples/ShowBoxScore.js b/src/components/examples/ShowBoxScore.js index 0c03239..e56cdcd 100644 --- a/src/components/examples/ShowBoxScore.js +++ b/src/components/examples/ShowBoxScore.js @@ -1,40 +1,43 @@ -import React, { useEffect } from 'react' +import React from 'react' import { useNCAA } from '../NCAA' -const gameID = '3912213'; - -const date = new Date(); +const gameID = '3912213' function ShowBoxScore() { - const { getBoxScore, boxscore, loadingBoxScore } = useNCAA(); + const { getBoxScore, boxscore, loadingBoxScore } = useNCAA() const handleBoxScore = () => { - getBoxScore(gameID); + getBoxScore(gameID) } - let gameTitle; + let gameTitle if (typeof boxscore === 'undefined' || boxscore.length === 0) { gameTitle = Click refresh to get game data for game ID 3912213 } else { - gameTitle = {boxscore.meta['description']} + gameTitle = {boxscore.meta.description} } - - let score_viz = []; - if (typeof boxscore === 'undefined' || boxscore.length === 0 || loadingBoxScore) { - score_viz =

No score to report

+ + let scoreViz = [] + if ( + typeof boxscore === 'undefined' || + boxscore.length === 0 || + loadingBoxScore + ) { + scoreViz =

No score to report

} else { - console.log(boxscore); - score_viz =

Boxscore printed to console!

+ console.log(boxscore) + scoreViz =

Boxscore printed to console!

} return (
-
+ +

{gameTitle} - {score_viz} + {scoreViz}
- ); + ) } -export default ShowBoxScore; +export default ShowBoxScore diff --git a/src/components/examples/ShowGames.js b/src/components/examples/ShowGames.js index cd4879b..c79b1e9 100644 --- a/src/components/examples/ShowGames.js +++ b/src/components/examples/ShowGames.js @@ -1,50 +1,81 @@ -import React, { useEffect } from 'react' +import React from 'react' import { useNCAA } from '../NCAA' -const date = new Date(); +const date = new Date() function ShowGames() { - const { day, month, year, changeDate, games, getGames, sport, gender } = useNCAA(); + const { day, month, year, changeDate, games, getGames } = useNCAA() const handleGames = () => { - getGames('basketball-men'); + getGames('basketball-men') } - const handleDay = (new_day) => { - if (new_day == 0) { - new_day = 1; + const handleDay = (newDay) => { + if (newDay === 0) { + newDay = 1 } - date.setDate(new_day); - changeDate(date); + date.setDate(newDay) + changeDate(date) } - const handleMonth = (new_month) => { - if(new_month <= 0) { - new_month = 0; + const handleMonth = (newMonth) => { + if (newMonth <= 0) { + newMonth = 0 } - date.setMonth(new_month); - changeDate(date); + date.setMonth(newMonth) + changeDate(date) } - const handleYear = (new_year) => { - if (new_year == 0) { - new_year = 2020; + const handleYear = (newYear) => { + if (newYear === 0) { + newYear = 2020 } - date.setFullYear(new_year); - changeDate(date); + date.setFullYear(newYear) + changeDate(date) } return (
- Day: {handleDay(event.target.value)}}/>
- Month: {handleMonth(event.target.value - 1)}}/>
- Year: {handleYear(event.target.value)}}/>
-
+ Day: + { + handleDay(event.target.value) + }} + />
- Number of games on {day}-{month}-{year}: {games.length}
- { games.map((game, i) =>
  • {game.game.title}
  • ) } + Month: + { + handleMonth(event.target.value - 1) + }} + /> +
    + Year: + { + handleYear(event.target.value) + }} + /> +
    + +
    +
    + + Number of games on {day}-{month}-{year}: + + {games.length} +
    + {games.map((game, i) => ( +
  • {game.game.title}
  • + ))}
    - ); + ) } -export default ShowGames; +export default ShowGames diff --git a/src/index.js b/src/index.js index 78c2a65..e587322 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,3 @@ import { NCAA, useNCAA } from './components/NCAA' -export { NCAA, useNCAA }; +export { NCAA, useNCAA }