re-add react-frontend
continuous-integration/drone/push Build is failing Details

Signed-off-by: Martyn Ranyard <m@rtyn.berlin>
This commit is contained in:
Martyn 2020-08-01 11:48:56 +02:00
parent 982d9bc535
commit 3f6d1e20ce
28 changed files with 25179 additions and 0 deletions

23
build/react-frontend/.gitignore vendored Normal file
View File

@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*

View File

@ -0,0 +1,68 @@
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
## Available Scripts
In the project directory, you can run:
### `npm start`
Runs the app in the development mode.<br />
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
The page will reload if you make edits.<br />
You will also see any lint errors in the console.
### `npm test`
Launches the test runner in the interactive watch mode.<br />
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
### `npm run build`
Builds the app for production to the `build` folder.<br />
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.<br />
Your app is ready to be deployed!
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
### `npm run eject`
**Note: this is a one-way operation. Once you `eject`, you cant go back!**
If you arent satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point youre on your own.
You dont have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldnt feel obligated to use this feature. However we understand that this tool wouldnt be useful if you couldnt customize it when you are ready for it.
## Learn More
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
To learn React, check out the [React documentation](https://reactjs.org/).
### Code Splitting
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
### Analyzing the Bundle Size
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
### Making a Progressive Web App
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
### Advanced Configuration
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
### Deployment
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
### `npm run build` fails to minify
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify

14100
build/react-frontend/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,37 @@
{
"name": "twitchsingstools-frontend",
"version": "0.1.0",
"private": true,
"dependencies": {
"@material-ui/core": "^4.11.0",
"@material-ui/icons": "^4.9.1",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.1",
"axios": "^0.19.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Tools for Twitch Sings provided by iMartynOnTwitch"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>TwitchSingsTools</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

View File

@ -0,0 +1,25 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
},
{
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
],
"start_url": ".",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}

View File

@ -0,0 +1,3 @@
# https://www.robotstxt.org/robotstxt.html
User-agent: *
Disallow:

View File

@ -0,0 +1,27 @@
.App {
text-align: center;
}
.App-logo {
height: 20vmin;
pointer-events: none;
}
.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}
.App-link {
color: #61dafb;
}
.App-menu {
max-width: 98%;
}

View File

@ -0,0 +1,52 @@
import React from 'react';
import logo from './../../logo.svg';
import './App.css';
import Container from '@material-ui/core/Container';
import Typography from '@material-ui/core/Typography';
import { Button, Paper } from '@material-ui/core';
function App() {
const client_id = "sau3e70wvs369jw1u25ex8g3cve599"
const redirect_uri = "https://" + encodeURI(window.location.href.split("/")[2]) + "/twitchadmin"
const twitchURL = "https://id.twitch.tv/oauth2/authorize?client_id="+ client_id +"&redirect_uri="+ redirect_uri +"&response_type=code&scope=user:read:broadcast"
return (
<Container className="App">
<Paper>
<img src={logo} className="App-logo" alt="logo" />
<Typography variant="h4" component="h1" gutterBottom>
Twitch Sings Tools
</Typography>
<Button variant="contained" color="primary" href={twitchURL}>
Log in with Twitch
</Button>
<Typography variant="h5" component="h2" gutterBottom>
Data about Twitch Sings <b>published</b> performances
</Typography>
<Typography component="p" gutterBottom>
This set of tools uses the standard twitch APIs to create a list of songs you have sung and singers you have sung with. <i>Note</i>: If twitch sings ever changes how they name published performances, this may get harder to do.
</Typography>
<Typography variant="h5" component="h2" gutterBottom>
Some insights
</Typography>
<Typography component="p" gutterBottom>
There's a "top 10 people you sing with" and a "top 10 songs you sing". There's actually not that much insight that can be drawn other than those without getting people involved :-)
</Typography>
<Typography variant="h5" component="h2" gutterBottom>
CSV Export!
</Typography>
<Typography component="p" gutterBottom>
You can bring the data into Excel, Google Sheets, Libre/OpenOffice, Lotus 1-2-3 or whatever, and analyse/graph to your hearts content!
</Typography>
<Typography variant="h5" component="h2" gutterBottom>
Chatbot
</Typography>
<Typography component="p" gutterBottom>
...Coming "Soon"(tm)
</Typography>
</Paper>
</Container>
);
}
export default App;

View File

@ -0,0 +1,9 @@
import React from 'react';
import { render } from '@testing-library/react';
import App from './App';
test('renders learn react link', () => {
const { getByText } = render(<App />);
const linkElement = getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});

View File

@ -0,0 +1,28 @@
.App {
text-align: center;
}
.App-logo {
pointer-events: none;
max-width: 20vmin;
max-height: 9vmin;
}
.App-header {
background-color: #282c34;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-evenly;
font-size: calc(10px + 2vmin);
color: white;
}
.App-link {
color: #61dafb;
}
.App-menu {
max-width: 98%;
}

View File

