|
|
|
@ -4,11 +4,12 @@
|
|
|
|
|
* @memberof Builtin.Enhancements.Components
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { getModule, FluxDispatcher } from '@vizality/webpack';
|
|
|
|
|
import { findInReactTree } from '@vizality/util/react';
|
|
|
|
|
import { patch, unpatch } from '@vizality/patcher';
|
|
|
|
|
import { getModule } from '@vizality/webpack';
|
|
|
|
|
import { Regexes } from '@vizality/constants';
|
|
|
|
|
import { fetchUser } from '@discord/user';
|
|
|
|
|
import { Constants } from '@discord/util';
|
|
|
|
|
|
|
|
|
|
export const labels = [ 'Components', 'Anchor' ];
|
|
|
|
|
|
|
|
|
@ -23,49 +24,72 @@ export default builtin => {
|
|
|
|
|
patch('vz-attributes-anchors', Anchor, 'default', (_, res) => {
|
|
|
|
|
try {
|
|
|
|
|
const props = findInReactTree(res, r => r.className?.includes(anchor) && r.href);
|
|
|
|
|
if (!props) return;
|
|
|
|
|
if (!props) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Force Vizality route links open within the app.
|
|
|
|
|
*/
|
|
|
|
|
if (vizalityRegex.test(props.href)) {
|
|
|
|
|
const route = props.href?.replace(discordRegex, '');
|
|
|
|
|
props.onClick = e => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
vizality.api.routes.navigateTo(route);
|
|
|
|
|
props.onClick = evt => {
|
|
|
|
|
try {
|
|
|
|
|
evt.preventDefault();
|
|
|
|
|
vizality.api.routes.navigateTo(route);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
return builtin.error(builtin._labels.concat(labels), err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Force Vizality protocol links open within the app.
|
|
|
|
|
*/
|
|
|
|
|
if (vizalityProtocolRegex.test(props.href)) {
|
|
|
|
|
const route = props.href?.replace(vizalityProtocolRegex, '');
|
|
|
|
|
props.onClick = e => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
vizality.api.routes.navigateTo(`/vizality/${route}`);
|
|
|
|
|
props.onClick = evt => {
|
|
|
|
|
try {
|
|
|
|
|
evt.preventDefault();
|
|
|
|
|
vizality.api.routes.navigateTo(`/vizality/${route}`);
|
|
|
|
|
} catch (err) {
|
|
|
|
|
return builtin.error(builtin._labels.concat(labels), err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Force user links open in user profile modals within the app.
|
|
|
|
|
*/
|
|
|
|
|
if (userRegex.test(props.href)) {
|
|
|
|
|
const userId = props.href?.replace(userRegex, '');
|
|
|
|
|
props.onClick = e => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
if (!userId) return;
|
|
|
|
|
fetchUser(userId)
|
|
|
|
|
.then(() => getModule('open', 'fetchProfile')?.open(userId))
|
|
|
|
|
.catch(() => vizality.api.notifications.sendToast({
|
|
|
|
|
id: 'VIZALITY_USER_NOT_FOUND',
|
|
|
|
|
header: 'User Not Found',
|
|
|
|
|
type: 'User Not Found',
|
|
|
|
|
content: 'That user was unable to be located.',
|
|
|
|
|
icon: 'PersonRemove'
|
|
|
|
|
}));
|
|
|
|
|
props.onClick = async evt => {
|
|
|
|
|
try {
|
|
|
|
|
evt.preventDefault();
|
|
|
|
|
if (!userId) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const user = await fetchUser(userId);
|
|
|
|
|
if (!user) {
|
|
|
|
|
return vizality.api.notifications.sendToast({
|
|
|
|
|
id: 'VIZALITY_USER_NOT_FOUND',
|
|
|
|
|
header: 'User Not Found',
|
|
|
|
|
content: 'That user was unable to be located.',
|
|
|
|
|
icon: 'PersonRemove'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return FluxDispatcher.dirtyDispatch({
|
|
|
|
|
type: Constants.ActionTypes.USER_PROFILE_MODAL_OPEN,
|
|
|
|
|
userId
|
|
|
|
|
});
|
|
|
|
|
} catch (err) {
|
|
|
|
|
return builtin.error(builtin._labels.concat(labels), err);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
|
|
|
|
return builtin.error(builtin._labels.concat(labels), err);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return () => unpatch('vz-attributes-anchors');
|
|
|
|
|
};
|
|
|
|
|