start using the $discord global everywhere

pull/98/head
dperolio 2 years ago
parent c93dbbe570
commit f2aa93b899
No known key found for this signature in database
GPG Key ID: 4191689562D51409

@ -1,20 +1,21 @@
// getLocale
// setLocale
// getLanguage
// getLanguages
// getMessage
// getMessages
// getMessagesByString
// getMessagesByAddon
// getAllMessages
// registerMessage
// registerMessages
// unregisterMessage
// unregisterMessages
// getMessagesByLocale
/*
* getLocale
* setLocale
* getLanguage
* getLanguages
* getMessage
* getMessages
* getMessagesByString
* getMessagesByAddon
* getAllMessages
* registerMessage
* registerMessages
* unregisterMessage
* unregisterMessages
* getMessagesByLocale
*/
import { getModule, FluxDispatcher } from '@vizality/webpack';
import { Constants } from '@discord/constants';
import { API } from '@vizality/entities';
import i18n from '@vizality/i18n';
@ -51,7 +52,7 @@ export default class I18n extends API {
async start () {
locale = getModule('locale', 'theme')?.locale;
FluxDispatcher.subscribe(Constants.ActionTypes.I18N_LOAD_SUCCESS, this._handleLocaleChange);
FluxDispatcher.subscribe($discord.constants.ActionTypes.I18N_LOAD_SUCCESS, this._handleLocaleChange);
this.injectAllStrings(__coreMessages);
}
@ -62,11 +63,13 @@ export default class I18n extends API {
* Need to store the original strings somewhere when overriding in order to revert
* on stop. Maybe this._original?
*/
// [ 'messages', 'defaultMessages' ].forEach(obj => {
// Object.keys(i18n._proxyContext[obj])
// .filter(key => Object.keys(this.messages[this.locale]).filter(k => k === key))
// .forEach(key => delete i18n._proxyContext[obj][key]);
// });
/*
* [ 'messages', 'defaultMessages' ].forEach(obj => {
* Object.keys(i18n._proxyContext[obj])
* .filter(key => Object.keys(this.messages[this.locale]).filter(k => k === key))
* .forEach(key => delete i18n._proxyContext[obj][key]);
* });
*/
this.removeAllListeners();
delete vizality.api.i18n;
}

@ -9,13 +9,11 @@
import { assertString, toSnakeCase } from '@vizality/util/string';
import { Sidebar } from '@vizality/components/dashboard';
import { Routes as _Routes } from '@discord/constants';
import { Events, Regexes } from '@vizality/constants';
import { assertObject } from '@vizality/util/object';
import { isComponent } from '@vizality/util/react';
import { getCaller } from '@vizality/util/file';
import { getModule } from '@vizality/webpack';
import { router } from '@discord/modules';
import { API } from '@vizality/entities';
import { isValidElement } from 'react';
@ -72,7 +70,7 @@ export default class Routes extends API {
history.shift();
const match = history.find(location => !location.includes('/vizality'));
const route = match.replace(new RegExp(Regexes.DISCORD), '');
router.replaceWith(route);
$discord.modules.router.replaceWith(route);
}
} catch (err) {
return this.error(this._labels.concat('restorePreviousRoute'), err);
@ -233,10 +231,10 @@ export default class Routes extends API {
if (!pathOrRouteId.startsWith('/')) {
switch (pathOrRouteId) {
case 'private': path = '/channels/@me/'; break;
case 'discover': path = _Routes.GUILD_DISCOVERY; break;
case 'friends': path = _Routes.FRIENDS; break;
case 'library': path = _Routes.APPLICATION_LIBRARY; break;
case 'nitro': path = _Routes.APPLICATION_STORE; break;
case 'discover': path = $discord.constants.Routes.GUILD_DISCOVERY; break;
case 'friends': path = $discord.constants.Routes.FRIENDS; break;
case 'library': path = $discord.constants.Routes.APPLICATION_LIBRARY; break;
case 'nitro': path = $discord.constants.Routes.APPLICATION_STORE; break;
default: path = `/vizality/${pathOrRouteId}`;
}
} else {
@ -247,7 +245,7 @@ export default class Routes extends API {
* Check if it's a Vizality route and has a # in the path.
*/
if (path.startsWith('/vizality/') && path.includes('#')) {
router.transitionTo(path);
$discord.modules.router.transitionTo(path);
const hash = path.split('#')[1];
/**
* This is bad, but currently it's the only way I really know how to do it.
@ -273,7 +271,7 @@ export default class Routes extends API {
/**
* Go to the route.
*/
return router.transitionTo(path);
return $discord.modules.router.transitionTo(path);
} catch (err) {
return this.error(err);
}
@ -340,10 +338,10 @@ export default class Routes extends API {
const location = {};
const routes = {
private: '/channels/@me/',
discover: _Routes.GUILD_DISCOVERY,
friends: _Routes.FRIENDS,
library: _Routes.APPLICATION_LIBRARY,
nitro: _Routes.APPLICATION_STORE,
discover: $discord.constants.Routes.GUILD_DISCOVERY,
friends: $discord.constants.Routes.FRIENDS,
library: $discord.constants.Routes.APPLICATION_LIBRARY,
nitro: $discord.constants.Routes.APPLICATION_STORE,
guild: '/channels/',
settings: '/vizality/settings',
plugins: '/vizality/plugins',

@ -8,7 +8,6 @@ import { isString, toKebabCase } from '@vizality/util/string';
import { getOwnerInstance } from '@vizality/util/react';
import { waitForElement } from '@vizality/util/dom';
import { patch, unpatch } from '@vizality/patcher';
import { Constants } from '@discord/constants';
import { getModule } from '@vizality/webpack';
/**
@ -16,7 +15,7 @@ import { getModule } from '@vizality/webpack';
* @see {@link https://discord.com/developers/docs/resources/channel#channel-object-channel-types|Discord}
*/
const CHANNEL_TYPES = {};
for (const type of Object.entries(Constants.ChannelTypes)) {
for (const type of Object.entries($discord.constants.ChannelTypes)) {
if (isString(type[1])) {
[ , CHANNEL_TYPES[Number(type[0])] ] = type;
}

@ -7,7 +7,6 @@
import { toHash, isString, toKebabCase } from '@vizality/util/string';
import { patch, unpatch } from '@vizality/patcher';
import { findInTree } from '@vizality/util/react';
import { Constants } from '@discord/constants';
import { getModule } from '@vizality/webpack';
import { Regexes } from '@vizality/constants';
@ -16,7 +15,7 @@ import { Regexes } from '@vizality/constants';
* @see {@link https://discord.com/developers/docs/resources/channel#message-object-message-types|Discord}
*/
const MESSAGE_TYPES = {};
for (const type of Object.entries(Constants.MessageTypes)) {
for (const type of Object.entries($discord.constants.MessageTypes)) {
if (type[0] !== '0' && isString(type[1])) {
[ , MESSAGE_TYPES[Number(type[0])] ] = type;
}

@ -5,11 +5,9 @@
*/
import { getModule, FluxDispatcher } from '@vizality/webpack';
import { Regexes, Protocols } from '@vizality/constants';
import { findInReactTree } from '@vizality/util/react';
import { patch, unpatch } from '@vizality/patcher';
import { Constants } from '@discord/constants';
import { Regexes, Protocols } from '@vizality/constants';
import { fetchUser } from '@discord/user';
export const labels = [ 'Components', 'Anchor' ];
@ -102,7 +100,7 @@ export default builtin => {
if (!userId) {
return;
}
const user = await fetchUser(userId);
const user = await $discord.users.fetchUser(userId);
if (!user) {
return vizality.api.notifications.sendToast({
id: 'VIZALITY_USER_NOT_FOUND',
@ -112,7 +110,7 @@ export default builtin => {
});
}
return FluxDispatcher.dirtyDispatch({
type: Constants.ActionTypes.USER_PROFILE_MODAL_OPEN,
type: $discord.constants.ActionTypes.USER_PROFILE_MODAL_OPEN,
userId
});
} catch (err) {

@ -5,7 +5,6 @@
*/
import { getModule } from '@vizality/webpack';
import { router } from '@discord/modules';
export const labels = [ 'Misc', 'Route' ];
@ -36,7 +35,7 @@ export default () => {
/**
* Add a route listener that will trigger handleRouteChange method on navigation.
*/
router?.listeners?.add(handleRouteChange);
$discord.modules.router.listeners.add(handleRouteChange);
/**
* Remove attributes and remove listeners on unload.
@ -45,6 +44,6 @@ export default () => {
root.removeAttribute('vz-route');
root.removeAttribute('vz-guild-id');
root.removeAttribute('vz-channel-id');
router?.listeners?.delete(handleRouteChange);
$discord.modules.router.listeners.delete(handleRouteChange);
};
};

@ -5,7 +5,6 @@
*/
import { getModule, FluxDispatcher } from '@vizality/webpack';
import { Constants } from '@discord/constants';
export const labels = [ 'Misc', 'Settings' ];
@ -41,7 +40,7 @@ export default () => {
/**
* Subscribe to Discord's user settings uppdate flux store.
*/
FluxDispatcher?.subscribe(Constants.ActionTypes.USER_SETTINGS_UPDATE, handleSettingsChange);
FluxDispatcher?.subscribe($discord.constants.ActionTypes.USER_SETTINGS_UPDATE, handleSettingsChange);
/**
* Remove attributes and unsubscribe from Flux on unload.
@ -49,6 +48,6 @@ export default () => {
return () => {
root?.removeAttribute('vz-theme');
root?.removeAttribute('vz-mode');
FluxDispatcher?.unsubscribe(Constants.ActionTypes.USER_SETTINGS_UPDATE, handleSettingsChange);
FluxDispatcher?.unsubscribe($discord.constants.ActionTypes.USER_SETTINGS_UPDATE, handleSettingsChange);
};
};

@ -1,8 +1,6 @@
import { FluxDispatcher } from '@vizality/webpack';
import { toPlural } from '@vizality/util/string';
import { Constants } from '@discord/constants';
import { error } from '@vizality/util/logger';
import { fetchUser } from '@discord/user';
import React, { memo } from 'react';
import AsyncComponent from './AsyncComponent';
@ -24,7 +22,7 @@ export default memo(({ onClick, href, className, userId, children, type, addonId
vz-user-id={userId}
vz-addon-id={addonId}
href={type === 'user' && userId
? `${window.location.origin}${Constants.Endpoints.USERS}/${userId}`
? `${window.location.origin}${$discord.constants.Endpoints.USERS}/${userId}`
: type === 'plugin' || type === 'theme' && addonId
? `${window.location.origin}/vizality/${toPlural(type)}/${addonId}}`
: href
@ -32,7 +30,7 @@ export default memo(({ onClick, href, className, userId, children, type, addonId
onClick={async evt => {
try {
/**
*
*
*/
if (!userId && !addonId && !href) {
if (!onClick) {
@ -42,7 +40,7 @@ export default memo(({ onClick, href, className, userId, children, type, addonId
}
/**
*
*
*/
if (href?.startsWith('#')) {
evt?.preventDefault?.();
@ -65,11 +63,11 @@ export default memo(({ onClick, href, className, userId, children, type, addonId
}
/**
*
*
*/
if (type === 'user') {
evt.preventDefault();
const user = await fetchUser(userId);
const user = await $discord.users.fetchUser(userId);
if (!user) {
return vizality.api.notifications.sendToast({
id: 'VIZALITY_USER_NOT_FOUND',
@ -79,13 +77,13 @@ export default memo(({ onClick, href, className, userId, children, type, addonId
});
}
return FluxDispatcher.dirtyDispatch({
type: Constants.ActionTypes.USER_PROFILE_MODAL_OPEN,
type: $discord.constants.ActionTypes.USER_PROFILE_MODAL_OPEN,
userId
});
}
/**
*
*
*/
if (type === 'plugin' || type === 'theme') {
evt.preventDefault();

@ -4,7 +4,7 @@ import { getModule } from '@vizality/webpack';
import React, { memo } from 'react';
/**
*
*
* @component
*/
export default memo(({ className, wrapperClassName, children }) => {

Loading…
Cancel
Save