@ -0,0 +1,121 @@
import React from 'react';
import logo from './../../logo-small.svg';
import './AppAdmin.css';
import { Paper, Container, AppBar, Tabs, Tab, Box } from '@material-ui/core';
import PropTypes from 'prop-types';
import Typography from '@material-ui/core/Typography';
import TopTenSongs from "../TopTenSongs/TopTenSongs";
import TopTenSingers from "../TopTenSingers/TopTenSingers";
import DuetData from "../DuetData/DuetData";
import { Table, TableBody, TableCell, TableContainer, TableHead, TableRow } from '@material-ui/core';
import ProblemContainer from "../ProblemContainer/ProblemContainer";
function TabPanel(props) {
const { children, value, index, ...other } = props;
return (
<Typography
component="div"
role="tabpanel"
hidden={value !== index}
id={`vertical-tabpanel-${index}`}
aria-labelledby={`vertical-tab-${index}`}
{...other}
>
<Box p={3}>{children}</Box>
</Typography>
);
}
TabPanel.propTypes = {
children: PropTypes.node,
index: PropTypes.any.isRequired,
value: PropTypes.any.isRequired
};
function a11yProps(index) {
return {
id: `tab-${index}`,
"aria-controls": `tabpanel-${index}`
};
}
function AppAdmin() {
const [page, setPage] = React.useState(0);
if (
(window.location.href.split("/").length < 6) ||
(window.location.href.split("/")[3].search(/^admin/) < 0) ||
(window.location.href.split("/")[5].length != 48)
) {
return (
<ProblemContainer />
)
}
const channelName = window.location.href.split("/")[4]
const adminToken = window.location.href.split("/")[5]
const csvURL = "/csv/"+ channelName + "/" + adminToken
const tsvURL = "/tsv/"+ channelName + "/" + adminToken
function handleChange(event, newValue) {
setPage(newValue);
}
return (
<Container className="App">
<Paper>
<img src={logo} className="App-logo" alt="logo" />
<Typography variant="h4" component="h1" gutterBottom>
Twitch Sings Tools
</Typography>
<AppBar position="static" className="App-menu">
<Tabs value={page} onChange={handleChange} aria-label="simple tabs example">
<Tab label="Top Songs" {...a11yProps(0)}/>
<Tab label="Top Singers" {...a11yProps(1)}/>
<Tab label="Data" {...a11yProps(2)}/>
<Tab label="Export" {...a11yProps(3)}/>
</Tabs>
</AppBar>
<TabPanel value={page} index={0}>
<TopTenSongs />
</TabPanel>
<TabPanel value={page} index={1}>
<TopTenSingers />
</TabPanel>
<TabPanel value={page} index={2}>
<DuetData />
</TabPanel>
<TabPanel value={page} index={3}>
<Typography variant="h5" component="h2" gutterBottom>
Download your data as :
</Typography>
<TableContainer component={Paper}>
<Table>
<TableHead>
<TableRow>
<TableCell>TSV</TableCell>
<TableCell>CSV</TableCell>
</TableRow>
</TableHead>
<TableBody>
<TableRow>
<TableCell><a href={tsvURL}>here</a></TableCell>
<TableCell><a href={csvURL}>here</a></TableCell>
</TableRow>
</TableBody>
</Table>
</TableContainer>
<Typography variant="h5" component="h2" gutterBottom>
Note: Excel is not very good at handling CSV format it seems...
</Typography>
<Typography component="p" gutterBottom>It is important to "Import Data" not "Open" the csv in many cases (8 year old discussion of this behaviour <a href="https://superuser.com/questions/407082/easiest-way-to-open-csv-with-commas-in-excel">here</a>) - from that post the instructions are :</Typography>
<Typography component="q" gutterBottom>In Excel, DATA tab, in the Get External Data subsection, click "From Text" and import your CSV in the Wizard.</Typography>
<Typography component="p" gutterBottom>LibreOffice calc kinda just works...just sayin' ;-)</Typography>
</TabPanel>
</Paper>
</Container>
);
}
export default AppAdmin;

View File

