Skip to content

Commit

Permalink
Merge pull request #1 from flynneva/devel
Browse files Browse the repository at this point in the history
switch gh actions, add more error handling
  • Loading branch information
flynneva authored Dec 21, 2020
2 parents 0972b64 + 495c907 commit 3c1a295
Show file tree
Hide file tree
Showing 7 changed files with 9,563 additions and 4,888 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: build

on:
push:
branches-ignore:
- master

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [8.x, 10.x, 12.x]
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm run build --if-present
#- run: npm test
4 changes: 0 additions & 4 deletions .travis.yml

This file was deleted.

14,279 changes: 9,449 additions & 4,830 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-ncaa-data",
"version": "0.0.15",
"version": "0.0.18",
"description": "Put live (or old) NCAA data in your website!",
"author": "flynneva",
"license": "MIT",
Expand Down
135 changes: 84 additions & 51 deletions src/components/NCAA.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import React, { useContext } from 'react'
import { NCAAContext, NCAAProvider } from './NCAAContext'
import PropTypes from 'prop-types'

var headers = {
'pragma': 'no-cache',
'cache-control': 'no-cache'
}

function useNCAA() {
const [ ncaa, setNCAA ] = useContext(NCAAContext);

Expand Down Expand Up @@ -29,23 +34,29 @@ function useNCAA() {
'/' + ncaa.month +
'/' + ncaa.day +
'/scoreboard.json';
fetch(query, {
method: 'GET',
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()}));
}
})
.catch(error => {
console.log(error);
setNCAA(ncaa => ({ ...ncaa, games: [] }));
setNCAA(ncaa => ({ ...ncaa, sport: 'none'}));
});
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}));
}
})
.catch(error => {
console.log(error);
setNCAA(ncaa => ({ ...ncaa, games: [] }));
setNCAA(ncaa => ({ ...ncaa, sport: 'none'}));
setNCAA(ncaa => ({ ...ncaa, loadingGames: false}));
});
}
}

function getBoxScore(gameID) {
Expand All @@ -54,18 +65,24 @@ function useNCAA() {
'/game' +
'/' + gameID +
'/boxscore.json';
fetch(query, {
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}));
})
.catch(error => {
console.log(error);
})
})
.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) {
Expand All @@ -74,18 +91,24 @@ function useNCAA() {
'/game' +
'/' + gameID +
'/gameInfo.json';
fetch(query, {
method: 'GET',
body: JSON.stringify()
})
.then(response => response.json())
.then(data => {
setNCAA(ncaa => ({ ...ncaa, gameInfo: data}));
setNCAA(ncaa => ({ ...ncaa, gameID: gameID}));
})
.catch(error => {
console.log(error);
})
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);
})
}
}

function getPbP(gameID) {
Expand All @@ -94,18 +117,24 @@ function useNCAA() {
'/game' +
'/' + gameID +
'/pbp.json';
fetch(query, {
method: 'GET',
body: JSON.stringify()
})
.then(response => response.json())
.then(data => {
setNCAA(ncaa => ({ ...ncaa, pbp: data}));
setNCAA(ncaa => ({ ...ncaa, gameID: gameID}));
})
.catch(error => {
console.log(error);
})
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);
})
}
}

function toggleGender() {
Expand All @@ -131,6 +160,10 @@ function useNCAA() {
gameInfo: ncaa.gameInfo,
boxscore: ncaa.boxscore,
pbp: ncaa.pbp,
loadingGames: ncaa.loadingGames,
loadingGameInfo: ncaa.loadingGameInfo,
loadingBoxScore: ncaa.loadingBoxScore,
loadingPbp: ncaa.loadingPbp,
proxy_api: ncaa.proxy_api,
timestamp: ncaa.timestamp,
day: ncaa.day,
Expand Down
4 changes: 4 additions & 0 deletions src/components/NCAAContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ const ncaaObj = {
sport: 'none',
games: [],
gameID: '0000000',
loadingGames: false,
loadingGameInfo: false,
loadingBoxScore: false,
loadingPbp: false,
gameInfo: [],
boxscore: [],
pbp: [],
Expand Down
4 changes: 2 additions & 2 deletions src/components/examples/ShowBoxScore.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const gameID = '3912213';
const date = new Date();

function ShowBoxScore() {
const { getBoxScore, boxscore } = useNCAA();
const { getBoxScore, boxscore, loadingBoxScore } = useNCAA();

const handleBoxScore = () => {
getBoxScore(gameID);
Expand All @@ -20,7 +20,7 @@ function ShowBoxScore() {
}

let score_viz = [];
if (typeof boxscore === 'undefined' || boxscore.length === 0) {
if (typeof boxscore === 'undefined' || boxscore.length === 0 || loadingBoxScore) {
score_viz = <p>No score to report</p>
} else {
console.log(boxscore);
Expand Down

0 comments on commit 3c1a295

Please sign in to comment.