2020-12-11 18:23:13 +00:00
|
|
|
import PopupBase from '../PopupBase';
|
|
|
|
import React from 'react';
|
|
|
|
import ActorTile from '../../ActorTile/ActorTile';
|
|
|
|
import style from './AddActorPopup.module.css';
|
|
|
|
import {NewActorPopupContent} from '../NewActorPopup/NewActorPopup';
|
2020-12-17 20:53:22 +00:00
|
|
|
import {callAPI} from '../../../utils/Api';
|
2020-12-29 19:39:30 +00:00
|
|
|
import {ActorType} from '../../../api/VideoTypes';
|
|
|
|
import {GeneralSuccess} from '../../../api/GeneralTypes';
|
|
|
|
|
|
|
|
interface props {
|
|
|
|
onHide: () => void;
|
|
|
|
movie_id: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface state {
|
|
|
|
contentDefault: boolean;
|
|
|
|
actors: ActorType[];
|
|
|
|
}
|
2020-12-11 18:23:13 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Popup for Adding a new Actor to a Video
|
|
|
|
*/
|
2020-12-29 19:39:30 +00:00
|
|
|
class AddActorPopup extends React.Component<props, state> {
|
|
|
|
constructor(props: props) {
|
2020-12-11 18:23:13 +00:00
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
contentDefault: true,
|
2020-12-29 19:39:30 +00:00
|
|
|
actors: []
|
2020-12-11 18:23:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
this.tileClickHandler = this.tileClickHandler.bind(this);
|
|
|
|
}
|
|
|
|
|
2020-12-29 19:39:30 +00:00
|
|
|
render(): JSX.Element {
|
2020-12-11 18:23:13 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{/* todo render actor tiles here and add search field*/}
|
|
|
|
<PopupBase title='Add new Actor to Video' onHide={this.props.onHide} banner={
|
|
|
|
<button
|
|
|
|
className={style.newactorbutton}
|
2020-12-29 19:39:30 +00:00
|
|
|
onClick={(): void => {
|
|
|
|
this.setState({contentDefault: false});
|
|
|
|
}}>Create new Actor</button>}>
|
2020-12-11 18:23:13 +00:00
|
|
|
{this.resolvePage()}
|
|
|
|
</PopupBase>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-12-29 19:39:30 +00:00
|
|
|
componentDidMount(): void {
|
2020-12-11 18:23:13 +00:00
|
|
|
// fetch the available actors
|
|
|
|
this.loadActors();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* selector for current showing popup page
|
|
|
|
* @returns {JSX.Element}
|
|
|
|
*/
|
2020-12-29 19:39:30 +00:00
|
|
|
resolvePage(): JSX.Element {
|
2020-12-11 18:23:13 +00:00
|
|
|
if (this.state.contentDefault) return (this.getContent());
|
2020-12-29 19:39:30 +00:00
|
|
|
else return (<NewActorPopupContent onHide={(): void => {
|
2020-12-11 18:23:13 +00:00
|
|
|
this.loadActors();
|
|
|
|
this.setState({contentDefault: true});
|
|
|
|
}}/>);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns content for the newActor popup
|
|
|
|
* @returns {JSX.Element}
|
|
|
|
*/
|
2020-12-29 19:39:30 +00:00
|
|
|
getContent(): JSX.Element {
|
|
|
|
if (this.state.actors.length !== 0) {
|
2020-12-11 18:23:13 +00:00
|
|
|
return (<div>
|
|
|
|
{this.state.actors.map((el) => (<ActorTile actor={el} onClick={this.tileClickHandler}/>))}
|
|
|
|
</div>);
|
|
|
|
} else {
|
|
|
|
return (<div>somekind of loading</div>);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* event handling for ActorTile Click
|
|
|
|
*/
|
2020-12-29 19:39:30 +00:00
|
|
|
tileClickHandler(actor: ActorType): void {
|
2020-12-11 18:23:13 +00:00
|
|
|
// fetch the available actors
|
2020-12-29 19:39:30 +00:00
|
|
|
callAPI<GeneralSuccess>('actor.php', {
|
|
|
|
action: 'addActorToVideo',
|
|
|
|
actorid: actor.actor_id,
|
|
|
|
videoid: this.props.movie_id
|
|
|
|
}, result => {
|
2020-12-17 20:53:22 +00:00
|
|
|
if (result.result === 'success') {
|
|
|
|
// return back to player page
|
|
|
|
this.props.onHide();
|
|
|
|
} else {
|
|
|
|
console.error('an error occured while fetching actors');
|
|
|
|
console.error(result);
|
|
|
|
}
|
|
|
|
});
|
2020-12-11 18:23:13 +00:00
|
|
|
}
|
|
|
|
|
2020-12-29 19:39:30 +00:00
|
|
|
loadActors(): void {
|
|
|
|
callAPI<ActorType[]>('actor.php', {action: 'getAllActors'}, result => {
|
2020-12-17 20:53:22 +00:00
|
|
|
this.setState({actors: result});
|
|
|
|
});
|
2020-12-11 18:23:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default AddActorPopup;
|