reformattings

no redirect on tagclick on homepage
no multiple add of same tag possible
This commit is contained in:
2020-10-25 18:48:23 +00:00
parent 812c45cb13
commit 777cc2a712
43 changed files with 493 additions and 448 deletions

View File

@ -1,11 +1,11 @@
import React from "react";
import style from "./Player.module.css"
import React from 'react';
import style from './Player.module.css';
import {PlyrComponent} from 'plyr-react';
import SideBar, {SideBarItem, SideBarTitle} from "../../elements/SideBar/SideBar";
import Tag from "../../elements/Tag/Tag";
import AddTagPopup from "../../elements/AddTagPopup/AddTagPopup";
import PageTitle, {Line} from "../../elements/PageTitle/PageTitle";
import SideBar, {SideBarItem, SideBarTitle} from '../../elements/SideBar/SideBar';
import Tag from '../../elements/Tag/Tag';
import AddTagPopup from '../../elements/AddTagPopup/AddTagPopup';
import PageTitle, {Line} from '../../elements/PageTitle/PageTitle';
/**
@ -26,7 +26,7 @@ class Player extends React.Component {
'settings', // Settings menu
'airplay', // Airplay (currently Safari only)
'download', // Show a download button with a link to either the current source or a custom URL you specify in your options
'fullscreen', // Toggle fullscreen
'fullscreen' // Toggle fullscreen
]
};
@ -66,28 +66,36 @@ class Player extends React.Component {
fetch('/api/tags.php', {method: 'POST', body: updateRequest})
.then((response) => response.json()
.then((result) => {
if (result.result !== "success") {
console.error("error occured while writing to db -- todo error handling");
if (result.result !== 'success') {
console.error('error occured while writing to db -- todo error handling');
console.error(result.result);
} else {
// update tags if successful
let array = [...this.state.suggesttag]; // make a separate copy of the array
const index = array.map(function (e) {
return e.tag_id;
}).indexOf(tag_id);
// check if tag has already been added
const tagindwx = this.state.tags.map(function (e) {
return e.tag_name;
}).indexOf(tag_name);
// check if tag is available in quickadds
if (index !== -1) {
array.splice(index, 1);
// only add tag if it isn't already there
if (tagindwx === -1) {
// update tags if successful
let array = [...this.state.suggesttag]; // make a separate copy of the array (because of setState)
const quickaddindex = this.state.suggesttag.map(function (e) {
return e.tag_id;
}).indexOf(tag_id);
this.setState({
tags: [...this.state.tags, {tag_name: tag_name}],
suggesttag: array
});
} else {
this.setState({
tags: [...this.state.tags, {tag_name: tag_name}]
});
// check if tag is available in quickadds
if (quickaddindex !== -1) {
array.splice(quickaddindex, 1);
this.setState({
tags: [...this.state.tags, {tag_name: tag_name}],
suggesttag: array
});
} else {
this.setState({
tags: [...this.state.tags, {tag_name: tag_name}]
});
}
}
}
}));
@ -170,7 +178,7 @@ class Player extends React.Component {
<button className='btn btn-info' onClick={() => this.setState({popupvisible: true})}>Give this
Video a Tag
</button>
<button className='btn btn-danger' onClick={() => {this.deleteVideo()}}>Delete Video</button>
<button className='btn btn-danger' onClick={() => {this.deleteVideo();}}>Delete Video</button>
</div>
</div>
<button className={style.closebutton} onClick={() => this.closebtn()}>Close</button>
@ -200,7 +208,7 @@ class Player extends React.Component {
{
src: result.movie_url,
type: 'video/mp4',
size: 1080,
size: 1080
}
],
poster: result.thumbnail
@ -229,11 +237,11 @@ class Player extends React.Component {
fetch('/api/video.php', {method: 'POST', body: updateRequest})
.then((response) => response.json()
.then((result) => {
if (result.result === "success") {
if (result.result === 'success') {
// likes +1 --> avoid reload of all data
this.setState({likes: this.state.likes + 1})
this.setState({likes: this.state.likes + 1});
} else {
console.error("an error occured while liking");
console.error('an error occured while liking');
console.error(result);
}
}));
@ -258,11 +266,11 @@ class Player extends React.Component {
fetch('/api/video.php', {method: 'POST', body: updateRequest})
.then((response) => response.json()
.then((result) => {
if (result.result === "success") {
if (result.result === 'success') {
// return to last element if successful
this.props.viewbinding.returnToLastElement();
} else {
console.error("an error occured while liking");
console.error('an error occured while liking');
console.error(result);
}
}));

View File

@ -1,6 +1,6 @@
import {shallow} from "enzyme";
import React from "react";
import Player from "./Player";
import {shallow} from 'enzyme';
import React from 'react';
import Player from './Player';
describe('<Player/>', function () {
it('renders without crashing ', function () {
@ -16,11 +16,11 @@ describe('<Player/>', function () {
{
src: '/tstvid.mp4',
type: 'video/mp4',
size: 1080,
size: 1080
}
]
});
expect(wrapper.find("r")).toHaveLength(1);
expect(wrapper.find('r')).toHaveLength(1);
});
function simulateLikeButtonClick() {
@ -28,7 +28,7 @@ describe('<Player/>', function () {
// initial fetch for getting movie data
expect(global.fetch).toHaveBeenCalledTimes(1);
wrapper.find('.videoactions').find("button").first().simulate('click');
wrapper.find('.videoactions').find('button').first().simulate('click');
// fetch for liking
expect(global.fetch).toHaveBeenCalledTimes(2);
@ -69,20 +69,20 @@ describe('<Player/>', function () {
it('show tag popup', function () {
const wrapper = shallow(<Player/>);
expect(wrapper.find("AddTagPopup")).toHaveLength(0);
expect(wrapper.find('AddTagPopup')).toHaveLength(0);
// todo dynamic button find without index
wrapper.find('.videoactions').find("button").at(1).simulate('click');
wrapper.find('.videoactions').find('button').at(1).simulate('click');
// addtagpopup should be showing now
expect(wrapper.find("AddTagPopup")).toHaveLength(1);
expect(wrapper.find('AddTagPopup')).toHaveLength(1);
});
it('test delete button', done => {
const wrapper = shallow(<Player viewbinding={{
returnToLastElement: jest.fn()
}}/>);
global.fetch = prepareFetchApi({result: "success"});
global.fetch = prepareFetchApi({result: 'success'});
wrapper.find('.videoactions').find("button").at(2).simulate('click');
wrapper.find('.videoactions').find('button').at(2).simulate('click');
process.nextTick(() => {
// refetch is called so fetch called 3 times
@ -101,7 +101,7 @@ describe('<Player/>', function () {
wrapper.setProps({
viewbinding: {
returnToLastElement: () => {
func()
func();
}
}
});
@ -115,7 +115,7 @@ describe('<Player/>', function () {
it('inserts Tags correctly', function () {
const wrapper = shallow(<Player/>);
expect(wrapper.find("Tag")).toHaveLength(0);
expect(wrapper.find('Tag')).toHaveLength(0);
wrapper.setState({
tags: [
@ -124,7 +124,7 @@ describe('<Player/>', function () {
]
});
expect(wrapper.find("Tag")).toHaveLength(2);
expect(wrapper.find('Tag')).toHaveLength(2);
});
it('inserts tag quickadd correctly', function () {
@ -137,7 +137,7 @@ describe('<Player/>', function () {
global.fetch = prepareFetchApi({result: 'success'});
// render tag subcomponent
const tag = wrapper.find("Tag").first().dive();
const tag = wrapper.find('Tag').first().dive();
tag.simulate('click');
process.nextTick(() => {
@ -155,7 +155,7 @@ describe('<Player/>', function () {
global.console.error = jest.fn();
// render tag subcomponent
const tag = wrapper.find("Tag").first().dive();
const tag = wrapper.find('Tag').first().dive();
tag.simulate('click');
process.nextTick(() => {
@ -169,15 +169,15 @@ describe('<Player/>', function () {
function generatetag() {
const wrapper = shallow(<Player/>);
expect(wrapper.find("Tag")).toHaveLength(0);
expect(wrapper.find('Tag')).toHaveLength(0);
wrapper.setState({
suggesttag: [
{tag_name: 'first', tag_id: 1},
{tag_name: 'first', tag_id: 1}
]
});
expect(wrapper.find("Tag")).toHaveLength(1);
expect(wrapper.find('Tag')).toHaveLength(1);
return wrapper;
}