diff --git a/share_extension/android/extension.js b/share_extension/android/extension.js index e8ab2c442..6e79a8b67 100644 --- a/share_extension/android/extension.js +++ b/share_extension/android/extension.js @@ -2,7 +2,6 @@ // See LICENSE.txt for license information. import React, {PureComponent} from 'react'; -import PropTypes from 'prop-types'; import {Alert, NativeModules} from 'react-native'; import {intlShape} from 'react-intl'; @@ -15,7 +14,6 @@ const ShareExtension = NativeModules.MattermostShare; export default class ShareApp extends PureComponent { static contextTypes = { intl: intlShape, - store: PropTypes.object.isRequired, }; constructor(props) { diff --git a/share_extension/android/index.js b/share_extension/android/index.js index a360732d8..a32f1a6cd 100644 --- a/share_extension/android/index.js +++ b/share_extension/android/index.js @@ -8,9 +8,8 @@ import {IntlProvider} from 'react-intl'; import {Client4} from 'mattermost-redux/client'; import {getTranslations} from 'app/i18n'; -import initialState from 'app/initial_state'; import {getCurrentLocale} from 'app/selectors/i18n'; -import configureStore from 'app/store'; +import {store} from 'app/mattermost'; import {extensionSelectTeamId} from './actions'; import Extension from './extension'; @@ -19,25 +18,41 @@ export default class ShareApp extends PureComponent { constructor() { super(); - this.store = configureStore(initialState); - this.unsubscribeFromStore = this.store.subscribe(this.listenForHydration); - this.state = {init: false}; + const st = store.getState(); + if (st?.views?.root?.hydrationComplete) { + this.state = {init: true}; + this.listenForHydration(); + } else { + this.unsubscribeFromStore = store.subscribe(this.listenForHydration); + this.state = {init: false}; + } + } + + componentDidMount() { + this.mounted = true; } listenForHydration = () => { - const {dispatch, getState} = this.store; + const {dispatch, getState} = store; const state = getState(); if (state.views.root.hydrationComplete) { const {credentials} = state.entities.general; const {currentTeamId} = state.entities.teams; - this.unsubscribeFromStore(); + if (this.unsubscribeFromStore) { + this.unsubscribeFromStore(); + } + if (credentials.token && credentials.url) { Client4.setToken(credentials.token); Client4.setUrl(credentials.url); } - extensionSelectTeamId(currentTeamId)(dispatch, getState); - this.setState({init: true}); + + dispatch(extensionSelectTeamId(currentTeamId)); + + if (this.mounted) { + this.setState({init: true}); + } } }; @@ -46,10 +61,10 @@ export default class ShareApp extends PureComponent { return null; } - const locale = getCurrentLocale(this.store.getState()); + const locale = getCurrentLocale(store.getState()); return ( - + { + return teamChannelIds.reduce((publicChannels, id) => { if (!myMembers[id]) { - return false; + return publicChannels; } + const channel = channels[id]; - return teamChannelIds.includes(id) && channel.type === General.OPEN_CHANNEL; - }).map((id) => channels[id]).sort(sortChannelsByDisplayName.bind(null, locale)); - return publicChannels; + if (channel.type === General.OPEN_CHANNEL) { + publicChannels.push(channel); + } + + return publicChannels; + }, []).sort(sortChannelsByDisplayName.bind(null, locale)); } ); @@ -74,14 +78,18 @@ export const getExtensionSortedPrivateChannels = createSelector( } const locale = currentUser.locale || 'en'; - const publicChannels = teamChannelIds.filter((id) => { + return teamChannelIds.reduce((privateChannels, id) => { if (!myMembers[id]) { - return false; + return privateChannels; } + const channel = channels[id]; - return teamChannelIds.includes(id) && channel.type === General.PRIVATE_CHANNEL; - }).map((id) => channels[id]).sort(sortChannelsByDisplayName.bind(null, locale)); - return publicChannels; + if (channel.type === General.PRIVATE_CHANNEL) { + privateChannels.push(channel); + } + + return privateChannels; + }, []).sort(sortChannelsByDisplayName.bind(null, locale)); } );