import React from 'react'; import SideBar, {SideBarItem, SideBarTitle} from '../../elements/SideBar/SideBar'; import Tag from '../../elements/Tag/Tag'; import VideoContainer from '../../elements/VideoContainer/VideoContainer'; import style from './HomePage.module.css'; import PageTitle, {Line} from '../../elements/PageTitle/PageTitle'; import {callAPI} from '../../utils/Api'; import {Route, Switch, withRouter} from 'react-router-dom'; import {RouteComponentProps} from 'react-router'; import SearchHandling from './SearchHandling'; import {VideoTypes} from '../../types/ApiTypes'; interface props extends RouteComponentProps {} interface state { sideinfo: { videonr: number, fullhdvideonr: number, hdvideonr: number, sdvideonr: number, tagnr: number }, subtitle: string, data: VideoTypes.VideoUnloadedType[], selectionnr: number } /** * The home page component showing on the initial pageload */ export class HomePage extends React.Component { /** keyword variable needed temporary store search keyword */ keyword = ''; constructor(props: props) { super(props); this.state = { sideinfo: { videonr: 0, fullhdvideonr: 0, hdvideonr: 0, sdvideonr: 0, tagnr: 0 }, subtitle: 'All Videos', data: [], selectionnr: 0 }; } componentDidMount(): void { // initial get of all videos this.fetchVideoData('All'); this.fetchStartData(); } /** * fetch available videos for specified tag * this function clears all preview elements an reloads gravity with tag * * @param tag tag to fetch videos */ fetchVideoData(tag: string): void { callAPI('video.php', {action: 'getMovies', tag: tag}, (result: VideoTypes.VideoUnloadedType[]) => { this.setState({ data: [] }); this.setState({ data: result, selectionnr: result.length, subtitle: `${tag} Videos` }); }); } /** * fetch the necessary data for left info box */ fetchStartData(): void { callAPI('video.php', {action: 'getStartData'}, (result: VideoTypes.startDataType) => { this.setState({ sideinfo: { videonr: result['total'], fullhdvideonr: result['fullhd'], hdvideonr: result['hd'], sdvideonr: result['sd'], tagnr: result['tags'] } }); }); } render(): JSX.Element { return ( <>
{ e.preventDefault(); this.props.history.push('/search/' + this.keyword); }}> { this.keyword = e.target.value; }}/>
Infos: {this.state.sideinfo.videonr} Videos Total! {this.state.sideinfo.fullhdvideonr} FULL-HD Videos! {this.state.sideinfo.hdvideonr} HD Videos! {this.state.sideinfo.sdvideonr} SD Videos! {this.state.sideinfo.tagnr} different Tags! Default Tags: this.fetchVideoData('All')}/> this.fetchVideoData('FullHd')}/> this.fetchVideoData('LowQuality')}/> this.fetchVideoData('HD')}/> {this.state.data.length !== 0 ? :
No Data found!
}
); } } export default withRouter(HomePage);