Allow for reload in caching
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Signed-off-by: Martyn Ranyard <m@rtyn.berlin>
This commit is contained in:
parent
f721c91690
commit
705b1f5e12
|
@ -46,11 +46,40 @@ class AppAdmin extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.setPage = this.setPage.bind(this);
|
this.setPage = this.setPage.bind(this);
|
||||||
this.state = {page: 0};
|
this.reloadSongComponent = this.reloadSongComponent.bind(this);
|
||||||
|
this.reloadSingersComponent = this.reloadSingersComponent.bind(this);
|
||||||
|
this.reloadDuetComponent = this.reloadDuetComponent.bind(this);
|
||||||
|
this.state = {
|
||||||
|
page: 0,
|
||||||
|
reloadSongComponent: false,
|
||||||
|
reloadSingersComponent: false,
|
||||||
|
reloadDuetComponent: false,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
setPage(pageNum) {
|
setPage(pageNum) {
|
||||||
this.setState({page: pageNum})
|
let newState = this.state;
|
||||||
|
newState.page = pageNum;
|
||||||
|
this.setState(newState);
|
||||||
|
}
|
||||||
|
|
||||||
|
reloadSongComponent(components) {
|
||||||
|
let newState = this.state;
|
||||||
|
newState.reloadComponents = components;
|
||||||
|
this.setState(newState);
|
||||||
|
}
|
||||||
|
|
||||||
|
reloadSingersComponent(components) {
|
||||||
|
let newState = this.state;
|
||||||
|
newState.reloadComponents = components;
|
||||||
|
this.setState(newState);
|
||||||
|
}
|
||||||
|
|
||||||
|
reloadDuetComponent(components) {
|
||||||
|
let newState = this.state;
|
||||||
|
newState.reloadDuetComponent = components;
|
||||||
|
console.log("I'm trying!")
|
||||||
|
this.setState(newState);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -72,6 +101,9 @@ class AppAdmin extends React.Component {
|
||||||
const csvURL = "/csv/"+ channelName + "/" + adminToken
|
const csvURL = "/csv/"+ channelName + "/" + adminToken
|
||||||
const tsvURL = "/tsv/"+ channelName + "/" + adminToken
|
const tsvURL = "/tsv/"+ channelName + "/" + adminToken
|
||||||
const setPage = this.setPage
|
const setPage = this.setPage
|
||||||
|
const reloadDuetComponent = this.state.reloadDuetComponent
|
||||||
|
const reloadSongComponent = this.state.reloadSongComponent
|
||||||
|
const reloadSingersComponent = this.state.reloadSingersComponent
|
||||||
|
|
||||||
function handleChange(event, newValue) {
|
function handleChange(event, newValue) {
|
||||||
setPage(newValue);
|
setPage(newValue);
|
||||||
|
@ -95,13 +127,16 @@ class AppAdmin extends React.Component {
|
||||||
</Tabs>
|
</Tabs>
|
||||||
</AppBar>
|
</AppBar>
|
||||||
<TabPanel value={page} index={0}>
|
<TabPanel value={page} index={0}>
|
||||||
<TopTenSongs />
|
<TopTenSongs reloadSongComponent={reloadSongComponent}
|
||||||
|
onReloadedChange={this.reloadSongComponent}/>
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
<TabPanel value={page} index={1}>
|
<TabPanel value={page} index={1}>
|
||||||
<TopTenSingers />
|
<TopTenSingers reloadSingersComponent={reloadSingersComponent}
|
||||||
|
onReloadedChange={this.reloadSingersComponent}/>
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
<TabPanel value={page} index={2}>
|
<TabPanel value={page} index={2}>
|
||||||
<DuetData />
|
<DuetData reloadDuetComponent={reloadDuetComponent}
|
||||||
|
onReloadedChange={this.reloadDuetComponent}/>
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
<TabPanel value={page} index={3}>
|
<TabPanel value={page} index={3}>
|
||||||
<Typography variant="h5" component="h2" gutterBottom>
|
<Typography variant="h5" component="h2" gutterBottom>
|
||||||
|
@ -132,7 +167,11 @@ class AppAdmin extends React.Component {
|
||||||
|
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
<TabPanel value={page} index={4}>
|
<TabPanel value={page} index={4}>
|
||||||
<CacheDeets />
|
<CacheDeets
|
||||||
|
onReloadSongsChange={this.reloadSongComponent}
|
||||||
|
onReloadSingersChange={this.reloadSingersComponent}
|
||||||
|
onReloadDuetChange={this.reloadDuetComponent}
|
||||||
|
/>
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
<TabPanel value={page} index={5}>
|
<TabPanel value={page} index={5}>
|
||||||
<BotDeets />
|
<BotDeets />
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { useEffect } from 'react';
|
import React from 'react';
|
||||||
import { Container, Typography, Button } from '@material-ui/core';
|
import { Container, Typography, Button } from '@material-ui/core';
|
||||||
|
|
||||||
const channelName = window.location.href.split("/")[4]
|
const channelName = window.location.href.split("/")[4]
|
||||||
|
@ -6,38 +6,63 @@ const adminToken = window.location.href.split("/")[5]
|
||||||
const dataURL = "/cachedeets/"+ channelName + "/" + adminToken
|
const dataURL = "/cachedeets/"+ channelName + "/" + adminToken
|
||||||
const forceURL = "/force/"+ channelName + "/" + adminToken
|
const forceURL = "/force/"+ channelName + "/" + adminToken
|
||||||
|
|
||||||
function CacheDeets() {
|
class CacheDeets extends React.Component {
|
||||||
|
constructor(props) {
|
||||||
function handleClick(e) {
|
super(props);
|
||||||
setCacheState({cacheData: null, loading: true })
|
this.state = {
|
||||||
fetch(forceURL).then((res) => res.json().then((data)=>{
|
cacheData: [],
|
||||||
setCacheState({cacheData: data, loading: false })
|
loading: true
|
||||||
}));
|
};
|
||||||
console.log('The link was clicked.');
|
this.setCacheData = this.setCacheData.bind(this);
|
||||||
|
this.setLoading = this.setLoading.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// render() {
|
setCacheData(data) {
|
||||||
const [cacheState, setCacheState] = React.useState({loading: true, cacheData: []})
|
let newState = this.state
|
||||||
|
newState.cacheData = data
|
||||||
|
this.setState(newState)
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
setLoading(data) {
|
||||||
// We should only fetch once!
|
let newState = this.state
|
||||||
if (cacheState.loading) {
|
newState.loading = data
|
||||||
let actualURL = dataURL
|
this.setState(newState)
|
||||||
if (window.location.href.split("/")[2] === "192.168.1.111:3000") {
|
}
|
||||||
//Frontend dev mode only
|
|
||||||
actualURL = "/sampleData/cache.json"
|
componentDidMount() {
|
||||||
}
|
// We should only fetch once!
|
||||||
fetch(actualURL).then((res) => res.json().then((data)=>{
|
if (this.state.loading) {
|
||||||
setCacheState({cacheData: data, loading: false })
|
let actualURL = dataURL
|
||||||
}));
|
if (window.location.href.split("/")[2] === "192.168.1.111:3000") {
|
||||||
|
//Frontend dev mode only
|
||||||
|
actualURL = "/sampleData/cache.json"
|
||||||
}
|
}
|
||||||
}, [setCacheState, cacheState.loading]);
|
fetch(actualURL).then((res) => res.json().then((data)=>{
|
||||||
|
this.setLoading(false)
|
||||||
|
this.setCacheData(data)
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (cacheState.loading) {
|
render() {
|
||||||
|
const loading = this.state.loading
|
||||||
|
const setLoading = this.setLoading
|
||||||
|
const cacheData = this.state.cacheData
|
||||||
|
|
||||||
|
function handleClick(e) {
|
||||||
|
setLoading(true)
|
||||||
|
fetch(forceURL).then((data)=>{
|
||||||
|
setLoading(false)
|
||||||
|
window.location.reload()
|
||||||
|
})
|
||||||
|
console.log('The link was clicked.');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (loading) {
|
||||||
return <p>Sorry, still loading...</p>
|
return <p>Sorry, still loading...</p>
|
||||||
}
|
}
|
||||||
|
|
||||||
let dd = cacheState.cacheData
|
let dd = cacheData
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container>
|
<Container>
|
||||||
|
@ -51,6 +76,6 @@ function CacheDeets() {
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
//}
|
}
|
||||||
|
|
||||||
export default CacheDeets;
|
export default CacheDeets;
|
||||||
|
|
Loading…
Reference in New Issue