Pull meUsername from Redux

This commit is contained in:
Alex Gleason 2020-04-17 17:14:04 -05:00
parent 08d95c83a7
commit 725a9b3403
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
5 changed files with 23 additions and 8 deletions

View file

@ -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));

View file

@ -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']),

View file

@ -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']),

View file

@ -68,7 +68,6 @@ import {
LoginPage,
Preferences,
} from './util/async-components';
import { meUsername } from '../../initial_state';
// Dummy import, to make sure that <Status /> 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}`);
}

View file

@ -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');