2020-06-25 20:43:26 +00:00
|
|
|
import React from "react";
|
2020-07-03 22:45:18 +00:00
|
|
|
import "./MovieSettings.css"
|
2020-06-25 20:43:26 +00:00
|
|
|
|
|
|
|
class MovieSettings extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
text: []
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
if (this.myinterval) {
|
|
|
|
clearInterval(this.myinterval);
|
|
|
|
}
|
|
|
|
this.myinterval = setInterval(this.updateStatus, 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
clearInterval(this.myinterval);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<button className='reindexbtn btn btn-success' onClick={() => {
|
|
|
|
this.startReindex()
|
|
|
|
}}>Reindex Movies
|
|
|
|
</button>
|
|
|
|
<div className='indextextarea'>{this.state.text.map(m => (
|
|
|
|
<div className='textarea-element'>{m}</div>
|
|
|
|
))}</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
startReindex() {
|
2020-07-03 22:45:18 +00:00
|
|
|
document.getElementsByClassName("indextextarea")[0].innerHTML = "";
|
2020-06-25 20:43:26 +00:00
|
|
|
console.log("starting");
|
|
|
|
const updateRequest = new FormData();
|
|
|
|
// fetch all videos available
|
|
|
|
fetch('/api/extractvideopreviews.php', {method: 'POST', body: updateRequest})
|
|
|
|
.then((response) => response.json()
|
|
|
|
.then((result) => {
|
2020-07-03 22:45:18 +00:00
|
|
|
// todo 2020-07-4: some kind of start event
|
|
|
|
// maybe disable start btn
|
2020-06-25 20:43:26 +00:00
|
|
|
console.log("returned");
|
|
|
|
}))
|
|
|
|
.catch(() => {
|
|
|
|
console.log("no connection to backend");
|
|
|
|
});
|
|
|
|
if (this.myinterval) {
|
|
|
|
clearInterval(this.myinterval);
|
|
|
|
}
|
|
|
|
this.myinterval = setInterval(this.updateStatus, 1000);
|
|
|
|
console.log("sent");
|
|
|
|
}
|
|
|
|
|
|
|
|
updateStatus = () => {
|
|
|
|
const updateRequest = new FormData();
|
|
|
|
fetch('/api/extractionData.php', {method: 'POST', body: updateRequest})
|
|
|
|
.then((response) => response.json()
|
|
|
|
.then((result) => {
|
|
|
|
if (result.contentAvailable === true) {
|
|
|
|
console.log(result);
|
2020-07-03 22:45:18 +00:00
|
|
|
// todo 2020-07-4: scroll to bottom of div here
|
2020-06-25 20:43:26 +00:00
|
|
|
this.setState({
|
2020-07-03 22:45:18 +00:00
|
|
|
// insert a string for each line
|
2020-06-25 20:43:26 +00:00
|
|
|
text: [...result.message.split("\n"),
|
|
|
|
...this.state.text]
|
|
|
|
});
|
|
|
|
} else {
|
2020-07-03 22:45:18 +00:00
|
|
|
// clear refresh interval if no content available
|
|
|
|
// todo 2020-07-4: maybe enable start btn again
|
2020-06-25 20:43:26 +00:00
|
|
|
clearInterval(this.myinterval);
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
.catch(() => {
|
|
|
|
console.log("no connection to backend");
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default MovieSettings;
|