From 725a9b34038a7b4463313e93885a9932d298883d Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 17 Apr 2020 17:14:04 -0500 Subject: [PATCH] Pull meUsername from Redux --- .../features/compose/components/action_bar.js | 13 ++++++++++--- app/gabsocial/features/favourited_statuses/index.js | 3 ++- app/gabsocial/features/pinned_statuses/index.js | 3 ++- app/gabsocial/features/ui/index.js | 11 +++++++++-- app/gabsocial/initial_state.js | 1 - 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/app/gabsocial/features/compose/components/action_bar.js b/app/gabsocial/features/compose/components/action_bar.js index e533f271e..fee214477 100644 --- a/app/gabsocial/features/compose/components/action_bar.js +++ b/app/gabsocial/features/compose/components/action_bar.js @@ -4,7 +4,6 @@ import { openModal } from '../../../actions/modal'; import PropTypes from 'prop-types'; import DropdownMenuContainer from '../../../containers/dropdown_menu_container'; import { defineMessages, injectIntl } from 'react-intl'; -import { meUsername } from 'gabsocial/initial_state'; import { logOut } from 'gabsocial/actions/auth'; const messages = defineMessages({ @@ -20,6 +19,13 @@ const messages = defineMessages({ keyboard_shortcuts: { id: 'navigation_bar.keyboard_shortcuts', defaultMessage: 'Hotkeys' }, }); +const mapStateToProps = state => { + const me = state.get('me'); + return { + meUsername: state.getIn(['accounts', me, 'username']), + }; +}; + const mapDispatchToProps = (dispatch) => ({ onOpenHotkeys() { dispatch(openModal('HOTKEYS')); @@ -37,6 +43,7 @@ class ActionBar extends React.PureComponent { size: PropTypes.number, onOpenHotkeys: PropTypes.func.isRequired, onClickLogOut: PropTypes.func.isRequired, + meUsername: PropTypes.string, }; handleHotkeyClick = () => { @@ -44,7 +51,7 @@ class ActionBar extends React.PureComponent { } render() { - const { intl, onClickLogOut } = this.props; + const { intl, onClickLogOut, meUsername } = this.props; const size = this.props.size || 16; let menu = []; @@ -73,4 +80,4 @@ class ActionBar extends React.PureComponent { } -export default injectIntl(connect(null, mapDispatchToProps)(ActionBar)); +export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(ActionBar)); diff --git a/app/gabsocial/features/favourited_statuses/index.js b/app/gabsocial/features/favourited_statuses/index.js index c503374fe..d613df21e 100644 --- a/app/gabsocial/features/favourited_statuses/index.js +++ b/app/gabsocial/features/favourited_statuses/index.js @@ -8,10 +8,11 @@ import StatusList from '../../components/status_list'; import { injectIntl, FormattedMessage } from 'react-intl'; import ImmutablePureComponent from 'react-immutable-pure-component'; import { debounce } from 'lodash'; -import { meUsername } from 'gabsocial/initial_state'; import MissingIndicator from 'gabsocial/components/missing_indicator'; const mapStateToProps = (state, { params: { username } }) => { + const me = state.get('me'); + const meUsername = state.getIn(['accounts', me, 'username']); return { isMyAccount: (username.toLowerCase() === meUsername.toLowerCase()), statusIds: state.getIn(['status_lists', 'favourites', 'items']), diff --git a/app/gabsocial/features/pinned_statuses/index.js b/app/gabsocial/features/pinned_statuses/index.js index be10e2914..689191b6c 100644 --- a/app/gabsocial/features/pinned_statuses/index.js +++ b/app/gabsocial/features/pinned_statuses/index.js @@ -7,10 +7,11 @@ import Column from '../ui/components/column'; import StatusList from '../../components/status_list'; import { injectIntl, FormattedMessage } from 'react-intl'; import ImmutablePureComponent from 'react-immutable-pure-component'; -import { meUsername } from 'gabsocial/initial_state'; import MissingIndicator from 'gabsocial/components/missing_indicator'; const mapStateToProps = (state, { params: { username } }) => { + const me = state.get('me'); + const meUsername = state.getIn(['accounts', me, 'username']); return { isMyAccount: (username.toLowerCase() === meUsername.toLowerCase()), statusIds: state.getIn(['status_lists', 'pins', 'items']), diff --git a/app/gabsocial/features/ui/index.js b/app/gabsocial/features/ui/index.js index 969ed379c..f0e6cbfe3 100644 --- a/app/gabsocial/features/ui/index.js +++ b/app/gabsocial/features/ui/index.js @@ -68,7 +68,6 @@ import { LoginPage, Preferences, } from './util/async-components'; -import { meUsername } from '../../initial_state'; // Dummy import, to make sure that ends up in the application bundle. // Without this it ends up in ~8 very commonly used bundles. @@ -80,14 +79,18 @@ const messages = defineMessages({ }); const mapStateToProps = state => { + const me = state.get('me'); + const meUsername = state.getIn(['accounts', me, 'username']); + return { isComposing: state.getIn(['compose', 'is_composing']), hasComposingText: state.getIn(['compose', 'text']).trim().length !== 0, hasMediaAttachments: state.getIn(['compose', 'media_attachments']).size > 0, dropdownMenuIsOpen: state.getIn(['dropdown_menu', 'openId']) !== null, - me: state.get('me'), accessToken: state.getIn(['auth', 'user', 'access_token']), streamingUrl: state.getIn(['instance', 'urls', 'streaming_api']), + me, + meUsername, }; }; @@ -261,6 +264,7 @@ class UI extends React.PureComponent { dropdownMenuIsOpen: PropTypes.bool, me: PropTypes.string, streamingUrl: PropTypes.string, + meUsername: PropTypes.string, }; state = { @@ -504,14 +508,17 @@ class UI extends React.PureComponent { } handleHotkeyGoToFavourites = () => { + const { meUsername } = this.props; this.context.router.history.push(`/${meUsername}/favorites`); } handleHotkeyGoToPinned = () => { + const { meUsername } = this.props; this.context.router.history.push(`/${meUsername}/pins`); } handleHotkeyGoToProfile = () => { + const { meUsername } = this.props; this.context.router.history.push(`/${meUsername}`); } diff --git a/app/gabsocial/initial_state.js b/app/gabsocial/initial_state.js index aa1d6798c..bb812bbc5 100644 --- a/app/gabsocial/initial_state.js +++ b/app/gabsocial/initial_state.js @@ -11,7 +11,6 @@ export const unfollowModal = getMeta('unfollow_modal'); export const boostModal = getMeta('boost_modal'); export const deleteModal = getMeta('delete_modal'); export const me = getMeta('me'); -export const meUsername = getMeta('username'); export const searchEnabled = getMeta('search_enabled'); export const invitesEnabled = getMeta('invites_enabled'); export const repository = getMeta('repository');