2020-12-29 19:39:30 +00:00
|
|
|
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';
|
2021-01-29 22:15:17 +00:00
|
|
|
import {APINode, callAPI} from '../../utils/Api';
|
2020-12-29 19:39:30 +00:00
|
|
|
import {Route, Switch, withRouter} from 'react-router-dom';
|
|
|
|
import {RouteComponentProps} from 'react-router';
|
|
|
|
import SearchHandling from './SearchHandling';
|
2021-01-22 21:05:21 +00:00
|
|
|
import {VideoTypes} from '../../types/ApiTypes';
|
2021-03-14 14:51:53 +00:00
|
|
|
import {DefaultTags} from '../../types/GeneralTypes';
|
2021-06-13 22:29:50 +02:00
|
|
|
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
|
|
|
|
import {faSortDown} from '@fortawesome/free-solid-svg-icons';
|
|
|
|
|
|
|
|
// eslint-disable-next-line no-shadow
|
2021-06-22 22:01:35 +02:00
|
|
|
export enum SortBy {
|
2021-06-13 22:29:50 +02:00
|
|
|
date,
|
|
|
|
likes,
|
|
|
|
random,
|
|
|
|
name
|
|
|
|
}
|
2020-12-29 19:39:30 +00:00
|
|
|
|
2021-03-14 14:51:53 +00:00
|
|
|
interface Props extends RouteComponentProps {}
|
2020-12-29 19:39:30 +00:00
|
|
|
|
|
|
|
interface state {
|
2021-03-14 14:51:53 +00:00
|
|
|
sideinfo: VideoTypes.startDataType;
|
|
|
|
subtitle: string;
|
|
|
|
data: VideoTypes.VideoUnloadedType[];
|
|
|
|
selectionnr: number;
|
2021-06-13 22:29:50 +02:00
|
|
|
sortby: string;
|
2020-12-29 19:39:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The home page component showing on the initial pageload
|
|
|
|
*/
|
2021-03-14 14:51:53 +00:00
|
|
|
export class HomePage extends React.Component<Props, state> {
|
2020-12-29 19:39:30 +00:00
|
|
|
/** keyword variable needed temporary store search keyword */
|
|
|
|
keyword = '';
|
|
|
|
|
2021-03-14 14:51:53 +00:00
|
|
|
constructor(props: Props) {
|
2020-12-29 19:39:30 +00:00
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
sideinfo: {
|
2021-02-23 16:01:29 +00:00
|
|
|
VideoNr: 0,
|
|
|
|
FullHdNr: 0,
|
|
|
|
HDNr: 0,
|
|
|
|
SDNr: 0,
|
|
|
|
DifferentTags: 0,
|
2021-03-14 14:51:53 +00:00
|
|
|
Tagged: 0
|
2020-12-29 19:39:30 +00:00
|
|
|
},
|
|
|
|
subtitle: 'All Videos',
|
|
|
|
data: [],
|
2021-06-13 22:29:50 +02:00
|
|
|
selectionnr: 0,
|
|
|
|
sortby: 'Date Added'
|
2020-12-29 19:39:30 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-06-13 22:29:50 +02:00
|
|
|
sortState = SortBy.date;
|
|
|
|
tagState = DefaultTags.all;
|
|
|
|
|
2020-12-29 19:39:30 +00:00
|
|
|
componentDidMount(): void {
|
|
|
|
// initial get of all videos
|
2021-06-13 22:29:50 +02:00
|
|
|
this.fetchVideoData();
|
2020-12-29 19:39:30 +00:00
|
|
|
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
|
|
|
|
*/
|
2021-06-13 22:29:50 +02:00
|
|
|
fetchVideoData(): void {
|
2021-06-08 18:12:09 +00:00
|
|
|
callAPI(
|
|
|
|
APINode.Video,
|
2021-06-13 22:29:50 +02:00
|
|
|
{action: 'getMovies', Tag: this.tagState.TagId, Sort: this.sortState},
|
2021-06-08 18:12:09 +00:00
|
|
|
(result: {Videos: VideoTypes.VideoUnloadedType[]; TagName: string}) => {
|
|
|
|
this.setState({
|
|
|
|
data: result.Videos,
|
|
|
|
selectionnr: result.Videos.length
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
2020-12-29 19:39:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* fetch the necessary data for left info box
|
|
|
|
*/
|
|
|
|
fetchStartData(): void {
|
2021-01-29 22:15:17 +00:00
|
|
|
callAPI(APINode.Video, {action: 'getStartData'}, (result: VideoTypes.startDataType) => {
|
2021-02-23 16:01:29 +00:00
|
|
|
this.setState({sideinfo: result});
|
2020-12-29 19:39:30 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render(): JSX.Element {
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Switch>
|
|
|
|
<Route path='/search/:name'>
|
2021-03-14 14:51:53 +00:00
|
|
|
<SearchHandling />
|
2020-12-29 19:39:30 +00:00
|
|
|
</Route>
|
|
|
|
<Route path='/'>
|
2021-03-14 14:51:53 +00:00
|
|
|
<PageTitle title='Home Page' subtitle={this.state.subtitle + ' - ' + this.state.selectionnr}>
|
|
|
|
<form
|
|
|
|
className={'form-inline ' + style.searchform}
|
|
|
|
onSubmit={(e): void => {
|
|
|
|
e.preventDefault();
|
|
|
|
this.props.history.push('/search/' + this.keyword);
|
|
|
|
}}>
|
|
|
|
<input
|
|
|
|
data-testid='searchtextfield'
|
|
|
|
className='form-control mr-sm-2'
|
|
|
|
type='text'
|
|
|
|
placeholder='Search'
|
|
|
|
onChange={(e): void => {
|
|
|
|
this.keyword = e.target.value;
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<button data-testid='searchbtnsubmit' className='btn btn-success' type='submit'>
|
|
|
|
Search
|
|
|
|
</button>
|
2020-12-29 19:39:30 +00:00
|
|
|
</form>
|
|
|
|
</PageTitle>
|
|
|
|
<SideBar>
|
|
|
|
<SideBarTitle>Infos:</SideBarTitle>
|
2021-03-14 14:51:53 +00:00
|
|
|
<Line />
|
|
|
|
<SideBarItem>
|
|
|
|
<b>{this.state.sideinfo.VideoNr}</b> Videos Total!
|
|
|
|
</SideBarItem>
|
|
|
|
<SideBarItem>
|
|
|
|
<b>{this.state.sideinfo.FullHdNr}</b> FULL-HD Videos!
|
|
|
|
</SideBarItem>
|
|
|
|
<SideBarItem>
|
|
|
|
<b>{this.state.sideinfo.HDNr}</b> HD Videos!
|
|
|
|
</SideBarItem>
|
|
|
|
<SideBarItem>
|
|
|
|
<b>{this.state.sideinfo.SDNr}</b> SD Videos!
|
|
|
|
</SideBarItem>
|
|
|
|
<SideBarItem>
|
|
|
|
<b>{this.state.sideinfo.DifferentTags}</b> different Tags!
|
|
|
|
</SideBarItem>
|
|
|
|
<Line />
|
2020-12-29 19:39:30 +00:00
|
|
|
<SideBarTitle>Default Tags:</SideBarTitle>
|
2021-03-14 14:51:53 +00:00
|
|
|
<Tag
|
|
|
|
tagInfo={{TagName: 'All', TagId: DefaultTags.all.TagId}}
|
|
|
|
onclick={(): void => {
|
2021-06-13 22:29:50 +02:00
|
|
|
this.tagState = DefaultTags.all;
|
|
|
|
this.fetchVideoData();
|
2021-03-14 14:51:53 +00:00
|
|
|
this.setState({subtitle: 'All Videos'});
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<Tag
|
|
|
|
tagInfo={{TagName: 'Full Hd', TagId: DefaultTags.fullhd.TagId}}
|
|
|
|
onclick={(): void => {
|
2021-06-13 22:29:50 +02:00
|
|
|
this.tagState = DefaultTags.fullhd;
|
|
|
|
this.fetchVideoData();
|
2021-03-14 14:51:53 +00:00
|
|
|
this.setState({subtitle: 'Full Hd Videos'});
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<Tag
|
|
|
|
tagInfo={{TagName: 'Low Quality', TagId: DefaultTags.lowq.TagId}}
|
|
|
|
onclick={(): void => {
|
2021-06-13 22:29:50 +02:00
|
|
|
this.tagState = DefaultTags.lowq;
|
|
|
|
this.fetchVideoData();
|
2021-03-14 14:51:53 +00:00
|
|
|
this.setState({subtitle: 'Low Quality Videos'});
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<Tag
|
|
|
|
tagInfo={{TagName: 'HD', TagId: DefaultTags.hd.TagId}}
|
|
|
|
onclick={(): void => {
|
2021-06-13 22:29:50 +02:00
|
|
|
this.tagState = DefaultTags.hd;
|
|
|
|
this.fetchVideoData();
|
2021-03-14 14:51:53 +00:00
|
|
|
this.setState({subtitle: 'HD Videos'});
|
|
|
|
}}
|
|
|
|
/>
|
2020-12-29 19:39:30 +00:00
|
|
|
</SideBar>
|
2021-06-13 22:29:50 +02:00
|
|
|
<div>
|
2021-06-22 22:01:35 +02:00
|
|
|
<span className={style.sortbyLabel}>Sort By: </span>
|
2021-06-13 22:29:50 +02:00
|
|
|
<div className={style.dropdown}>
|
|
|
|
<span className={style.dropbtn}>
|
|
|
|
<span>{this.state.sortby}</span>
|
|
|
|
<FontAwesomeIcon style={{marginLeft: 3, paddingBottom: 3}} icon={faSortDown} size='1x' />
|
|
|
|
</span>
|
|
|
|
<div className={style.dropdownContent}>
|
2021-06-22 22:01:35 +02:00
|
|
|
<span onClick={(): void => this.onDropDownItemClick(SortBy.date, 'Date Added')}>Date Added</span>
|
|
|
|
<span onClick={(): void => this.onDropDownItemClick(SortBy.likes, 'Most likes')}>Most likes</span>
|
|
|
|
<span onClick={(): void => this.onDropDownItemClick(SortBy.random, 'Random')}>Random</span>
|
|
|
|
<span onClick={(): void => this.onDropDownItemClick(SortBy.name, 'Name')}>Name</span>
|
2021-06-13 22:29:50 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2021-04-16 21:12:56 +02:00
|
|
|
<VideoContainer data={this.state.data} />
|
2021-03-14 14:51:53 +00:00
|
|
|
<div className={style.rightinfo} />
|
2020-12-29 19:39:30 +00:00
|
|
|
</Route>
|
|
|
|
</Switch>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
2021-06-22 22:01:35 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* click handler for sortby dropdown item click
|
|
|
|
* @param type type of sort action
|
|
|
|
* @param name new header title
|
|
|
|
*/
|
|
|
|
onDropDownItemClick(type: SortBy, name: string): void {
|
|
|
|
this.sortState = type;
|
|
|
|
this.setState({sortby: name});
|
|
|
|
this.fetchVideoData();
|
|
|
|
}
|
2020-12-29 19:39:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default withRouter(HomePage);
|