fix dashboard being spam added to PrivateChannelsList from recent PR

pull/106/head
dperolio 2 years ago
parent 6c34a027ca
commit 9fa8679e3d
No known key found for this signature in database
GPG Key ID: 4191689562D51409

@ -20,26 +20,26 @@ export default class Dashboard extends Builtin {
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async start () { async start () {
this.injectStyles('styles/main.scss'); super.injectStyles('styles/main.scss');
this._injectPrivateTab(); this._injectPrivateTab();
// this.injectGuildHomeButton(); // this.injectGuildHomeButton();
vizality.api.routes.registerRoute({ $vz.api.routes.registerRoute({
id: 'dashboard', id: 'dashboard',
path: '', path: '',
render: Routes render: Routes
}); });
vizality.api.actions.registerAction('VIZALITY_CLOSE_DASHBOARD', this._leaveDashboard.bind(this)); $vz.api.actions.registerAction('VIZALITY_CLOSE_DASHBOARD', this._leaveDashboard.bind(this));
vizality.api.actions.registerAction('VIZALITY_TOGGLE_DASHBOARD', this._toggleDashboard.bind(this)); $vz.api.actions.registerAction('VIZALITY_TOGGLE_DASHBOARD', this._toggleDashboard.bind(this));
vizality.api.keybinds.registerKeybind({ $vz.api.keybinds.registerKeybind({
id: 'VIZALITY_CLOSE_DASHBOARD', id: 'VIZALITY_CLOSE_DASHBOARD',
shortcut: 'esc', shortcut: 'esc',
executor: this._leaveDashboard.bind(this) executor: this._leaveDashboard.bind(this)
}); });
vizality.api.keybinds.registerKeybind({ $vz.api.keybinds.registerKeybind({
id: 'VIZALITY_TOGGLE_DASHBOARD', id: 'VIZALITY_TOGGLE_DASHBOARD',
shortcut: 'alt+v', shortcut: 'alt+v',
executor: this._toggleDashboard.bind(this) executor: this._toggleDashboard.bind(this)
@ -51,11 +51,11 @@ export default class Dashboard extends Builtin {
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async stop () { async stop () {
vizality.api.routes.unregisterRoute('dashboard'); $vz.api.routes.unregisterRoute('dashboard');
vizality.api.actions.unregisterAction('VIZALITY_CLOSE_DASHBOARD'); $vz.api.actions.unregisterAction('VIZALITY_CLOSE_DASHBOARD');
vizality.api.actions.unregisterAction('VIZALITY_TOGGLE_DASHBOARD'); $vz.api.actions.unregisterAction('VIZALITY_TOGGLE_DASHBOARD');
vizality.api.keybinds.unregisterKeybind('VIZALITY_CLOSE_DASHBOARD'); $vz.api.keybinds.unregisterKeybind('VIZALITY_CLOSE_DASHBOARD');
vizality.api.keybinds.unregisterKeybind('VIZALITY_TOGGLE_DASHBOARD'); $vz.api.keybinds.unregisterKeybind('VIZALITY_TOGGLE_DASHBOARD');
unpatch('vz-dashboard-private-channels-list-item'); unpatch('vz-dashboard-private-channels-list-item');
} }
@ -65,7 +65,7 @@ export default class Dashboard extends Builtin {
*/ */
_leaveDashboard () { _leaveDashboard () {
try { try {
return vizality.api.routes.restorePreviousRoute(); return $vz.api.routes.restorePreviousRoute();
} catch (err) { } catch (err) {
return this.error(this._labels.concat('_leaveDashboard'), err); return this.error(this._labels.concat('_leaveDashboard'), err);
} }
@ -78,11 +78,11 @@ export default class Dashboard extends Builtin {
*/ */
_toggleDashboard () { _toggleDashboard () {
try { try {
const currentRoute = vizality.api.routes.getLocation(); const currentRoute = $vz.api.routes.getLocation();
if (currentRoute?.pathname?.startsWith('/vizality')) { if (currentRoute?.pathname?.startsWith('/vizality')) {
return this._leaveDashboard(); return this._leaveDashboard();
} }
return vizality.api.routes.navigateTo('dashboard'); return $vz.api.routes.navigateTo('dashboard');
} catch (err) { } catch (err) {
return this.error(this._labels.concat('_toggleDashboard'), err); return this.error(this._labels.concat('_toggleDashboard'), err);
} }
@ -91,7 +91,6 @@ export default class Dashboard extends Builtin {
/** /**
* Patches the private channels list to add a button just above the Friends button * Patches the private channels list to add a button just above the Friends button
* that takes you to the Vizality dashboard. * that takes you to the Vizality dashboard.
* @returns {void}
*/ */
_injectPrivateTab () { _injectPrivateTab () {
try { try {
@ -100,19 +99,30 @@ export default class Dashboard extends Builtin {
const { LinkButton } = getModule('LinkButton'); const { LinkButton } = getModule('LinkButton');
patch('vz-dashboard-private-channels-list-item', ConnectedPrivateChannelsList, 'default', (_, res) => { patch('vz-dashboard-private-channels-list-item', ConnectedPrivateChannelsList, 'default', (_, res) => {
try { try {
const { children: list } = findInReactTree(res, (c) => c.channels); const { children: PrivateChannelsList } = findInReactTree(res, props => props.channels);
if (!list) return; /**
* Make sure the PrivateChannelsList is found.
list.unshift( */
<LinkButton if (!PrivateChannelsList) {
icon={() => <Icon name='vizality' />} return;
route='/vizality' }
text='Dashboard'
selected={vizality.api.routes.getLocation()?.pathname?.startsWith('/vizality')} /**
onContextMenu={evt => openContextMenu(evt, () => <SettingsContextMenu />)} * Make sure there's a Dashboard button in the PrivateChannelsList, otherwise
/> * prepend one.
); */
if (!PrivateChannelsList.some(channel => channel.props?.text === 'Dashboard')) {
PrivateChannelsList.unshift(
<LinkButton
icon={() => <Icon name='vizality' />}
route='/vizality'
text='Dashboard'
selected={$vz.api.routes.getLocation().pathname.startsWith('/vizality')}
onContextMenu={evt => openContextMenu(evt, () => <SettingsContextMenu />)}
/>
);
}
} catch (err) { } catch (err) {
return this.error(this._labels.concat('_injectPrivateTab'), err); return this.error(this._labels.concat('_injectPrivateTab'), err);
} }

Loading…
Cancel
Save