@ -0,0 +1,168 @@
import React, { useEffect } from 'react';
import { makeStyles } from '@material-ui/core/styles';
import { Table, TableBody, TableCell, TableContainer, TableHead, TableRow, TableSortLabel, Paper } from '@material-ui/core';
import PropTypes from 'prop-types';
const channelName = window.location.href.split("/")[4]
const adminToken = window.location.href.split("/")[5]
const dataURL = "/json/"+ channelName + "/" + adminToken
const headCells = [
{ id: 'displayPublishDate', numeric: false, disablePadding: true, label: 'Published' },
{ id: 'songName', numeric: false, disablePadding: false, label: 'Song' },
{ id: 'singerName', numeric: false, disablePadding: false, label: 'Singer' },
{ id: 'displayLastSongDate', numeric: false, disablePadding: false, label: 'Last Sang Song' },
{ id: 'displayLastDuetDate', numeric: false, disablePadding: false, label: 'Last Dueted with Singer' },
];
function descendingComparator(a, b, orderBy) {
if (orderBy == "displayPublishDate") {
orderBy = "publishDate"
}
if (orderBy == "displayLastSongDate") {
orderBy = "lastSongDate"
}
if (orderBy == "displayLastDuetDate") {
orderBy = "lastDuetDate"
}
if (b[orderBy] < a[orderBy]) {
return -1;
}
if (b[orderBy] > a[orderBy]) {
return 1;
}
return 0;
}
function stableSort(array, comparator) {
const stabilizedThis = array.map((el, index) => [el, index]);
stabilizedThis.sort((a, b) => {
const order = comparator(a[0], b[0]);
if (order !== 0) return order;
return a[1] - b[1];
});
return stabilizedThis.map((el) => el[0]);
}
function getComparator(order, orderBy) {
return order === 'desc'
? (a, b) => descendingComparator(a, b, orderBy)
: (a, b) => -descendingComparator(a, b, orderBy);
}
function EnhancedTableHead(props) {
const { classes, order, orderBy, onRequestSort } = props;
const createSortHandler = (property) => (event) => {
onRequestSort(event, property);
};
return (
<TableHead>
<TableRow>
{headCells.map((headCell) => (
<TableCell
key={headCell.id}
align={headCell.numeric ? 'right' : 'left'}
padding={headCell.disablePadding ? 'none' : 'default'}
sortDirection={orderBy === headCell.id ? order : false}
>
<TableSortLabel
active={orderBy === headCell.id}
direction={orderBy === headCell.id ? order : 'asc'}
onClick={createSortHandler(headCell.id)}
>
{headCell.label}
{orderBy === headCell.id ? (
<span className={classes.visuallyHidden}>
{order === 'desc' ? 'sorted descending' : 'sorted ascending'}
</span>
) : null}
</TableSortLabel>
</TableCell>
))}
</TableRow>
</TableHead>
);
}
EnhancedTableHead.propTypes = {
classes: PropTypes.object.isRequired,
numSelected: PropTypes.number.isRequired,
onRequestSort: PropTypes.func.isRequired,
onSelectAllClick: PropTypes.func.isRequired,
order: PropTypes.oneOf(['asc', 'desc']).isRequired,
orderBy: PropTypes.string.isRequired,
rowCount: PropTypes.number.isRequired,
};
function DuetData() {
const useStyles = makeStyles({
table: {
minWidth: 650,
},
});
const [order, setOrder] = React.useState('asc');
const [orderBy, setOrderBy] = React.useState('calories');
const [duetState, setDuetState] = React.useState({loading: true, duetData: []})
const classes = useStyles();
useEffect(() => {
// We should only fetch once!
if (duetState.loading) {
fetch(dataURL).then((res) => res.json().then((data)=>{
setDuetState({duetData: data, loading: false })
}));
}
}, [setDuetState]);
const handleRequestSort = (event, property) => {
const isAsc = orderBy === property && order === 'asc';
setOrder(isAsc ? 'desc' : 'asc');
setOrderBy(property);
};
if (duetState.loading) {
return <p>Sorry, still loading...</p>
}
let dd = duetState.duetData
return (
<TableContainer component={Paper}
order={order}
orderBy={orderBy}
onRequestSort={handleRequestSort}>
<Table className={classes.table} size="small" aria-label="simple table">
<EnhancedTableHead onRequestSort={handleRequestSort}>
<TableRow>
<TableCell>Song Name</TableCell>
<TableCell align="right">Sings</TableCell>
</TableRow>
</EnhancedTableHead>
<TableBody>
{stableSort(dd, getComparator(order, orderBy))
.map((row, index) => {
const labelId = `enhanced-table-${index}`;
return (
<TableRow key={row.publishDate} >
<TableCell component="th" id={labelId} scope="row" padding="none" title={row.publishDate}>
{row.displayPublishDate}
</TableCell>
<TableCell align="left">{row.songName}</TableCell>
<TableCell align="left">{row.singerName}</TableCell>
<TableCell component="th" id={labelId} scope="row" padding="none" title={row.lastSongDate}>
{row.displayLastSongDate}
</TableCell>
<TableCell component="th" id={labelId} scope="row" padding="none" title={row.lastDuetDate}>
{row.displayLastDuetDate}
</TableCell>
</TableRow>
);
})}
</TableBody>
</Table>
</TableContainer>
);
}
export default DuetData;

View File

@ -0,0 +1,23 @@
.App {
text-align: center;
}
.App-logo {
height: 20vmin;
pointer-events: none;
}
.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}
.App-link {
color: #61dafb;
}

View File

@ -0,0 +1,34 @@
import React from 'react';
import logo from './../../logo.svg';
import './ProblemContainer.css';
import Container from '@material-ui/core/Container';
import Typography from '@material-ui/core/Typography';
import { Button, Paper } from '@material-ui/core';
function ProblemContainer() {
const client_id = "sau3e70wvs369jw1u25ex8g3cve599"
const redirect_uri = "https://" + encodeURI(window.location.href.split("/")[2]) + "/twitchadmin"
const twitchURL = "https://id.twitch.tv/oauth2/authorize?client_id="+ client_id +"&redirect_uri="+ redirect_uri +"&response_type=code&scope=user:read:broadcast"
return (
<Container className="App">
<Paper>
<img src={logo} className="App-logo" alt="logo" />
<Typography variant="h4" component="h1" gutterBottom>
Twitch Sings Tools
</Typography>
<Typography variant="h5" component="h2" gutterBottom>
PROBLEM.
</Typography>
<Typography variant="p" component="p" gutterBottom>
Sorry, for some reason the login didn't work out. Gotta bail. Rain check?!
</Typography>
<Button variant="contained" color="primary" href={twitchURL}>
Log in with Twitch
</Button>
</Paper>
</Container>
);
}
export default ProblemContainer;

View File

