const {max,min}=list.reduce((a,v)=>(a.max=a.max<v.Cur_OfficialRate?v.Cur_OfficialRate:a.max, a.min=a.min>v.Cur_OfficialRate?v.Cur_OfficialRate:a.min, a), {max:0, min: 99999999});
function parseMediaURL(media) {
let regexp = /https:\/\/i\.ytimg\.com\/vi\/([a-zA-Z0-9_-]+)\/maxresdefault\.jpg/i;
let url = media.src;
let match = url.match(regexp);
return match[1];
}
function youtubeGetID(input){
var r = input.replace(/(>|<)/gi,'').split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/)
if(r[2] !== undefined) {
return r[2].split(/[^0-9a-z_\-]/i)[0]
} else {
r = input.match(/^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/)|(?:(?:watch)?\?v(?:i)?=|\&v(?:i)?=))([^#\&\?]*).*/)
if(r && r[1] !== undefined) {
return r[1]
}
else return input
}
}
parseMediaURL(mediaю)
, замените на youtubeGetID(media.src)
. class App extends React.Component {
state = {
counter: 0,
};
...
}
class App extends React.Component {
constructor(props) {
super(props);
state = {
counter: 0,
};
}
handleIncrement() {
this.setState((state) => ({ counter: state.counter + 1 }));
}
render() {
return (
<main>
<h1>React Camp</h1>
<Counter
title='Simple counter'
counter={this.state.counter}
handleIncrement={this.handleIncrement}
/>
</main>
);
}
}
...
class Worker extends React.Component {
constructor(props) {
super(props);
// console.log(props)
// this.state(props.worker);
}
kill(pid){
ws.send("worker.kill",this.props.worker.pid);
}
renderButton(){
if( !this.props.worker.alive ){
return <div className="worker-button">мертв</div>
}
return <button className="worker-button" onClick={() => this.kill()}>убить</button>
}
render() {
return (
<div className="worker">
<div className="worker-info">status: <b>{this.props.worker.status}</b></div>
<div className="worker-info">pid: <b>{this.props.worker.pid}</b></div>
<div className="worker-info"><b>{this.props.worker.generated}</b> / <b>{this.props.worker.processed}</b></div>
{this.renderButton()}
</div>
);
}
}
...