mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-11 03:24:16 +00:00
added user menu
This commit is contained in:
parent
3ab7b24d7d
commit
7dc84241f2
@ -1,11 +1,20 @@
|
|||||||
import React from "react"
|
import React from "react"
|
||||||
import { Button, Tooltip, Badge } from "antd"
|
import { Button, Tooltip, Badge, Dropdown } from "antd"
|
||||||
import { Icons } from "components/Icons"
|
import { Icons } from "components/Icons"
|
||||||
import LiveChat from "components/LiveChat"
|
import LiveChat from "components/LiveChat"
|
||||||
import classnames from "classnames"
|
import classnames from "classnames"
|
||||||
|
|
||||||
import "./index.less"
|
import "./index.less"
|
||||||
|
|
||||||
|
const eventsToDispatch = {
|
||||||
|
"kick": (user) => {
|
||||||
|
app.cores.sync.music.moderation.kickUser(user.user_id)
|
||||||
|
},
|
||||||
|
"transfer_owner": (user) => {
|
||||||
|
app.cores.sync.music.moderation.transferOwner(user.user_id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default class SyncRoomCard extends React.Component {
|
export default class SyncRoomCard extends React.Component {
|
||||||
state = {
|
state = {
|
||||||
roomData: {},
|
roomData: {},
|
||||||
@ -59,7 +68,7 @@ export default class SyncRoomCard extends React.Component {
|
|||||||
|
|
||||||
// chat instance
|
// chat instance
|
||||||
const chatInstance = app.cores.api.instance().wsInstances.chat
|
const chatInstance = app.cores.api.instance().wsInstances.chat
|
||||||
|
|
||||||
if (chatInstance) {
|
if (chatInstance) {
|
||||||
Object.keys(this.chatEvents).forEach((event) => {
|
Object.keys(this.chatEvents).forEach((event) => {
|
||||||
chatInstance.on(event, this.chatEvents[event])
|
chatInstance.on(event, this.chatEvents[event])
|
||||||
@ -112,6 +121,45 @@ export default class SyncRoomCard extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
generateUserMenu = (user) => {
|
||||||
|
const isSelf = user.user_id === app.userData._id
|
||||||
|
const imOwner = app.userData._id === this.state.roomData.ownerUserId
|
||||||
|
|
||||||
|
const items = []
|
||||||
|
|
||||||
|
if (!isSelf && imOwner) {
|
||||||
|
items.push({
|
||||||
|
key: "kick",
|
||||||
|
label: <>
|
||||||
|
<Icons.MdLogout /> Kick
|
||||||
|
</>,
|
||||||
|
})
|
||||||
|
|
||||||
|
items.push({
|
||||||
|
key: "transfer_owner",
|
||||||
|
label: <>
|
||||||
|
<Icons.Crown /> Transfer owner
|
||||||
|
</>,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
type: "group",
|
||||||
|
label: `@${user.username}`,
|
||||||
|
children: items,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
handleUserMenuClick = (event, user) => {
|
||||||
|
const action = eventsToDispatch[event]
|
||||||
|
|
||||||
|
if (typeof action === "function") {
|
||||||
|
action(user)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return <>
|
return <>
|
||||||
<div className="sync-room_subcard top">
|
<div className="sync-room_subcard top">
|
||||||
@ -144,9 +192,16 @@ export default class SyncRoomCard extends React.Component {
|
|||||||
<div className="sync-room_users">
|
<div className="sync-room_users">
|
||||||
{
|
{
|
||||||
Array.isArray(this.state.roomData?.connectedUsers) && this.state.roomData?.connectedUsers.map((user, index) => {
|
Array.isArray(this.state.roomData?.connectedUsers) && this.state.roomData?.connectedUsers.map((user, index) => {
|
||||||
return <Tooltip
|
return <Dropdown
|
||||||
title={user.username}
|
menu={{
|
||||||
key={index}
|
items: this.generateUserMenu(user),
|
||||||
|
onClick: (event) => {
|
||||||
|
this.handleUserMenuClick(event.key, user)
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
trigger={["click"]}
|
||||||
|
placement="top"
|
||||||
|
arrow
|
||||||
>
|
>
|
||||||
<div className="sync-room_user" key={index}>
|
<div className="sync-room_user" key={index}>
|
||||||
{
|
{
|
||||||
@ -158,7 +213,7 @@ export default class SyncRoomCard extends React.Component {
|
|||||||
<img src={user.avatar} alt={user.username} />
|
<img src={user.avatar} alt={user.username} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Tooltip>
|
</Dropdown>
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user