@ -0,0 +1,149 @@
import React, { useEffect } from 'react';
import { makeStyles } from '@material-ui/core/styles';
import { Table, TableBody, TableCell, TableContainer, TableHead, TableRow, TableSortLabel, Paper } from '@material-ui/core';
import PropTypes from 'prop-types';
const channelName = window.location.href.split("/")[4]
const adminToken = window.location.href.split("/")[5]
const dataURL = "/topsingers/"+ channelName + "/" + adminToken
const headCells = [
{ id: 'singerName', numeric: false, disablePadding: true, label: 'Singer Name' },
{ id: 'singCount', numeric: true, disablePadding: false, label: 'Count' },
];
function descendingComparator(a, b, orderBy) {
if (b[orderBy] < a[orderBy]) {
return -1;
}
if (b[orderBy] > a[orderBy]) {
return 1;
}
return 0;
}
function stableSort(array, comparator) {
const stabilizedThis = array.map((el, index) => [el, index]);
stabilizedThis.sort((a, b) => {
const order = comparator(a[0], b[0]);
if (order !== 0) return order;
return a[1] - b[1];
});
return stabilizedThis.map((el) => el[0]);
}
function getComparator(order, orderBy) {
return order === 'desc'
? (a, b) => descendingComparator(a, b, orderBy)
: (a, b) => -descendingComparator(a, b, orderBy);
}
function EnhancedTableHead(props) {
const { classes, order, orderBy, onRequestSort } = props;
const createSortHandler = (property) => (event) => {
onRequestSort(event, property);
};
return (
<TableHead>
<TableRow>
{headCells.map((headCell) => (
<TableCell
key={headCell.id}
align={headCell.numeric ? 'right' : 'left'}
padding={headCell.disablePadding ? 'none' : 'default'}
sortDirection={orderBy === headCell.id ? order : false}
>
<TableSortLabel
active={orderBy === headCell.id}
direction={orderBy === headCell.id ? order : 'asc'}
onClick={createSortHandler(headCell.id)}
>
{headCell.label}
{orderBy === headCell.id ? (
<span className={classes.visuallyHidden}>
{order === 'desc' ? 'sorted descending' : 'sorted ascending'}
</span>
) : null}
</TableSortLabel>
</TableCell>
))}
</TableRow>
</TableHead>
);
}
EnhancedTableHead.propTypes = {
classes: PropTypes.object.isRequired,
numSelected: PropTypes.number.isRequired,
onRequestSort: PropTypes.func.isRequired,
onSelectAllClick: PropTypes.func.isRequired,
order: PropTypes.oneOf(['asc', 'desc']).isRequired,
orderBy: PropTypes.string.isRequired,
rowCount: PropTypes.number.isRequired,
};
function TopTenSingers() {
const useStyles = makeStyles({
table: {
minWidth: 650,
},
});
const [order, setOrder] = React.useState('asc');
const [orderBy, setOrderBy] = React.useState('calories');
const [singerState, setSingerState] = React.useState({loading: true, duetData: []})
const classes = useStyles();
const handleRequestSort = (event, property) => {
const isAsc = orderBy === property && order === 'asc';
setOrder(isAsc ? 'desc' : 'asc');
setOrderBy(property);
};
useEffect(() => {
// We should only fetch once!
if (singerState.loading) {
fetch(dataURL).then((res) => res.json().then((data)=>{
setSingerState({duetData: data, loading: false })
}));
}
}, [setSingerState]);
if (singerState.loading) {
return <p>Sorry, still loading...</p>
}
let dd = singerState.duetData
return (
<TableContainer component={Paper}
order={order}
orderBy={orderBy}
onRequestSort={handleRequestSort}>
<Table className={classes.table} size="small" aria-label="simple table">
<EnhancedTableHead onRequestSort={handleRequestSort}>
<TableRow>
<TableCell>Song Name</TableCell>
<TableCell align="right">Sings</TableCell>
</TableRow>
</EnhancedTableHead>
<TableBody>
{stableSort(dd, getComparator(order, orderBy))
.map((row, index) => {
const labelId = `enhanced-table-${index}`;
return (
<TableRow key={row.singerName} >
<TableCell component="th" id={labelId} scope="row" padding="none">
{row.singerName}
</TableCell>
<TableCell align="right">{row.singCount}</TableCell>
</TableRow>
);
})}
</TableBody>
</Table>
</TableContainer>
);
}
export default TopTenSingers;

View File

