From 98a949bed1aca4916f82bbbe615f90891d330b49 Mon Sep 17 00:00:00 2001 From: Agusti Bau Date: Sat, 25 Apr 2020 01:09:07 +0200 Subject: [PATCH] Refactored DNDTagTile to use useContextMenu Signed-off-by: Agusti Bau --- src/components/views/elements/DNDTagTile.js | 63 ++++++--------------- 1 file changed, 18 insertions(+), 45 deletions(-) diff --git a/src/components/views/elements/DNDTagTile.js b/src/components/views/elements/DNDTagTile.js index 3ef805992e..5a96f01d9f 100644 --- a/src/components/views/elements/DNDTagTile.js +++ b/src/components/views/elements/DNDTagTile.js @@ -17,55 +17,29 @@ limitations under the License. import TagTile from './TagTile'; -import React, {createRef} from 'react'; +import React from 'react'; import { Draggable } from 'react-beautiful-dnd'; -import {ContextMenu, toRightOf} from "../../structures/ContextMenu"; +import {ContextMenu, toRightOf, useContextMenu} from "../../structures/ContextMenu"; import * as sdk from '../../../index'; -export default class DNDTagTile extends React.Component { - constructor() { - super(); - this.state = { - menuDisplayed: false, - }; +export default function DNDTagTile(props) { + const [menuDisplayed, handle, openMenu, closeMenu] = useContextMenu(); - this.openMenu = this.openMenu.bind(this); - this.closeMenu = this.closeMenu.bind(this); - } - - componentDidMount() { - this._contextMenuButton = createRef(); - } - - openMenu() { - this.setState({ - menuDisplayed: true, - }); - } - - closeMenu() { - console.log("Closig menu"); - this.setState({ - menuDisplayed: false, - }); - } - - getContextMenu() { - const elementRect = this._contextMenuButton.current.getBoundingClientRect(); + let contextMenu = null; + if (menuDisplayed && handle.current) { + const elementRect = handle.current.getBoundingClientRect(); const TagTileContextMenu = sdk.getComponent('context_menus.TagTileContextMenu'); - return ( - - + contextMenu = ( + + ); } - - render(props) { return
{ (provided, snapshot) => ( @@ -76,17 +50,16 @@ export default class DNDTagTile extends React.Component { {...provided.dragHandleProps} >
{ provided.placeholder } ) } - {this.state.menuDisplayed && this.getContextMenu()} + {contextMenu} ; - } }