117 lines
3 KiB
JavaScript
Executable file
117 lines
3 KiB
JavaScript
Executable file
/* eslint-disable no-unused-vars */
|
|
import {DragSource, DropTarget} from 'react-dnd';
|
|
|
|
import UserStore from '../stores/UserStore';
|
|
import GuildChannelStore from '../stores/views/GuildChannelStore';
|
|
import GuildStore from '../stores/GuildStore';
|
|
|
|
import GuildActionCreators from '../actions/GuildActionCreators';
|
|
|
|
import PermissionUtils from '../utils/PermissionUtils';
|
|
import DragAndDropUtils from '../utils/DragAndDropUtils';
|
|
|
|
import {ChannelTypes, Permissions} from '../Constants';
|
|
|
|
const DRAG_USER = 'DRAG_USER';
|
|
|
|
export function makeChannelSortable(type, component) {
|
|
return DropTarget(
|
|
`draggable-channel-${type}`,
|
|
{
|
|
drop({channel, position}, monitor) {
|
|
const updates = DragAndDropUtils.getPositionUpdates(
|
|
GuildChannelStore.getChannels(channel.getGuildId())[type],
|
|
monitor.getItem().position,
|
|
position,
|
|
obj => obj.channel.id,
|
|
obj => obj.channel.position
|
|
);
|
|
|
|
if (updates.length > 0) {
|
|
GuildActionCreators.batchChannelUpdate(channel.getGuildId(), updates);
|
|
}
|
|
},
|
|
},
|
|
(connect, monitor) => {
|
|
return {
|
|
connectChannelDropTarget: connect.dropTarget(),
|
|
sorting: monitor.isOver() && monitor.canDrop(),
|
|
sortingPosition: monitor.isOver() && monitor.getItem().position,
|
|
};
|
|
}
|
|
)(
|
|
DragSource(
|
|
`draggable-channel-${type}`,
|
|
{
|
|
canDrag({channel, collapsed}) {
|
|
if (collapsed && channel.type === ChannelTypes.GUILD_TEXT) {
|
|
return false;
|
|
}
|
|
return PermissionUtils.can(Permissions.MANAGE_CHANNELS, UserStore.getCurrentUser(), channel);
|
|
},
|
|
|
|
beginDrag(props) {
|
|
return {
|
|
id: props.channel.id,
|
|
position: props.position,
|
|
};
|
|
},
|
|
},
|
|
connect => {
|
|
return {
|
|
connectChannelDragSource: connect.dragSource(),
|
|
connectDragPreview: connect.dragPreview(),
|
|
};
|
|
}
|
|
)(component)
|
|
);
|
|
}
|
|
|
|
export function makeVoiceUserDroppable(component) {
|
|
return DropTarget(
|
|
DRAG_USER,
|
|
{
|
|
canDrop({channel}, monitor) {
|
|
return (
|
|
PermissionUtils.can(Permissions.CONNECT, monitor.getItem().user, channel) ||
|
|
PermissionUtils.can(Permissions.MOVE_MEMBERS, UserStore.getCurrentUser(), channel)
|
|
);
|
|
},
|
|
|
|
drop({channel}, monitor) {
|
|
GuildActionCreators.setChannel(channel.getGuildId(), monitor.getItem().user.id, channel.id);
|
|
},
|
|
},
|
|
(connect, monitor) => {
|
|
return {
|
|
connectUserDropTarget: connect.dropTarget(),
|
|
isUserOver: monitor.isOver() && monitor.canDrop(),
|
|
};
|
|
}
|
|
)(component);
|
|
}
|
|
|
|
export function makeVoiceUserDraggable(component) {
|
|
return DragSource(
|
|
DRAG_USER,
|
|
{
|
|
canDrag({canDrag}) {
|
|
return canDrag;
|
|
},
|
|
|
|
beginDrag({user}) {
|
|
return {user};
|
|
},
|
|
},
|
|
connect => {
|
|
return {
|
|
connectUserDragSource: connect.dragSource(),
|
|
};
|
|
}
|
|
)(component);
|
|
}
|
|
|
|
|
|
|
|
// WEBPACK FOOTER //
|
|
// ./discord_app/containers/makeDraggable.js
|