2020-12-29 19:39:30 +00:00
|
|
|
import {RouteComponentProps} from 'react-router';
|
|
|
|
import React from 'react';
|
|
|
|
import {withRouter} from 'react-router-dom';
|
2021-01-29 22:15:17 +00:00
|
|
|
import {APINode, callAPI} from '../../utils/Api';
|
2020-12-29 19:39:30 +00:00
|
|
|
import VideoContainer from '../../elements/VideoContainer/VideoContainer';
|
|
|
|
import PageTitle from '../../elements/PageTitle/PageTitle';
|
|
|
|
import SideBar from '../../elements/SideBar/SideBar';
|
2021-01-22 21:05:21 +00:00
|
|
|
import {VideoTypes} from '../../types/ApiTypes';
|
2020-12-29 19:39:30 +00:00
|
|
|
|
|
|
|
interface params {
|
|
|
|
name: string;
|
|
|
|
}
|
|
|
|
|
2021-03-14 14:51:53 +00:00
|
|
|
interface Props extends RouteComponentProps<params> {}
|
2020-12-29 19:39:30 +00:00
|
|
|
|
|
|
|
interface state {
|
2021-01-22 21:05:21 +00:00
|
|
|
data: VideoTypes.VideoUnloadedType[];
|
2020-12-29 19:39:30 +00:00
|
|
|
}
|
|
|
|
|
2021-03-14 14:51:53 +00:00
|
|
|
export class SearchHandling extends React.Component<Props, state> {
|
|
|
|
constructor(props: Props) {
|
2020-12-29 19:39:30 +00:00
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
data: []
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount(): void {
|
|
|
|
this.searchVideos(this.props.match.params.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
render(): JSX.Element {
|
|
|
|
return (
|
|
|
|
<>
|
2021-03-14 14:51:53 +00:00
|
|
|
<PageTitle title='Search' subtitle={this.props.match.params.name + ': ' + this.state.data.length} />
|
|
|
|
<SideBar hiddenFrame />
|
2020-12-29 19:39:30 +00:00
|
|
|
{this.getVideoData()}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get videocontainer if data loaded
|
|
|
|
*/
|
|
|
|
getVideoData(): JSX.Element {
|
|
|
|
if (this.state.data.length !== 0) {
|
2021-03-14 14:51:53 +00:00
|
|
|
return <VideoContainer data={this.state.data} />;
|
2020-12-29 19:39:30 +00:00
|
|
|
} else {
|
2021-03-14 14:51:53 +00:00
|
|
|
return <div>No Data found!</div>;
|
2020-12-29 19:39:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* search for a keyword in db and update previews
|
|
|
|
*
|
|
|
|
* @param keyword The keyword to search for
|
|
|
|
*/
|
|
|
|
searchVideos(keyword: string): void {
|
2021-05-25 22:34:29 +02:00
|
|
|
callAPI(APINode.Video, {action: 'getSearchKeyWord', KeyWord: keyword}, (result: VideoTypes.VideoUnloadedType[]) => {
|
2020-12-29 19:39:30 +00:00
|
|
|
this.setState({
|
|
|
|
data: result
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default withRouter(SearchHandling);
|