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'; import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'; import {faSortDown} from '@fortawesome/free-solid-svg-icons'; // eslint-disable-next-line no-shadow enum SortBy { date, likes, random, name } interface Props extends RouteComponentProps {} interface state { sideinfo: VideoTypes.startDataType; subtitle: string; data: VideoTypes.VideoUnloadedType[]; selectionnr: number; sortby: string; } /** * 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, sortby: 'Date Added' }; } sortState = SortBy.date; tagState = DefaultTags.all; componentDidMount(): void { // initial get of all videos this.fetchVideoData(); 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(): void { callAPI( APINode.Video, {action: 'getMovies', Tag: this.tagState.TagId, Sort: this.sortState}, (result: {Videos: VideoTypes.VideoUnloadedType[]; TagName: string}) => { this.setState({ data: result.Videos, selectionnr: result.Videos.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.tagState = DefaultTags.all; this.fetchVideoData(); this.setState({subtitle: 'All Videos'}); }} /> { this.tagState = DefaultTags.fullhd; this.fetchVideoData(); this.setState({subtitle: 'Full Hd Videos'}); }} /> { this.tagState = DefaultTags.lowq; this.fetchVideoData(); this.setState({subtitle: 'Low Quality Videos'}); }} /> { this.tagState = DefaultTags.hd; this.fetchVideoData(); this.setState({subtitle: 'HD Videos'}); }} />
Sort By:
{this.state.sortby}
{ this.sortState = SortBy.date; this.setState({sortby: 'Date Added '}); this.fetchVideoData(); }}> Date Added { this.sortState = SortBy.likes; this.setState({sortby: 'Most likes'}); this.fetchVideoData(); }}> Most likes { this.sortState = SortBy.random; this.setState({sortby: 'Random'}); this.fetchVideoData(); }}> Random { this.sortState = SortBy.name; this.setState({sortby: 'Name'}); this.fetchVideoData(); }}> Name
); } } export default withRouter(HomePage);