@ -0,0 +1,150 @@
import React, { useEffect } from 'react';
import { makeStyles } from '@material-ui/core/styles';
import { Table, TableBody, TableCell, TableContainer, TableHead, TableRow, TableSortLabel, Paper } from '@material-ui/core';
import PropTypes from 'prop-types';
const channelName = window.location.href.split("/")[4]
const adminToken = window.location.href.split("/")[5]
const dataURL = "/topsongs/"+ channelName + "/" + adminToken
const headCells = [
{ id: 'songName', numeric: false, disablePadding: true, label: 'Song Name' },
{ id: 'singCount', numeric: true, disablePadding: false, label: 'Count' },
];
function descendingComparator(a, b, orderBy) {
if (b[orderBy] < a[orderBy]) {
return -1;
}
if (b[orderBy] > a[orderBy]) {
return 1;
}
return 0;
}
function stableSort(array, comparator) {
const stabilizedThis = array.map((el, index) => [el, index]);
stabilizedThis.sort((a, b) => {
const order = comparator(a[0], b[0]);
if (order !== 0) return order;
return a[1] - b[1];
});
return stabilizedThis.map((el) => el[0]);
}
function getComparator(order, orderBy) {
return order === 'desc'
? (a, b) => descendingComparator(a, b, orderBy)
: (a, b) => -descendingComparator(a, b, orderBy);
}
function EnhancedTableHead(props) {
const { classes, order, orderBy, onRequestSort } = props;
const createSortHandler = (property) => (event) => {
onRequestSort(event, property);
};
return (
<TableHead>
<TableRow>
{headCells.map((headCell) => (
<TableCell
key={headCell.id}
align={headCell.numeric ? 'right' : 'left'}
padding={headCell.disablePadding ? 'none' : 'default'}
sortDirection={orderBy === headCell.id ? order : false}
>
<TableSortLabel
active={orderBy === headCell.id}
direction={orderBy === headCell.id ? order : 'asc'}
onClick={createSortHandler(headCell.id)}
>
{headCell.label}
{orderBy === headCell.id ? (
<span className={classes.visuallyHidden}>
{order === 'desc' ? 'sorted descending' : 'sorted ascending'}
</span>
) : null}
</TableSortLabel>
</TableCell>
))}
</TableRow>
</TableHead>
);
}
EnhancedTableHead.propTypes = {
classes: PropTypes.object.isRequired,
numSelected: PropTypes.number.isRequired,
onRequestSort: PropTypes.func.isRequired,
onSelectAllClick: PropTypes.func.isRequired,
order: PropTypes.oneOf(['asc', 'desc']).isRequired,
orderBy: PropTypes.string.isRequired,
rowCount: PropTypes.number.isRequired,
};
function TopTenSongs() {
const useStyles = makeStyles({
table: {
minWidth: 650,
},
});
const [order, setOrder] = React.useState('asc');
const [orderBy, setOrderBy] = React.useState('calories');
const [songState, setSongState] = React.useState({loading: true, duetData: []})
const classes = useStyles();
const handleRequestSort = (event, property) => {
const isAsc = orderBy === property && order === 'asc';
setOrder(isAsc ? 'desc' : 'asc');
setOrderBy(property);
};
useEffect(() => {
// We should only fetch once!
if (songState.loading) {
fetch(dataURL).then((res) => res.json().then((data)=>{
setSongState({duetData: data, loading: false })
}));
}
}, [setSongState]);
if (songState.loading) {
return <p>Sorry, still loading...</p>
}
let dd = songState.duetData
return (
<TableContainer component={Paper}
order={order}
orderBy={orderBy}
onRequestSort={handleRequestSort}>
<Table className={classes.table} size="small" aria-label="simple table">
<EnhancedTableHead onRequestSort={handleRequestSort}>
<TableRow>
<TableCell>Song Name</TableCell>
<TableCell align="right">Sings</TableCell>
</TableRow>
</EnhancedTableHead>
<TableBody>
{stableSort(dd, getComparator(order, orderBy))
.map((row, index) => {
const labelId = `enhanced-table-${index}`;
return (
<TableRow key={row.songName} >
<TableCell component="th" id={labelId} scope="row" padding="none">
{row.songName}
</TableCell>
<TableCell align="right">{row.singCount}</TableCell>
</TableRow>
);
})}
</TableBody>
</Table>
</TableContainer>
);
}
export default TopTenSongs;

View File

@ -0,0 +1,13 @@
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}

31
build/react-frontend/src/index.js vendored Normal file
View File

@ -0,0 +1,31 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import CssBaseline from '@material-ui/core/CssBaseline';
import { ThemeProvider } from '@material-ui/core/styles';
import App from './Components/App/App';
import AppAdmin from './Components/AppAdmin/AppAdmin';
import theme from './theme';
import * as serviceWorker from './serviceWorker';
function whichApp() {
if (window.location.href.split("/")[3].search(/^admin/) >= 0) {
return <AppAdmin />
} else {
return <App />
}
}
const app = whichApp()
ReactDOM.render(
<ThemeProvider theme={theme}>
{/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */}
<CssBaseline />
{app}
</ThemeProvider>,
document.getElementById('root')
);
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister();

View File

