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/.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 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: "" diff --git a/doczrc.js b/doczrc.js index a103322..e0d32c4 100644 --- a/doczrc.js +++ b/doczrc.js @@ -1,24 +1,23 @@ -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/', 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 2e562ec..34701d6 100644 --- a/src/components/NCAA.js +++ b/src/components/NCAA.js @@ -3,145 +3,166 @@ 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'; - if(!ncaa.loadingGames) { - setNCAA(ncaa => ({ ...ncaa, loadingGames: true})); + 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 })) fetch(query, { - 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()})); - setNCAA(ncaa => ({ ...ncaa, loadingGames: false})); - } + method: 'GET', + headers: headers, + body: JSON.stringify() }) - .catch(error => { - console.log(error); - setNCAA(ncaa => ({ ...ncaa, games: [] })); - setNCAA(ncaa => ({ ...ncaa, sport: 'none'})); - setNCAA(ncaa => ({ ...ncaa, loadingGames: false})); - }); + .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 })) + }) } } function getBoxScore(gameID) { - var query = '/' + ncaa.proxy_api + - '/' + ncaa.base_query + - '/game' + - '/' + gameID + - '/boxscore.json'; - if(!ncaa.loadingBoxScore) { - setNCAA(ncaa => ({ ...ncaa, loadingBoxScore: true})); + var query = + '/' + + ncaa.proxy_api + + '/' + + ncaa.base_query + + '/game' + + '/' + + gameID + + '/boxscore.json' + 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) + }) } } function getGameInfo(gameID) { - var query = '/' + ncaa.proxy_api + - '/' + ncaa.base_query + - '/game' + - '/' + gameID + - '/gameInfo.json'; - if(!ncaa.loadingGameInfo) { - setNCAA(ncaa => ({ ...ncaa, loadingGameInfo: true})); + var query = + '/' + + ncaa.proxy_api + + '/' + + ncaa.base_query + + '/game' + + '/' + + gameID + + '/gameInfo.json' + 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) + }) } } function getPbP(gameID) { - var query = '/' + ncaa.proxy_api + - '/' + ncaa.base_query + - '/game' + - '/' + gameID + - '/pbp.json'; - if(!ncaa.loadingPbp) { - setNCAA(ncaa => ({ ...ncaa, loadingPbp: true})); + var query = + '/' + + ncaa.proxy_api + + '/' + + ncaa.base_query + + '/game' + + '/' + + gameID + + '/pbp.json' + 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' })) } } @@ -168,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 } 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() - }) -})