From b159d31eeaaf5bdbb69e34fc5a86e3ee3dd8a429 Mon Sep 17 00:00:00 2001 From: 1Lighty <49841131+1Lighty@users.noreply.github.com> Date: Sat, 26 Jun 2021 06:09:52 +0200 Subject: [PATCH] Fix performance issues, updating issues and a UX issue (#6) * fix possible failure bricking updating on pc * fix constant hard rerendering issues * fix webpack search in render and rerendering issue * make UX slightly better by adding min height * bump version --- components/TypingIndicator.jsx | 23 +++++++++++++--------- index.js | 35 ++++++++++++++++++++++------------ manifest.json | 4 ++-- stores/dmTypingStore.js | 3 ++- style.css | 1 + 5 files changed, 42 insertions(+), 24 deletions(-) diff --git a/components/TypingIndicator.jsx b/components/TypingIndicator.jsx index 3f19a75..bf97609 100644 --- a/components/TypingIndicator.jsx +++ b/components/TypingIndicator.jsx @@ -2,27 +2,32 @@ const { React, getModule, i18n: { Messages }, constants: { Routes } } = require('powercord/webpack'); const { Tooltip, Spinner } = require('powercord/components'); +const ChannelStore = getModule([ 'hasChannel' ], false); +const ChannelUtils = getModule([ 'openPrivateChannel' ], false); +const Router = getModule([ 'transitionTo' ], false); + module.exports = class TypingIndicator extends React.PureComponent { constructor (props) { super(props); this.getSetting = props.getSetting; - this.channelStore = getModule([ 'hasChannel' ], false); - this.channelUtils = getModule([ 'openPrivateChannel' ], false); - this.transitionTo = getModule([ 'transitionTo'], false).transitionTo; + // bind has to happen here, if you do bind in render, then it will just + // rerender every single time needlessly + this.handleOpenPrivateChannel = this.handleOpenPrivateChannel.bind(this); } - async handleOpenPrivateChannel (typingUsers, user) { + handleOpenPrivateChannel () { + const { typingUsers, typingUsersFlat: [ user ] } = this.props; const channelIds = Object.keys(typingUsers); - const privateGroupChannel = Object.values(this.channelStore.getMutablePrivateChannels()).find(channel => ( + const privateGroupChannel = Object.values(ChannelStore.getMutablePrivateChannels()).find(channel => ( channel.isGroupDM() && channel.id === channelIds[0] )); if (privateGroupChannel) { - return this.transitionTo(Routes.CHANNEL('@me', privateGroupChannel.id)); + return Router.transitionTo(Routes.CHANNEL('@me', privateGroupChannel.id)); } - return this.channelUtils.openPrivateChannel(user.id); + return ChannelUtils.openPrivateChannel(user.id); } formatUsernames () { @@ -91,7 +96,7 @@ module.exports = class TypingIndicator extends React.PureComponent { } render () { - const { clickable, typingUsers, typingUsersFlat } = this.props; + const { clickable, typingUsersFlat } = this.props; if (typingUsersFlat.length === 0) return null; @@ -102,7 +107,7 @@ module.exports = class TypingIndicator extends React.PureComponent { return ; } - return
+ return
({ + typingUsers, + typingUsersFlat, + ...powercord.api.settings._fluxProps('dm-typing-indicator') + }))(TypingIndicator); + inject('dm-typing-indicator', HomeButtonsModule, 'DefaultHomeButton', ([ props ], res) => { if (!Array.isArray(res)) res = [ res ]; @@ -48,12 +63,6 @@ module.exports = class DMTypingIndicator extends Plugin { const typingUsersFlat = props.typingUsersFlat || dmTypingStore.getFlattenedDMTypingUsers(); const typingUsers = props.typingUsers || dmTypingStore.getDMTypingUsers(); - const ConnectedTypingIndicator = Flux.connectStores([ powercord.api.settings.store, dmTypingStore ], () => ({ - typingUsers, - typingUsersFlat, - ...powercord.api.settings._fluxProps('dm-typing-indicator') - }))(TypingIndicator); - const indicatorStyle = this.settings.get('indicatorStyle', 'icon'); const hideWhenViewed = this.settings.get('hideWhenViewed', true); @@ -66,11 +75,13 @@ module.exports = class DMTypingIndicator extends Plugin { if (badgeContainer && indicatorStyle === 'badge' && typingUsersFlat.length > 0) { badgeContainer.props.lowerBadgeWidth = 28; - badgeContainer.props.lowerBadge = React.createElement(ConnectedTypingIndicator, { badge: true }); + badgeContainer.props.lowerBadge = React.createElement(ConnectedTypingIndicator, { badge: true, typingUsersFlat, typingUsers }); } else { res.splice(1, 0, React.createElement(ConnectedTypingIndicator, { className: this.classes.listItem, - clickable: typingUsersFlat.length === 1 + clickable: typingUsersFlat.length === 1, + typingUsersFlat, + typingUsers })); } diff --git a/manifest.json b/manifest.json index 60e9767..5738439 100644 --- a/manifest.json +++ b/manifest.json @@ -3,5 +3,5 @@ "description": "Displays whenever a user is typing in your DMs.", "author": "Moth, M|-|4r13y ツ", "license": "MIT", - "version": "3.1.8" -} + "version": "3.1.9" +} \ No newline at end of file diff --git a/stores/dmTypingStore.js b/stores/dmTypingStore.js index a0ae8ae..e557421 100644 --- a/stores/dmTypingStore.js +++ b/stores/dmTypingStore.js @@ -3,7 +3,8 @@ const { Flux, FluxDispatcher, getModule } = require('powercord/webpack'); const { forceUpdateElement } = require('powercord/util'); const { getSetting } = powercord.api.settings._fluxProps('dm-typing-indicator'); -const { tutorialContainer } = getModule([ 'homeIcon', 'downloadProgress' ], false); +// use an || {}, otherwise plugin will fail to construct and you won't be able to update it +const { tutorialContainer } = getModule([ 'homeIcon', 'downloadProgress' ], false) || (console.error('tutorialContainer not found in DM-Typing-Indicator!'), { tutorialContainer: 'CLASSNOTFOUND' }); const privateChannelStore = getModule([ 'getPrivateChannelIds' ], false); const relationshipStore = getModule([ 'isBlocked', 'isFriend' ], false); diff --git a/style.css b/style.css index bbdc31a..561ed8b 100644 --- a/style.css +++ b/style.css @@ -6,6 +6,7 @@ text-transform: uppercase; word-wrap: normal; width: 62px; + min-height: 10px; color: var(--text-muted); }