shuffle button always on same position now
This commit is contained in:
Lukas Heiligenbrunner 2020-07-22 19:00:55 +02:00
parent e4b55a1c76
commit 1eddddcbac
3 changed files with 20 additions and 13 deletions

View File

@ -36,6 +36,7 @@ class VideoContainer extends React.Component {
{/*todo css for no items to show*/} {/*todo css for no items to show*/}
{this.state.loadeditems.length === 0 ? {this.state.loadeditems.length === 0 ?
"no items to show!" : null} "no items to show!" : null}
{this.props.children}
</div> </div>
); );
} }

View File

@ -1,9 +1,9 @@
import React from "react"; import React from "react";
import Preview from "../../elements/Preview/Preview";
import style from "./RandomPage.module.css" import style from "./RandomPage.module.css"
import SideBar, {SideBarTitle} from "../../elements/SideBar/SideBar"; import SideBar, {SideBarTitle} from "../../elements/SideBar/SideBar";
import Tag from "../../elements/Tag/Tag"; import Tag from "../../elements/Tag/Tag";
import PageTitle from "../../elements/PageTitle/PageTitle"; import PageTitle from "../../elements/PageTitle/PageTitle";
import VideoContainer from "../../elements/VideoContainer/VideoContainer";
class RandomPage extends React.Component { class RandomPage extends React.Component {
constructor(props, context) { constructor(props, context) {
@ -35,18 +35,17 @@ class RandomPage extends React.Component {
))} ))}
</SideBar> </SideBar>
<div className='maincontent'> {this.state.videos.length !== 0 ?
{this.state.videos.map(elem => ( <VideoContainer
<Preview data={this.state.videos}
key={elem.movie_id} viewbinding={this.props.viewbinding}>
name={elem.movie_name} <div className={style.Shufflebutton}>
movie_id={elem.movie_id} <button onClick={() => this.shuffleclick()} className={style.btnshuffle}>Shuffle</button>
viewbinding={this.props.viewbinding}/> </div>
))} </VideoContainer>
<div className={style.Shufflebutton}> :
<button onClick={() => this.shuffleclick()} className={style.btnshuffle}>Shuffle</button> <div>No Data found!</div>}
</div>
</div>
</div> </div>
); );
} }
@ -65,6 +64,8 @@ class RandomPage extends React.Component {
.then((response) => response.json() .then((response) => response.json()
.then((result) => { .then((result) => {
console.log(result); console.log(result);
this.setState({videos: []}); // needed to trigger rerender of main videoview
this.setState({ this.setState({
videos: result.rows, videos: result.rows,
tags: result.tags tags: result.tags

View File

@ -29,6 +29,11 @@ describe('<RandomPage/>', function () {
const wrapper = shallow(<RandomPage/>); const wrapper = shallow(<RandomPage/>);
// simulate at least one existing element
wrapper.setState({videos: [
{}
]});
wrapper.find(".btnshuffle").simulate("click"); wrapper.find(".btnshuffle").simulate("click");
expect(global.fetch).toBeCalledTimes(2); expect(global.fetch).toBeCalledTimes(2);