@ -0,0 +1,107 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="80.730843mm"
height="26.72481mm"
viewBox="0 0 80.730843 26.72481"
version="1.1"
id="svg997"
inkscape:version="0.92.5 (2060ec1f9f, 2020-04-08)"
sodipodi:docname="logo-small.svg">
<defs
id="defs991" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.175"
inkscape:cx="3675.6034"
inkscape:cy="-1948.4018"
inkscape:document-units="mm"
inkscape:current-layer="text1547"
showgrid="false"
inkscape:window-width="2560"
inkscape:window-height="1377"
inkscape:window-x="2552"
inkscape:window-y="-8"
inkscape:window-maximized="1"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0" />
<metadata
id="metadata994">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(445.82239,280.74791)">
<g
aria-label="tools"
style="font-style:normal;font-weight:normal;font-size:704.71020508px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:26.42663383"
id="text1547">
<path
d="m -440.42684,-278.7583 v 5.36182 h 6.39034 v 2.41113 h -6.39034 v 10.25154 q 0,2.30997 0.62386,2.96755 0.64072,0.65758 2.57974,0.65758 h 3.18674 v 2.59661 h -3.18674 q -3.59141,0 -4.95716,-1.33203 -1.36574,-1.34888 -1.36574,-4.88971 v -10.25154 h -2.27625 v -2.41113 h 2.27625 v -5.36182 z"
style="stroke-width:1.29493093"
id="path1551"
inkscape:connector-curvature="0" />
<path
d="m -422.62155,-271.2214 q -2.49543,0 -3.94549,1.95589 -1.45005,1.93902 -1.45005,5.32809 0,3.38908 1.43319,5.34497 1.45005,1.93902 3.96235,1.93902 2.47858,0 3.92863,-1.95588 1.45006,-1.95589 1.45006,-5.32811 0,-3.35535 -1.45006,-5.31124 -1.45005,-1.97274 -3.92863,-1.97274 z m 0,-2.63033 q 4.04666,0 6.35663,2.63033 2.30997,2.63033 2.30997,7.28398 0,4.6368 -2.30997,7.28399 -2.30997,2.63033 -6.35663,2.63033 -4.06351,0 -6.37348,-2.63033 -2.29311,-2.64719 -2.29311,-7.28399 0,-4.65365 2.29311,-7.28398 2.30997,-2.63033 6.37348,-2.63033 z"
style="stroke-width:1.29493093"
id="path1553"
inkscape:connector-curvature="0" />
<path
d="m -401.51148,-271.2214 q -2.49543,0 -3.94549,1.95589 -1.45005,1.93902 -1.45005,5.32809 0,3.38908 1.43319,5.34497 1.45005,1.93902 3.96235,1.93902 2.47859,0 3.92864,-1.95588 1.45005,-1.95589 1.45005,-5.32811 0,-3.35535 -1.45005,-5.31124 -1.45005,-1.97274 -3.92864,-1.97274 z m 0,-2.63033 q 4.04667,0 6.35663,2.63033 2.30997,2.63033 2.30997,7.28398 0,4.6368 -2.30997,7.28399 -2.30996,2.63033 -6.35663,2.63033 -4.06351,0 -6.37348,-2.63033 -2.29311,-2.64719 -2.29311,-7.28399 0,-4.65365 2.29311,-7.28398 2.30997,-2.63033 6.37348,-2.63033 z"
style="stroke-width:1.29493093"
id="path1555"
inkscape:connector-curvature="0" />
<path
d="m -387.71911,-280.74791 h 3.10244 v 26.23584 h -3.10244 z"
style="stroke-width:1.29493093"
id="path1557"
inkscape:connector-curvature="0" />
<path
d="m -366.10321,-272.84007 v 2.93383 q -1.31517,-0.67444 -2.7315,-1.01166 -1.41632,-0.33722 -2.93382,-0.33722 -2.30997,0 -3.47339,0.70816 -1.14655,0.70817 -1.14655,2.1245 0,1.07911 0.82619,1.70297 0.82619,0.60699 3.32164,1.16341 l 1.06225,0.23606 q 3.30476,0.70816 4.68738,2.00646 1.39946,1.28145 1.39946,3.59141 0,2.63033 -2.09077,4.16469 -2.07391,1.53436 -5.7159,1.53436 -1.5175,0 -3.16989,-0.3035 -1.63552,-0.28664 -3.45652,-0.87678 v -3.2036 q 1.71983,0.89364 3.38908,1.34888 1.66925,0.43839 3.30477,0.43839 2.19194,0 3.37221,-0.74188 1.18028,-0.75875 1.18028,-2.1245 0,-1.26458 -0.85991,-1.93903 -0.84306,-0.67444 -3.7263,-1.2983 l -1.07911,-0.25291 q -2.88325,-0.607 -4.16469,-1.85472 -1.28144,-1.26458 -1.28144,-3.45652 0,-2.66405 1.88844,-4.11411 1.88844,-1.45005 5.36182,-1.45005 1.71983,0 3.23733,0.25292 1.5175,0.25291 2.79894,0.75874 z"
style="stroke-width:1.29493093"
id="path1559"
inkscape:connector-curvature="0" />
</g>
<path
style="fill:none;fill-opacity:1;stroke:#ff8c0a;stroke-width:0.68919873;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
inkscape:transform-center-x="0.68257895"
inkscape:transform-center-y="-1.9869007"
d="m -416.5125,-258.27705 -1.63148,1.4538 -4.39724,-4.25187 -3.98975,4.15707 -1.73568,-1.46418 2.81877,-4.6018 -5.0913,-2.25985 0.6072,-2.38846 5.40138,1.29402 0.75555,-5.82372 2.04374,0.005 0.67427,5.65487 5.11647,-1.54971 0.80025,2.09668 -4.68721,2.70586 z"
id="path1542"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccccccccccccccc" />
<path
sodipodi:nodetypes="cccccccccccccccc"
inkscape:connector-curvature="0"
id="path1549"
d="m -395.32425,-258.20296 -1.63148,1.4538 -4.39723,-4.25188 -3.98975,4.15708 -1.73569,-1.46418 2.81878,-4.60181 -5.0913,-2.25985 0.6072,-2.38845 5.40137,1.29402 0.75555,-5.82373 2.04375,0.005 0.67427,5.65487 5.11647,-1.5497 0.80024,2.09667 -4.6872,2.70587 z"
inkscape:transform-center-y="-1.9869003"
inkscape:transform-center-x="0.68257979"
style="fill:none;fill-opacity:1;stroke:#ff8c0a;stroke-width:0.68919873;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 6.1 KiB

View File

