-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
987b93c
commit 176d59a
Showing
4 changed files
with
201 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
services/app/apps/codebattle/assets/js/widgets/pages/tournament/TournamentContextMenu.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import React, { | ||
memo, | ||
useMemo, | ||
useState, | ||
useCallback, | ||
} from 'react'; | ||
|
||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import { | ||
Menu, | ||
Item, | ||
// Separator, | ||
useContextMenu, | ||
} from 'react-contexify'; | ||
import { /* useSelector, */ useDispatch } from 'react-redux'; | ||
|
||
export const useTournamentContextMenu = ({ type }) => { | ||
const menuConf = useMemo(() => ({ id: `${type}-chat` }), [type]); | ||
const { show } = useContextMenu(menuConf); | ||
|
||
const [menuRequest, setMenuRequest] = useState(); | ||
|
||
const displayMenu = useCallback(event => { | ||
const { userId } = event.currentTarget.dataset; | ||
|
||
if (!userId) { | ||
return; | ||
} | ||
|
||
const request = { | ||
userId, | ||
}; | ||
|
||
setMenuRequest(request); | ||
show({ event }); | ||
}, [show]); | ||
|
||
return { | ||
menuId: menuConf.id, | ||
menuRequest, | ||
displayMenu, | ||
}; | ||
}; | ||
|
||
function TournamentContextMenu({ | ||
request = { | ||
userId: null, | ||
}, | ||
menuId, | ||
// inputRef, | ||
children, | ||
}) { | ||
const dispatch = useDispatch(); | ||
|
||
const { | ||
userId, | ||
} = request; | ||
|
||
// | ||
const handleBanClick = () => { | ||
if (userId) { | ||
dispatch(); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
{children} | ||
<Menu role="menu" id={menuId}> | ||
<Item | ||
aria-label="Ban" | ||
onClick={handleBanClick} | ||
> | ||
<FontAwesomeIcon | ||
className="mr-2" | ||
icon="ban" | ||
/> | ||
<span>Ban</span> | ||
</Item> | ||
</Menu> | ||
</> | ||
); | ||
} | ||
|
||
export default memo(TournamentContextMenu); |