diff --git a/src/elements/Popups/PopupBase.tsx b/src/elements/Popups/PopupBase.tsx index 7216b8e..524cb8c 100644 --- a/src/elements/Popups/PopupBase.tsx +++ b/src/elements/Popups/PopupBase.tsx @@ -70,7 +70,7 @@ class PopupBase extends React.Component { } /** - * Alert if clicked on outside of element + * handle click on outside of element */ handleClickOutside(event: MouseEvent): void { if (this.wrapperRef && this.wrapperRef.current && !this.wrapperRef.current.contains(event.target as Node)) { diff --git a/src/elements/Preview/Preview.tsx b/src/elements/Preview/Preview.tsx index b185836..b54d14e 100644 --- a/src/elements/Preview/Preview.tsx +++ b/src/elements/Preview/Preview.tsx @@ -72,7 +72,7 @@ class Preview extends React.Component { popupvisible(): JSX.Element { if (this.state.optionsvisible) - return (heeyyho); + return ( this.setState({optionsvisible: false})}>heeyyho); else return <>; } diff --git a/src/elements/QuickActionPop/QuickActionPop.tsx b/src/elements/QuickActionPop/QuickActionPop.tsx index ec9ac67..0d5e7ab 100644 --- a/src/elements/QuickActionPop/QuickActionPop.tsx +++ b/src/elements/QuickActionPop/QuickActionPop.tsx @@ -1,24 +1,50 @@ -import React from 'react'; -import style from './QuickActionPopup.module.css' - -interface props{ +import React, {RefObject} from 'react'; +import style from './QuickActionPopup.module.css'; +interface props { + position: { + x: number, + y: number + }, + onHide: () => void } class QuickActionPop extends React.Component { + private readonly wrapperRef: RefObject; + constructor(props: props) { super(props); - this.state = {}; + this.wrapperRef = React.createRef(); + + this.handleClickOutside = this.handleClickOutside.bind(this); + } + + + componentDidMount(): void { + document.addEventListener('mousedown', this.handleClickOutside); + } + + componentWillUnmount(): void { + document.removeEventListener('mousedown', this.handleClickOutside); } render(): JSX.Element { return ( -
-
{console.log('clicked');}}>testi
testi +
+ {this.props.children}
); } + + /** + * trigger hide if we click outside the div + */ + handleClickOutside(event: MouseEvent): void { + if (this.wrapperRef && this.wrapperRef.current && !this.wrapperRef.current.contains(event.target as Node)) { + this.props.onHide(); + } + } } export default QuickActionPop; diff --git a/src/elements/QuickActionPop/QuickActionPopup.module.css b/src/elements/QuickActionPop/QuickActionPopup.module.css index 543b94c..a68a836 100644 --- a/src/elements/QuickActionPop/QuickActionPopup.module.css +++ b/src/elements/QuickActionPop/QuickActionPopup.module.css @@ -4,5 +4,4 @@ height: 120px; z-index: 2; position: absolute; - } diff --git a/src/elements/Tag/Tag.tsx b/src/elements/Tag/Tag.tsx index 35bae3f..7bcbac0 100644 --- a/src/elements/Tag/Tag.tsx +++ b/src/elements/Tag/Tag.tsx @@ -1,18 +1,33 @@ -import React from 'react'; +import React, {SyntheticEvent} from 'react'; import styles from './Tag.module.css'; import {Link} from 'react-router-dom'; import {TagType} from '../../types/VideoTypes'; interface props { - onclick?: (_: string) => void - tagInfo: TagType + onclick?: (_: string) => void; + tagInfo: TagType; + onContextMenu?: (pos: {x: number, y: number}) => void +} + +interface state { + contextVisible: boolean } /** * A Component representing a single Category tag */ -class Tag extends React.Component { +class Tag extends React.Component { + constructor(props: Readonly | props) { + super(props); + + this.state = { + contextVisible: false + }; + + this.contextmenu = this.contextmenu.bind(this); + } + render(): JSX.Element { if (this.props.onclick) { return this.renderButton(); @@ -27,7 +42,9 @@ class Tag extends React.Component { renderButton(): JSX.Element { return ( - ); } @@ -42,6 +59,20 @@ class Tag extends React.Component { return; } } + + /** + * handle a custom contextmenu for this item + * @param e + * @private + */ + private contextmenu(e: SyntheticEvent): void { + if (!this.props.onContextMenu) return; + + const event = e as unknown as PointerEvent; + event.preventDefault(); + this.props.onContextMenu({x: event.clientX, y: event.clientY}); + // this.setState({contextVisible: true}); + } } export default Tag; diff --git a/src/pages/Player/Player.tsx b/src/pages/Player/Player.tsx index d238a0b..ddd41df 100644 --- a/src/pages/Player/Player.tsx +++ b/src/pages/Player/Player.tsx @@ -12,7 +12,7 @@ import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'; import {faPlusCircle} from '@fortawesome/free-solid-svg-icons'; import AddActorPopup from '../../elements/Popups/AddActorPopup/AddActorPopup'; import ActorTile from '../../elements/ActorTile/ActorTile'; -import {withRouter} from 'react-router-dom'; +import {Link, withRouter} from 'react-router-dom'; import {callAPI, getBackendDomain} from '../../utils/Api'; import {RouteComponentProps} from 'react-router'; import {GeneralSuccess} from '../../types/GeneralTypes'; @@ -20,6 +20,7 @@ import {ActorType, TagType} from '../../types/VideoTypes'; import PlyrJS from 'plyr'; import {Button} from '../../elements/GPElements/Button'; import {VideoTypes} from '../../types/ApiTypes'; +import QuickActionPop from '../../elements/QuickActionPop/QuickActionPop'; interface myprops extends RouteComponentProps<{ id: string }> {} @@ -34,7 +35,8 @@ interface mystate { suggesttag: TagType[], popupvisible: boolean, actorpopupvisible: boolean, - actors: ActorType[] + actors: ActorType[], + tagContextMenu: boolean } /** @@ -42,7 +44,7 @@ interface mystate { * and actions such as tag adding and liking */ export class Player extends React.Component { - options: PlyrJS.Options = { + private options: PlyrJS.Options = { controls: [ 'play-large', // The large play button in the center 'play', // Play/pause playback @@ -59,10 +61,13 @@ export class Player extends React.Component { ] }; + private contextpos = {x: 0, y: 0}; + constructor(props: myprops) { super(props); this.state = { + tagContextMenu: false, movie_id: -1, movie_name: '', likes: 0, @@ -148,7 +153,10 @@ export class Player extends React.Component { Tags: {this.state.tags.map((m: TagType) => ( - + { + this.setState({tagContextMenu: true}); + this.contextpos = pos; + }}/> ))} Tag Quickadd: @@ -232,6 +240,8 @@ export class Player extends React.Component { this.setState({actorpopupvisible: false}); }} movie_id={this.state.movie_id}/> : null } + + {this.renderContextMenu()} ); } @@ -319,6 +329,23 @@ export class Player extends React.Component { this.setState({actors: result}); }); } + + /** + * render the Tag context menu + */ + private renderContextMenu(): JSX.Element { + if (this.state.tagContextMenu) { + return ( + this.setState({tagContextMenu: false})} + position={this.contextpos}> +