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