Profile: start refactoring findAccountByUsername logic
This commit is contained in:
parent
282b6ae2cf
commit
079736e199
7 changed files with 20 additions and 13 deletions
|
@ -10,7 +10,7 @@ import { expandAccountMediaTimeline } from '../../actions/timelines';
|
|||
import LoadingIndicator from 'soapbox/components/loading_indicator';
|
||||
import Column from '../ui/components/column';
|
||||
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||
import { getAccountGallery } from 'soapbox/selectors';
|
||||
import { getAccountGallery, findAccountByUsername } from 'soapbox/selectors';
|
||||
import MediaItem from './components/media_item';
|
||||
import LoadMore from 'soapbox/components/load_more';
|
||||
import MissingIndicator from 'soapbox/components/missing_indicator';
|
||||
|
@ -21,7 +21,6 @@ import { FormattedMessage } from 'react-intl';
|
|||
const mapStateToProps = (state, { params, withReplies = false }) => {
|
||||
const username = params.username || '';
|
||||
const me = state.get('me');
|
||||
const accounts = state.getIn(['accounts']);
|
||||
const accountFetchError = (state.getIn(['accounts', -1, 'username'], '').toLowerCase() === username.toLowerCase());
|
||||
|
||||
let accountId = -1;
|
||||
|
@ -29,7 +28,7 @@ const mapStateToProps = (state, { params, withReplies = false }) => {
|
|||
if (accountFetchError) {
|
||||
accountId = null;
|
||||
} else {
|
||||
const account = accounts.find(acct => username.toLowerCase() === acct.getIn(['acct'], '').toLowerCase());
|
||||
const account = findAccountByUsername(state, username);
|
||||
accountId = account ? account.getIn(['id'], null) : -1;
|
||||
accountUsername = account ? account.getIn(['acct'], '') : '';
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ import { NavLink } from 'react-router-dom';
|
|||
import { fetchPatronAccount } from '../../actions/patron';
|
||||
import { getSoapboxConfig } from 'soapbox/actions/soapbox';
|
||||
import { getSettings } from 'soapbox/actions/settings';
|
||||
import { makeGetStatusIds } from 'soapbox/selectors';
|
||||
import { makeGetStatusIds, findAccountByUsername } from 'soapbox/selectors';
|
||||
import classNames from 'classnames';
|
||||
|
||||
const makeMapStateToProps = () => {
|
||||
|
@ -27,7 +27,6 @@ const makeMapStateToProps = () => {
|
|||
const mapStateToProps = (state, { params, withReplies = false }) => {
|
||||
const username = params.username || '';
|
||||
const me = state.get('me');
|
||||
const accounts = state.getIn(['accounts']);
|
||||
const accountFetchError = (state.getIn(['accounts', -1, 'username'], '').toLowerCase() === username.toLowerCase());
|
||||
const soapboxConfig = getSoapboxConfig(state);
|
||||
|
||||
|
@ -37,7 +36,7 @@ const makeMapStateToProps = () => {
|
|||
if (accountFetchError) {
|
||||
accountId = null;
|
||||
} else {
|
||||
const account = accounts.find(acct => username.toLowerCase() === acct.getIn(['acct'], '').toLowerCase());
|
||||
const account = findAccountByUsername(state, username);
|
||||
accountId = account ? account.getIn(['id'], null) : -1;
|
||||
accountUsername = account ? account.getIn(['acct'], '') : '';
|
||||
accountApId = account ? account.get('url') : '';
|
||||
|
|
|
@ -11,6 +11,7 @@ import { debounce } from 'lodash';
|
|||
import MissingIndicator from 'soapbox/components/missing_indicator';
|
||||
import { fetchAccount, fetchAccountByUsername } from '../../actions/accounts';
|
||||
import LoadingIndicator from '../../components/loading_indicator';
|
||||
import { findAccountByUsername } from 'soapbox/selectors';
|
||||
|
||||
const mapStateToProps = (state, { params }) => {
|
||||
const username = params.username || '';
|
||||
|
@ -28,14 +29,13 @@ const mapStateToProps = (state, { params }) => {
|
|||
};
|
||||
}
|
||||
|
||||
const accounts = state.getIn(['accounts']);
|
||||
const accountFetchError = (state.getIn(['accounts', -1, 'username'], '').toLowerCase() === username.toLowerCase());
|
||||
|
||||
let accountId = -1;
|
||||
if (accountFetchError) {
|
||||
accountId = null;
|
||||
} else {
|
||||
const account = accounts.find(acct => username.toLowerCase() === acct.getIn(['acct'], '').toLowerCase());
|
||||
const account = findAccountByUsername(state, username);
|
||||
accountId = account ? account.getIn(['id'], null) : -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,18 +17,18 @@ import Column from '../ui/components/column';
|
|||
import ScrollableList from '../../components/scrollable_list';
|
||||
import MissingIndicator from 'soapbox/components/missing_indicator';
|
||||
import { getFollowDifference } from 'soapbox/utils/accounts';
|
||||
import { findAccountByUsername } from 'soapbox/selectors';
|
||||
|
||||
const mapStateToProps = (state, { params, withReplies = false }) => {
|
||||
const username = params.username || '';
|
||||
const me = state.get('me');
|
||||
const accounts = state.getIn(['accounts']);
|
||||
const accountFetchError = (state.getIn(['accounts', -1, 'username'], '').toLowerCase() === username.toLowerCase());
|
||||
|
||||
let accountId = -1;
|
||||
if (accountFetchError) {
|
||||
accountId = null;
|
||||
} else {
|
||||
const account = accounts.find(acct => username.toLowerCase() === acct.getIn(['acct'], '').toLowerCase());
|
||||
const account = findAccountByUsername(state, username);
|
||||
accountId = account ? account.getIn(['id'], null) : -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,18 +17,18 @@ import Column from '../ui/components/column';
|
|||
import ScrollableList from '../../components/scrollable_list';
|
||||
import MissingIndicator from 'soapbox/components/missing_indicator';
|
||||
import { getFollowDifference } from 'soapbox/utils/accounts';
|
||||
import { findAccountByUsername } from 'soapbox/selectors';
|
||||
|
||||
const mapStateToProps = (state, { params, withReplies = false }) => {
|
||||
const username = params.username || '';
|
||||
const me = state.get('me');
|
||||
const accounts = state.getIn(['accounts']);
|
||||
const accountFetchError = (state.getIn(['accounts', -1, 'username'], '').toLowerCase() === username.toLowerCase());
|
||||
|
||||
let accountId = -1;
|
||||
if (accountFetchError) {
|
||||
accountId = null;
|
||||
} else {
|
||||
const account = accounts.find(acct => username.toLowerCase() === acct.getIn(['acct'], '').toLowerCase());
|
||||
const account = findAccountByUsername(state, username);
|
||||
accountId = account ? account.getIn(['id'], null) : -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ import { displayFqn } from 'soapbox/utils/state';
|
|||
import { getFeatures } from 'soapbox/utils/features';
|
||||
import { makeGetAccount } from '../selectors';
|
||||
import { Redirect } from 'react-router-dom';
|
||||
import { findAccountByUsername } from 'soapbox/selectors';
|
||||
|
||||
const mapStateToProps = (state, { params, withReplies = false }) => {
|
||||
const username = params.username || '';
|
||||
|
@ -32,7 +33,7 @@ const mapStateToProps = (state, { params, withReplies = false }) => {
|
|||
if (accountFetchError) {
|
||||
accountId = null;
|
||||
} else {
|
||||
account = accounts.find(acct => username.toLowerCase() === acct.getIn(['acct'], '').toLowerCase());
|
||||
account = findAccountByUsername(state, username);
|
||||
accountId = account ? account.getIn(['id'], null) : -1;
|
||||
accountUsername = account ? account.getIn(['acct'], '') : '';
|
||||
}
|
||||
|
|
|
@ -47,6 +47,14 @@ export const makeGetAccount = () => {
|
|||
});
|
||||
};
|
||||
|
||||
export const findAccountByUsername = (state, username) => {
|
||||
const accounts = state.get('accounts');
|
||||
|
||||
return accounts.find(account => {
|
||||
return username.toLowerCase() === account.getIn(['acct'], '').toLowerCase();
|
||||
});
|
||||
};
|
||||
|
||||
const toServerSideType = columnType => {
|
||||
switch (columnType) {
|
||||
case 'home':
|
||||
|
|
Loading…
Reference in a new issue