Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement adding a user to a list from their profile #9062

Merged
merged 2 commits into from
Nov 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions app/javascript/mastodon/actions/lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ export const LIST_EDITOR_REMOVE_REQUEST = 'LIST_EDITOR_REMOVE_REQUEST';
export const LIST_EDITOR_REMOVE_SUCCESS = 'LIST_EDITOR_REMOVE_SUCCESS';
export const LIST_EDITOR_REMOVE_FAIL = 'LIST_EDITOR_REMOVE_FAIL';

export const LIST_ADDER_RESET = 'LIST_ADDER_RESET';
export const LIST_ADDER_SETUP = 'LIST_ADDER_SETUP';

export const LIST_ADDER_LISTS_FETCH_REQUEST = 'LIST_ADDER_LISTS_FETCH_REQUEST';
export const LIST_ADDER_LISTS_FETCH_SUCCESS = 'LIST_ADDER_LISTS_FETCH_SUCCESS';
export const LIST_ADDER_LISTS_FETCH_FAIL = 'LIST_ADDER_LISTS_FETCH_FAIL';

export const fetchList = id => (dispatch, getState) => {
if (getState().getIn(['lists', id])) {
return;
Expand Down Expand Up @@ -316,3 +323,50 @@ export const removeFromListFail = (listId, accountId, error) => ({
accountId,
error,
});

export const resetListAdder = () => ({
type: LIST_ADDER_RESET,
});

export const setupListAdder = accountId => (dispatch, getState) => {
dispatch({
type: LIST_ADDER_SETUP,
account: getState().getIn(['accounts', accountId]),
});
dispatch(fetchLists());
dispatch(fetchAccountLists(accountId));
};

export const fetchAccountLists = accountId => (dispatch, getState) => {
dispatch(fetchAccountListsRequest(accountId));

api(getState).get(`/api/v1/accounts/${accountId}/lists`)
.then(({ data }) => dispatch(fetchAccountListsSuccess(accountId, data)))
.catch(err => dispatch(fetchAccountListsFail(accountId, err)));
};

export const fetchAccountListsRequest = id => ({
type:LIST_ADDER_LISTS_FETCH_REQUEST,
id,
});

export const fetchAccountListsSuccess = (id, lists) => ({
type: LIST_ADDER_LISTS_FETCH_SUCCESS,
id,
lists,
});

export const fetchAccountListsFail = (id, err) => ({
type: LIST_ADDER_LISTS_FETCH_FAIL,
id,
err,
});

export const addToListAdder = listId => (dispatch, getState) => {
dispatch(addToList(listId, getState().getIn(['listAdder', 'accountId'])));
};

export const removeFromListAdder = listId => (dispatch, getState) => {
dispatch(removeFromList(listId, getState().getIn(['listAdder', 'accountId'])));
};

Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const messages = defineMessages({
mutes: { id: 'navigation_bar.mutes', defaultMessage: 'Muted users' },
endorse: { id: 'account.endorse', defaultMessage: 'Feature on profile' },
unendorse: { id: 'account.unendorse', defaultMessage: 'Don\'t feature on profile' },
add_or_remove_from_list: { id: 'account.add_or_remove_from_list', defaultMessage: 'Add or Remove from lists' },
});

export default @injectIntl
Expand All @@ -51,6 +52,7 @@ class ActionBar extends React.PureComponent {
onBlockDomain: PropTypes.func.isRequired,
onUnblockDomain: PropTypes.func.isRequired,
onEndorseToggle: PropTypes.func.isRequired,
onAddToList: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
};

Expand Down Expand Up @@ -105,6 +107,7 @@ class ActionBar extends React.PureComponent {
}

menu.push({ text: intl.formatMessage(account.getIn(['relationship', 'endorsed']) ? messages.unendorse : messages.endorse), action: this.props.onEndorseToggle });
menu.push({ text: intl.formatMessage(messages.add_or_remove_from_list), action: this.props.onAddToList });
menu.push(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default class Header extends ImmutablePureComponent {
onBlockDomain: PropTypes.func.isRequired,
onUnblockDomain: PropTypes.func.isRequired,
onEndorseToggle: PropTypes.func.isRequired,
onAddToList: PropTypes.func.isRequired,
hideTabs: PropTypes.bool,
};

Expand Down Expand Up @@ -78,6 +79,10 @@ export default class Header extends ImmutablePureComponent {
this.props.onEndorseToggle(this.props.account);
}

handleAddToList = () => {
this.props.onAddToList(this.props.account);
}

render () {
const { account, hideTabs } = this.props;

Expand Down Expand Up @@ -106,6 +111,7 @@ export default class Header extends ImmutablePureComponent {
onBlockDomain={this.handleBlockDomain}
onUnblockDomain={this.handleUnblockDomain}
onEndorseToggle={this.handleEndorseToggle}
onAddToList={this.handleAddToList}
/>

{!hideTabs && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
dispatch(unblockDomain(domain));
},

onAddToList(account){
dispatch(openModal('LIST_ADDER', {
accountId: account.get('id'),
}));
},

});

export default injectIntl(connect(makeMapStateToProps, mapDispatchToProps)(Header));
43 changes: 43 additions & 0 deletions app/javascript/mastodon/features/list_adder/components/account.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from 'react';
import { connect } from 'react-redux';
import { makeGetAccount } from '../../../selectors';
import ImmutablePureComponent from 'react-immutable-pure-component';
import ImmutablePropTypes from 'react-immutable-proptypes';
import Avatar from '../../../components/avatar';
import DisplayName from '../../../components/display_name';
import { injectIntl } from 'react-intl';

const makeMapStateToProps = () => {
const getAccount = makeGetAccount();

const mapStateToProps = (state, { accountId }) => ({
account: getAccount(state, accountId),
});

return mapStateToProps;
};


export default @connect(makeMapStateToProps)
@injectIntl
class Account extends ImmutablePureComponent {

static propTypes = {
account: ImmutablePropTypes.map.isRequired,
};

render () {
const { account } = this.props;
return (
<div className='account'>
<div className='account__wrapper'>
<div className='account__display-name'>
<div className='account__avatar-wrapper'><Avatar account={account} size={36} /></div>
<DisplayName account={account} />
</div>
</div>
</div>
);
}

}
68 changes: 68 additions & 0 deletions app/javascript/mastodon/features/list_adder/components/list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import ImmutablePureComponent from 'react-immutable-pure-component';
import ImmutablePropTypes from 'react-immutable-proptypes';
import IconButton from '../../../components/icon_button';
import { defineMessages, injectIntl } from 'react-intl';
import { removeFromListAdder, addToListAdder } from '../../../actions/lists';

const messages = defineMessages({
remove: { id: 'lists.account.remove', defaultMessage: 'Remove from list' },
add: { id: 'lists.account.add', defaultMessage: 'Add to list' },
});

const MapStateToProps = (state, { listId, added }) => ({
list: state.get('lists').get(listId),
added: typeof added === 'undefined' ? state.getIn(['listAdder', 'lists', 'items']).includes(listId) : added,
});

const mapDispatchToProps = (dispatch, { listId }) => ({
onRemove: () => dispatch(removeFromListAdder(listId)),
onAdd: () => dispatch(addToListAdder(listId)),
});

export default @connect(MapStateToProps, mapDispatchToProps)
@injectIntl
class List extends ImmutablePureComponent {

static propTypes = {
list: ImmutablePropTypes.map.isRequired,
intl: PropTypes.object.isRequired,
onRemove: PropTypes.func.isRequired,
onAdd: PropTypes.func.isRequired,
added: PropTypes.bool,
};

static defaultProps = {
added: false,
};

render () {
const { list, intl, onRemove, onAdd, added } = this.props;

let button;

if (added) {
button = <IconButton icon='times' title={intl.formatMessage(messages.remove)} onClick={onRemove} />;
} else {
button = <IconButton icon='plus' title={intl.formatMessage(messages.add)} onClick={onAdd} />;
}

return (
<div className='list'>
<div className='list__wrapper'>
<div className='list__display-name'>
<i className='fa fa-fw fa-list-ul column-link__icon' />
{list.get('title')}
</div>

<div className='account__relationship'>
{button}
</div>
</div>
</div>
);
}

}
73 changes: 73 additions & 0 deletions app/javascript/mastodon/features/list_adder/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import React from 'react';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { connect } from 'react-redux';
import ImmutablePureComponent from 'react-immutable-pure-component';
import { injectIntl } from 'react-intl';
import { setupListAdder, resetListAdder } from '../../actions/lists';
import { createSelector } from 'reselect';
import List from './components/list';
import Account from './components/account';
import NewListForm from '../lists/components/new_list_form';
// hack

const getOrderedLists = createSelector([state => state.get('lists')], lists => {
if (!lists) {
return lists;
}

return lists.toList().filter(item => !!item).sort((a, b) => a.get('title').localeCompare(b.get('title')));
});

const mapStateToProps = state => ({
listIds: getOrderedLists(state).map(list=>list.get('id')),
});

const mapDispatchToProps = dispatch => ({
onInitialize: accountId => dispatch(setupListAdder(accountId)),
onReset: () => dispatch(resetListAdder()),
});

export default @connect(mapStateToProps, mapDispatchToProps)
@injectIntl
class ListAdder extends ImmutablePureComponent {

static propTypes = {
accountId: PropTypes.string.isRequired,
onClose: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
onInitialize: PropTypes.func.isRequired,
onReset: PropTypes.func.isRequired,
listIds: ImmutablePropTypes.list.isRequired,
};

componentDidMount () {
const { onInitialize, accountId } = this.props;
onInitialize(accountId);
}

componentWillUnmount () {
const { onReset } = this.props;
onReset();
}

render () {
const { accountId, listIds } = this.props;

return (
<div className='modal-root__modal list-adder'>
<div className='list-adder__account'>
<Account accountId={accountId} />
</div>

<NewListForm />


<div className='list-adder__lists'>
{listIds.map(ListId => <List key={ListId} listId={ListId} />)}
</div>
</div>
);
}

}
2 changes: 2 additions & 0 deletions app/javascript/mastodon/features/ui/components/modal_root.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
ReportModal,
EmbedModal,
ListEditor,
ListAdder,
} from '../../../features/ui/util/async-components';

const MODAL_COMPONENTS = {
Expand All @@ -30,6 +31,7 @@ const MODAL_COMPONENTS = {
'EMBED': EmbedModal,
'LIST_EDITOR': ListEditor,
'FOCAL_POINT': () => Promise.resolve({ default: FocalPointModal }),
'LIST_ADDER':ListAdder,
};

export default class ModalRoot extends React.PureComponent {
Expand Down
4 changes: 4 additions & 0 deletions app/javascript/mastodon/features/ui/util/async-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,7 @@ export function EmbedModal () {
export function ListEditor () {
return import(/* webpackChunkName: "features/list_editor" */'../../list_editor');
}

export function ListAdder () {
return import(/*webpackChunkName: "features/list_adder" */'../../list_adder');
}
1 change: 1 addition & 0 deletions app/javascript/mastodon/locales/ar.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"account.add_or_remove_from_list": "Add or Remove from lists",
"account.badges.bot": "روبوت",
"account.block": "حظر @{name}",
"account.block_domain": "إخفاء كل شيئ قادم من إسم النطاق {domain}",
Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/locales/ast.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"account.add_or_remove_from_list": "Add or Remove from lists",
"account.badges.bot": "Robó",
"account.block": "Bloquiar a @{name}",
"account.block_domain": "Hide everything from {domain}",
Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/locales/bg.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"account.add_or_remove_from_list": "Add or Remove from lists",
"account.badges.bot": "Bot",
"account.block": "Блокирай",
"account.block_domain": "Hide everything from {domain}",
Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/locales/ca.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"account.add_or_remove_from_list": "Add or Remove from lists",
"account.badges.bot": "Bot",
"account.block": "Bloca @{name}",
"account.block_domain": "Amaga-ho tot de {domain}",
Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/locales/co.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"account.add_or_remove_from_list": "Add or Remove from lists",
"account.badges.bot": "Bot",
"account.block": "Bluccà @{name}",
"account.block_domain": "Piattà tuttu da {domain}",
Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/locales/cs.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"account.add_or_remove_from_list": "Add or Remove from lists",
"account.badges.bot": "Robot",
"account.block": "Zablokovat uživatele @{name}",
"account.block_domain": "Skrýt vše z {domain}",
Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/locales/cy.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"account.add_or_remove_from_list": "Add or Remove from lists",
"account.badges.bot": "Bot",
"account.block": "Blociwch @{name}",
"account.block_domain": "Cuddiwch bopeth rhag {domain}",
Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/locales/da.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"account.add_or_remove_from_list": "Add or Remove from lists",
"account.badges.bot": "Robot",
"account.block": "Bloker @{name}",
"account.block_domain": "Skjul alt fra {domain}",
Expand Down
1 change: 1 addition & 0 deletions app/javascript/mastodon/locales/de.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"account.add_or_remove_from_list": "Add or Remove from lists",
"account.badges.bot": "Bot",
"account.block": "@{name} blockieren",
"account.block_domain": "Alles von {domain} verstecken",
Expand Down
Loading