@ -0,0 +1,107 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="368.46396mm"
height="121.97481mm"
viewBox="0 0 368.46396 121.97481"
version="1.1"
id="svg997"
inkscape:version="0.92.5 (2060ec1f9f, 2020-04-08)"
sodipodi:docname="logo.svg">
<defs
id="defs991" />
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.175"
inkscape:cx="3675.6034"
inkscape:cy="-1588.4018"
inkscape:document-units="mm"
inkscape:current-layer="text1547"
showgrid="false"
inkscape:window-width="2560"
inkscape:window-height="1377"
inkscape:window-x="2552"
inkscape:window-y="-8"
inkscape:window-maximized="1"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0" />
<metadata
id="metadata994">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(445.82239,280.74791)">
<g
aria-label="tools"
style="font-style:normal;font-weight:normal;font-size:704.71020508px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:26.42663383"
id="text1547">
<path
d="m -421.19656,-271.66713 v 24.47192 h 29.16621 v 11.00466 h -29.16621 v 46.78908 q 0,10.54293 2.84736,13.5442 2.92432,3.00128 11.77422,3.00128 h 14.54463 v 11.85118 h -14.54463 q -16.39156,0 -22.62497,-6.0795 -6.23342,-6.15646 -6.23342,-22.31716 v -46.78908 h -10.38902 v -11.00466 h 10.38902 v -24.47192 z"
style="stroke-width:5.91019917"
id="path1551"
inkscape:connector-curvature="0" />
<path
d="m -339.93133,-237.26793 q -11.38944,0 -18.00763,8.92687 -6.6182,8.8499 -6.6182,24.318 0,15.4681 6.54124,24.39496 6.61819,8.84991 18.08459,8.84991 11.31249,0 17.93068,-8.92686 6.6182,-8.92687 6.6182,-24.31801 0,-15.31419 -6.6182,-24.24105 -6.61819,-9.00382 -17.93068,-9.00382 z m 0,-12.00509 q 18.46938,0 29.01231,12.00509 10.54293,12.00509 10.54293,33.24487 0,21.16282 -10.54293,33.24487 -10.54293,12.00509 -29.01231,12.00509 -18.54632,0 -29.08926,-12.00509 -10.46598,-12.08205 -10.46598,-33.24487 0,-21.23978 10.46598,-33.24487 10.54294,-12.00509 29.08926,-12.00509 z"
style="stroke-width:5.91019917"
id="path1553"
inkscape:connector-curvature="0" />
<path
d="m -243.58277,-237.26793 q -11.38944,0 -18.00763,8.92687 -6.61819,8.8499 -6.61819,24.318 0,15.4681 6.54123,24.39496 6.61819,8.84991 18.08459,8.84991 11.3125,0 17.93069,-8.92686 6.61819,-8.92687 6.61819,-24.31801 0,-15.31419 -6.61819,-24.24105 -6.61819,-9.00382 -17.93069,-9.00382 z m 0,-12.00509 q 18.46938,0 29.01231,12.00509 10.54293,12.00509 10.54293,33.24487 0,21.16282 -10.54293,33.24487 -10.54293,12.00509 -29.01231,12.00509 -18.54632,0 -29.08925,-12.00509 -10.46598,-12.08205 -10.46598,-33.24487 0,-21.23978 10.46598,-33.24487 10.54293,-12.00509 29.08925,-12.00509 z"
style="stroke-width:5.91019917"
id="path1555"
inkscape:connector-curvature="0" />
<path
d="m -180.63298,-280.74791 h 14.15985 v 119.7431 h -14.15985 z"
style="stroke-width:5.91019917"
id="path1557"
inkscape:connector-curvature="0" />
<path
d="m -81.975769,-244.65568 v 13.3903 q -6.002557,-3.07823 -12.466831,-4.61734 -6.46427,-1.53912 -13.39029,-1.53912 -10.54294,0 -15.85288,3.23214 -5.23299,3.23214 -5.23299,9.69642 0,4.92517 3.77083,7.77253 3.77082,2.7704 15.16029,5.30994 l 4.84821,1.07738 q 15.083302,3.23214 21.393685,9.15773 6.387317,5.84864 6.387317,16.39157 0,12.00509 -9.542508,19.00806 -9.465552,7.00297 -26.087984,7.00297 -6.92601,0 -14.46768,-1.3852 -7.4647,-1.30825 -15.77592,-4.0017 v -14.62158 q 7.84948,4.07865 15.4681,6.15645 7.61862,2.00085 15.08332,2.00085 10.00425,0 15.391134,-3.38605 5.386906,-3.46301 5.386906,-9.69642 0,-5.77168 -3.924733,-8.84991 -3.8478,-3.07823 -17.007217,-5.92559 l -4.92517,-1.15433 q -13.15943,-2.77041 -19.00806,-8.46513 -5.84864,-5.77168 -5.84864,-15.77592 0,-12.15901 8.61904,-18.7772 8.61904,-6.61819 24.47191,-6.61819 7.84949,0 14.775504,1.15434 6.926012,1.15433 12.774657,3.463 z"
style="stroke-width:5.91019917"
id="path1559"
inkscape:connector-curvature="0" />
</g>
<path
style="fill:none;fill-opacity:1;stroke:#ff8c0a;stroke-width:3.14557457;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
inkscape:transform-center-x="3.1153683"
inkscape:transform-center-y="-9.0684207"
d="m -312.04901,-178.18855 -7.44625,6.63529 -20.06943,-19.40599 -18.20965,18.97332 -7.92185,-6.68267 12.8652,-21.00312 -23.23724,-10.31419 2.77132,-10.90116 24.65245,5.90605 3.4484,-26.58009 9.32787,0.0215 3.07745,25.80942 23.35208,-7.07303 3.65241,9.56944 -21.39289,12.34986 z"
id="path1542"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccccccccccccccc" />
<path
sodipodi:nodetypes="cccccccccccccccc"
inkscape:connector-curvature="0"
id="path1549"
d="m -215.34361,-177.85042 -7.44625,6.63529 -20.06943,-19.40599 -18.20965,18.97332 -7.92184,-6.68267 12.86519,-21.00312 -23.23724,-10.31419 2.77132,-10.90116 24.65245,5.90605 3.4484,-26.5801 9.32787,0.0215 3.07745,25.80943 23.35208,-7.07303 3.65241,9.56944 -21.39288,12.34986 z"
inkscape:transform-center-y="-9.0684254"
inkscape:transform-center-x="3.1153696"
style="fill:none;fill-opacity:1;stroke:#ff8c0a;stroke-width:3.14557457;stroke-linecap:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 6.3 KiB

