mastodon/app/javascript/mastodon/features/ui/components/messaging/contacts-list.js

127 lines
3.4 KiB
JavaScript
Raw Normal View History

2019-12-21 15:16:13 +01:00
import React from 'react';
import PropTypes from 'prop-types';
2020-01-06 20:50:36 +01:00
import accounts, { me } from '../../../../initial_state';
import api from '../../../../api';
import ImmutablePureComponent from 'react-immutable-pure-component';
import { mockContactList } from './mockContactList';
import Contact from './Contact';
2019-12-18 16:16:08 +01:00
export default class ContactsList extends ImmutablePureComponent {
2019-12-18 16:16:08 +01:00
static propTypes = {
myAccount : PropTypes.array,
showList : PropTypes.bool,
contactList : PropTypes.array,
conversationList: PropTypes.array,
2020-01-06 20:50:36 +01:00
following_count : PropTypes.number,
};
static defaultProps = {
showList : true,
myAccount : null,
userID : me,
following_count : 0,
contactList : mockContactList,
conversationList: mockContactList,
};
2019-12-18 16:16:08 +01:00
constructor(props) {
super(props);
2020-01-06 20:50:36 +01:00
this.state = {
2020-01-06 20:50:36 +01:00
following_count : accounts.accounts[me].following_count,
showList : props.showList,
myAccount : accounts.accounts[me],
contactList : mockContactList,
conversationList: mockContactList,
};
console.log('this.state', this.state);
// this.fetchContacts(1);
2019-12-18 16:16:08 +01:00
}
submitCompose() {
console.log('submit message');
}
toggleList = () => {
this.setState((state) => {
return {
showList: !state.showList,
};
});
};
/**
* find followed accounts
* @param AccountID
* @returns {Promise<AxiosResponse<T> | void>}
*/
fetchContacts = (AccountID = me) => {
return api(this.getState()).get('/api/v1/accounts/' + AccountID + '/following').then(resp => {
console.log('resp', resp);
}).catch(err => console.error('err', err));
};
2019-12-18 16:16:08 +01:00
render() {
console.log('this.state', this.state);
let renderedList = (
<span >no contacts</span >
);
if (this.props.contactList) {
renderedList = this.props.contactList.map(account => {
console.log('elem', account);
return (
<li
className='contact-item'
key={account.id}
>
<Contact account={account} />
</li >
);
});
}
2020-01-06 20:50:36 +01:00
const classList = 'btn btn-primary toggle-list ' + (this.state.showList ? 'active' : 'inactive');
2019-12-21 15:16:13 +01:00
return (
<div className='messaging-container'>
<div className='messaging-box'>
<div className='title column-header'>
2019-12-21 15:16:13 +01:00
<i
role='img'
className='fa fa-envelope column-header__icon fa-fw'
/>
Messaging box
</div >
2020-01-06 20:50:36 +01:00
<div className='user-list'>
<h2 className='title'>
la liste de {this.state.following_count} contacts
2019-12-21 15:16:13 +01:00
<button
2020-01-06 20:50:36 +01:00
className={classList}
onClick={this.toggleList}
>
2020-01-06 20:50:36 +01:00
{this.state.showList && (
<i className='fa fa-caret-up' />
)}
{!this.state.showList && (
<i className='fa fa-caret-left' />
)}
</button >
</h2 >
{this.state.showList && (
<div className='contact-list-container'>
<h3 >show list</h3 >
<ul className='contact-list'>
{renderedList}
</ul >
</div >
)}
</div >
2019-12-21 15:16:13 +01:00
</div >
</div >
);
2019-12-18 16:16:08 +01:00
}
}