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 {APINode, 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'; import {DefaultTags} from '../../types/GeneralTypes'; interface Props extends RouteComponentProps {} interface state { sideinfo: VideoTypes.startDataType; 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, FullHdNr: 0, HDNr: 0, SDNr: 0, DifferentTags: 0, Tagged: 0 }, subtitle: 'All Videos', data: [], selectionnr: 0 }; } componentDidMount(): void { // initial get of all videos this.fetchVideoData(DefaultTags.all.TagId); 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: number): void { callAPI(APINode.Video, {action: 'getMovies', tag: tag}, (result: VideoTypes.VideoUnloadedType[]) => { this.setState({ data: [] }); this.setState({ data: result, selectionnr: result.length }); }); } /** * fetch the necessary data for left info box */ fetchStartData(): void { callAPI(APINode.Video, {action: 'getStartData'}, (result: VideoTypes.startDataType) => { this.setState({sideinfo: result}); }); } 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.FullHdNr} FULL-HD Videos! {this.state.sideinfo.HDNr} HD Videos! {this.state.sideinfo.SDNr} SD Videos! {this.state.sideinfo.DifferentTags} different Tags! Default Tags: { this.fetchVideoData(DefaultTags.all.TagId); this.setState({subtitle: 'All Videos'}); }} /> { this.fetchVideoData(DefaultTags.fullhd.TagId); this.setState({subtitle: 'Full Hd Videos'}); }} /> { this.fetchVideoData(DefaultTags.lowq.TagId); this.setState({subtitle: 'Low Quality Videos'}); }} /> { this.fetchVideoData(DefaultTags.hd.TagId); this.setState({subtitle: 'HD Videos'}); }} />
); } } export default withRouter(HomePage);