Add files

This commit is contained in:
DoomRye 2022-07-26 10:06:20 -07:00
commit bb80829159
18195 changed files with 2122994 additions and 0 deletions

View file

@ -0,0 +1,99 @@
import React from 'react';
import hoistNonReactStatic from 'hoist-non-react-statics';
import {loadImage} from '../utils/ImageLoaderUtils';
const URL_REGEX = /url\(['"](.*)['"]\)/;
function getURL(url) {
if (!url || url === 'none') {
return null;
}
const match = url.match(URL_REGEX);
if (match) {
return match[1];
}
return url;
}
function makeUrlString(url) {
if (!url || url === 'none') {
return 'none';
}
return `url(${url})`;
}
export function backgroundImagePreloader(WrappedComponent) {
class BackgroundImagePreloader extends React.Component {
constructor(props) {
super(props);
const {style} = props;
// Always assume the initial asset is loaded
const cached = style ? getURL(style.backgroundImage) : null;
this.cached = [cached];
this.state = {
cached,
loaded: true,
};
}
componentWillReceiveProps(nextProps) {
const {cached} = this.state;
const {style} = nextProps;
const newURL = style ? getURL(style.backgroundImage) : null;
// Non urls require no caching
if (!newURL && newURL !== cached) {
this.setState({loaded: true, cached: newURL});
} else if (this.cached.indexOf(newURL) >= 0) {
this.setState({loaded: true, cached: newURL});
} else if (newURL && newURL !== cached) {
// We have a new URL and must load it
this.setState({loaded: false}, () => this.preloadURL(newURL));
}
}
preloadURL(url) {
if (this.canceller) {
this.canceller();
}
this.canceller = loadImage(url, err => {
if (this.canceller) {
this.canceller = null;
}
if (!err) {
this.cached.push(url);
this.setState({cached: url, loaded: true});
}
const {onBackgroundImageLoad} = this.props;
onBackgroundImageLoad && onBackgroundImageLoad(err, url);
});
}
componentWillUnmount() {
if (this.canceller) {
this.canceller();
}
this.cached.length = 0;
}
render() {
// eslint-disable-next-line no-unused-vars
let {style, onBackgroundImageLoad, ...props} = this.props;
const {loaded, cached} = this.state;
if (!loaded && style) {
style = {
...style,
backgroundImage: makeUrlString(cached),
};
}
return <WrappedComponent style={style} {...props} />;
}
}
hoistNonReactStatic(BackgroundImagePreloader, WrappedComponent);
return BackgroundImagePreloader;
}
// WEBPACK FOOTER //
// ./discord_app/containers/backgroundImagePreloader.js

View file

@ -0,0 +1,117 @@
/* 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