View File

@ -0,0 +1,141 @@
// This optional code is used to register a service worker.
// register() is not called by default.
// This lets the app load faster on subsequent visits in production, and gives
// it offline capabilities. However, it also means that developers (and users)
// will only see deployed updates on subsequent visits to a page, after all the
// existing tabs open on the page have been closed, since previously cached
// resources are updated in the background.
// To learn more about the benefits of this model and instructions on how to
// opt-in, read https://bit.ly/CRA-PWA
const isLocalhost = Boolean(
window.location.hostname === 'localhost' ||
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
// 127.0.0.0/8 are considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
);
export function register(config) {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
if (publicUrl.origin !== window.location.origin) {
// Our service worker won't work if PUBLIC_URL is on a different origin
// from what our page is served on. This might happen if a CDN is used to
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
return;
}
window.addEventListener('load', () => {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
if (isLocalhost) {
// This is running on localhost. Let's check if a service worker still exists or not.
checkValidServiceWorker(swUrl, config);
// Add some additional logging to localhost, pointing developers to the
// service worker/PWA documentation.
navigator.serviceWorker.ready.then(() => {
console.log(
'This web app is being served cache-first by a service ' +
'worker. To learn more, visit https://bit.ly/CRA-PWA'
);
});
} else {
// Is not localhost. Just register service worker
registerValidSW(swUrl, config);
}
});
}
}
function registerValidSW(swUrl, config) {
navigator.serviceWorker
.register(swUrl)
.then(registration => {
registration.onupdatefound = () => {
const installingWorker = registration.installing;
if (installingWorker == null) {
return;
}
installingWorker.onstatechange = () => {
if (installingWorker.state === 'installed') {
if (navigator.serviceWorker.controller) {
// At this point, the updated precached content has been fetched,
// but the previous service worker will still serve the older
// content until all client tabs are closed.
console.log(
'New content is available and will be used when all ' +
'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
);
// Execute callback
if (config && config.onUpdate) {
config.onUpdate(registration);
}
} else {
// At this point, everything has been precached.
// It's the perfect time to display a
// "Content is cached for offline use." message.
console.log('Content is cached for offline use.');
// Execute callback
if (config && config.onSuccess) {
config.onSuccess(registration);
}
}
}
};
};
})
.catch(error => {
console.error('Error during service worker registration:', error);
});
}
function checkValidServiceWorker(swUrl, config) {
// Check if the service worker can be found. If it can't reload the page.
fetch(swUrl, {
headers: { 'Service-Worker': 'script' },
})
.then(response => {
// Ensure service worker exists, and that we really are getting a JS file.
const contentType = response.headers.get('content-type');
if (
response.status === 404 ||
(contentType != null && contentType.indexOf('javascript') === -1)
) {
// No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then(registration => {
registration.unregister().then(() => {
window.location.reload();
});
});
} else {
// Service worker found. Proceed as normal.
registerValidSW(swUrl, config);
}
})
.catch(() => {
console.log(
'No internet connection found. App is running in offline mode.'
);
});
}
export function unregister() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready
.then(registration => {
registration.unregister();
})
.catch(error => {
console.error(error.message);
});
}
}

View File

@ -0,0 +1,5 @@
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom/extend-expect';

39
build/react-frontend/src/theme.js vendored Normal file
View File

@ -0,0 +1,39 @@
import { red } from '@material-ui/core/colors';
import { createMuiTheme } from '@material-ui/core/styles';
// A custom theme for this app
const theme = createMuiTheme({
palette: {
type: 'light',
primary: {
main: '#61dafb',
light: '#61dafb',
dark: '#21a1c4',
},
secondary: {
main: '#b5ecfb',
light: '#61dafb',
dark: '#21a1c4',
},
error: {
main: red.A400,
},
background: {
default: '#282c34',
},
},
overrides: {
MuiPaper: {
root: {
padding: '20px 10px',
margin: '10px',
backgroundColor: '#fff', // 5d737e
},
},
MuiButton: {
root: {
margin: '5px',
},
},
},
});
export default theme;