parent
21b04af524
commit
d0aad1ac85
@ -0,0 +1,103 @@
|
||||
/*
|
||||
|
||||
`<ComposeAdvancedOptionsToggle>`
|
||||
================================
|
||||
|
||||
> For more information on the contents of this file, please contact:
|
||||
>
|
||||
> - surinna [@srn@dev.glitch.social]
|
||||
|
||||
This creates the toggle used by `<ComposeAdvancedOptions>`.
|
||||
|
||||
__Props:__
|
||||
|
||||
- __`onChange` (`PropTypes.func`) :__
|
||||
This provides the function to call when the toggle is
|
||||
(de-?)activated.
|
||||
|
||||
- __`active` (`PropTypes.bool`) :__
|
||||
This prop controls whether the toggle is currently active or not.
|
||||
|
||||
- __`name` (`PropTypes.string`) :__
|
||||
This identifies the toggle, and is sent to `onChange()` when it is
|
||||
called.
|
||||
|
||||
- __`shortText` (`PropTypes.string`) :__
|
||||
This is a short string used as the title of the toggle.
|
||||
|
||||
- __`longText` (`PropTypes.string`) :__
|
||||
This is a longer string used as a subtitle for the toggle.
|
||||
|
||||
*/
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
|
||||
/*
|
||||
|
||||
Imports:
|
||||
--------
|
||||
|
||||
*/
|
||||
|
||||
// Package imports //
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import Toggle from 'react-toggle';
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
|
||||
/*
|
||||
|
||||
Implementation:
|
||||
---------------
|
||||
|
||||
*/
|
||||
|
||||
export default class ComposeAdvancedOptionsToggle extends React.PureComponent {
|
||||
|
||||
static propTypes = {
|
||||
onChange: PropTypes.func.isRequired,
|
||||
active: PropTypes.bool.isRequired,
|
||||
name: PropTypes.string.isRequired,
|
||||
shortText: PropTypes.string.isRequired,
|
||||
longText: PropTypes.string.isRequired,
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
### `onToggle()`
|
||||
|
||||
The `onToggle()` function simply calls the `onChange()` prop with the
|
||||
toggle's `name`.
|
||||
|
||||
*/
|
||||
|
||||
onToggle = () => {
|
||||
this.props.onChange(this.props.name);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
### `render()`
|
||||
|
||||
The `render()` function is used to render our component. We just render
|
||||
a `<Toggle>` and place next to it our text.
|
||||
|
||||
*/
|
||||
|
||||
render() {
|
||||
const { active, shortText, longText } = this.props;
|
||||
return (
|
||||
<div role='button' tabIndex='0' className='advanced-options-dropdown__option' onClick={this.onToggle}>
|
||||
<div className='advanced-options-dropdown__option__toggle'>
|
||||
<Toggle checked={active} onChange={this.onToggle} />
|
||||
</div>
|
||||
<div className='advanced-options-dropdown__option__content'>
|
||||
<strong>{shortText}</strong>
|
||||
{longText}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,171 @@
|
||||
/*
|
||||
|
||||
`<NotificationFollow>`
|
||||
======================
|
||||
|
||||
This component renders a follow notification.
|
||||
|
||||
__Props:__
|
||||
|
||||
- __`id` (`PropTypes.number.isRequired`) :__
|
||||
This is the id of the notification.
|
||||
|
||||
- __`onDeleteNotification` (`PropTypes.func.isRequired`) :__
|
||||
The function to call when a notification should be
|
||||
dismissed/deleted.
|
||||
|
||||
- __`account` (`PropTypes.object.isRequired`) :__
|
||||
The account associated with the follow notification, ie the account
|
||||
which followed the user.
|
||||
|
||||
- __`intl` (`PropTypes.object.isRequired`) :__
|
||||
Our internationalization object, inserted by `@injectIntl`.
|
||||
|
||||
*/
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
|
||||
/*
|
||||
|
||||
Imports:
|
||||
--------
|
||||
|
||||
*/
|
||||
|
||||
// Package imports //
|
||||
import React from 'react';
|
||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||
import PropTypes from 'prop-types';
|
||||
import { defineMessages, FormattedMessage, injectIntl } from 'react-intl';
|
||||
import escapeTextContentForBrowser from 'escape-html';
|
||||
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||
|
||||
// Mastodon imports //
|
||||
import emojify from '../../../mastodon/emoji';
|
||||
import Permalink from '../../../mastodon/components/permalink';
|
||||
import AccountContainer from '../../../mastodon/containers/account_container';
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
|
||||
/*
|
||||
|
||||
Inital setup:
|
||||
-------------
|
||||
|
||||
The `messages` constant is used to define any messages that we need
|
||||
from inside props.
|
||||
|
||||
*/
|
||||
|
||||
const messages = defineMessages({
|
||||
deleteNotification :
|
||||
{ id: 'status.dismiss_notification', defaultMessage: 'Dismiss notification' },
|
||||
});
|
||||
|
||||
/*
|
||||
|
||||
Implementation:
|
||||
---------------
|
||||
|
||||
*/
|
||||
|
||||
@injectIntl
|
||||
export default class NotificationFollow extends ImmutablePureComponent {
|
||||
|
||||
static propTypes = {
|
||||
id : PropTypes.number.isRequired,
|
||||
onDeleteNotification : PropTypes.func.isRequired,
|
||||
account : ImmutablePropTypes.map.isRequired,
|
||||
intl : PropTypes.object.isRequired,
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
### `handleNotificationDeleteClick()`
|
||||
|
||||
This function just calls our `onDeleteNotification()` prop with the
|
||||
notification's `id`.
|
||||
|
||||
*/
|
||||
|
||||
handleNotificationDeleteClick = () => {
|
||||
this.props.onDeleteNotification(this.props.id);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
### `render()`
|
||||
|
||||
This actually renders the component.
|
||||
|
||||
*/
|
||||
|
||||
render () {
|
||||
const { account, intl } = this.props;
|
||||
|
||||
/*
|
||||
|
||||
`dismiss` creates the notification dismissal button. Its title is given
|
||||
by `dismissTitle`.
|
||||
|
||||
*/
|
||||
|
||||
const dismissTitle = intl.formatMessage(messages.deleteNotification);
|
||||
const dismiss = (
|
||||
<button
|
||||
aria-label={dismissTitle}
|
||||
title={dismissTitle}
|
||||
onClick={this.handleNotificationDeleteClick}
|
||||
className='status__prepend-dismiss-button'
|
||||
>
|
||||
<i className='fa fa-eraser' />
|
||||
</button>
|
||||
);
|
||||
|
||||
/*
|
||||
|
||||
`link` is a container for the account's `displayName`, which links to
|
||||
the account timeline using a `<Permalink>`.
|
||||
|
||||
*/
|
||||
|
||||
const displayName = account.get('display_name') || account.get('username');
|
||||
const displayNameHTML = { __html: emojify(escapeTextContentForBrowser(displayName)) };
|
||||
const link = (
|
||||
<Permalink
|
||||
className='notification__display-name'
|
||||
href={account.get('url')}
|
||||
title={account.get('acct')}
|
||||
to={`/accounts/${account.get('id')}`}
|
||||
dangerouslySetInnerHTML={displayNameHTML}
|
||||
/>
|
||||
);
|
||||
|
||||
/*
|
||||
|
||||
We can now render our component.
|
||||
|
||||
*/
|
||||
|
||||
return (
|
||||
<div className='notification notification-follow'>
|
||||
<div className='notification__message'>
|
||||
<div className='notification__favourite-icon-wrapper'>
|
||||
<i className='fa fa-fw fa-user-plus' />
|
||||
</div>
|
||||
|
||||
<FormattedMessage
|
||||
id='notification.follow'
|
||||
defaultMessage='{name} followed you'
|
||||
values={{ name: link }}
|
||||
/>
|
||||
|
||||
{dismiss}
|
||||
</div>
|
||||
|
||||
<AccountContainer id={account.get('id')} withNote={false} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
// Package imports //
|
||||
import React from 'react';
|
||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||
import PropTypes from 'prop-types';
|
||||
import { defineMessages, FormattedMessage, injectIntl } from 'react-intl';
|
||||
import escapeTextContentForBrowser from 'escape-html';
|
||||
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||
|
||||
// Mastodon imports //
|
||||
import emojify from '../../../mastodon/emoji';
|
||||
import Permalink from '../../../mastodon/components/permalink';
|
||||
import AccountContainer from '../../../mastodon/containers/account_container';
|
||||
|
||||
const messages = defineMessages({
|
||||
deleteNotification: { id: 'status.dismiss_notification', defaultMessage: 'Dismiss notification' },
|
||||
});
|
||||
|
||||
|
||||
@injectIntl
|
||||
export default class FollowNotification extends ImmutablePureComponent {
|
||||
|
||||
static contextTypes = {
|
||||
router: PropTypes.object,
|
||||
};
|
||||
|
||||
static propTypes = {
|
||||
notificationId: PropTypes.number.isRequired,
|
||||
onDeleteNotification: PropTypes.func.isRequired,
|
||||
account: ImmutablePropTypes.map.isRequired,
|
||||
intl: PropTypes.object.isRequired,
|
||||
};
|
||||
|
||||
// Avoid checking props that are functions (and whose equality will always
|
||||
// evaluate to false. See react-immutable-pure-component for usage.
|
||||
updateOnProps = [
|
||||
'account',
|
||||
]
|
||||
|
||||
handleNotificationDeleteClick = () => {
|
||||
this.props.onDeleteNotification(this.props.notificationId);
|
||||
}
|
||||
|
||||
render () {
|
||||
const { account, intl } = this.props;
|
||||
|
||||
const dismissTitle = intl.formatMessage(messages.deleteNotification);
|
||||
const dismiss = (
|
||||
<button
|
||||
aria-label={dismissTitle}
|
||||
title={dismissTitle}
|
||||
onClick={this.handleNotificationDeleteClick}
|
||||
className='status__prepend-dismiss-button'
|
||||
>
|
||||
<i className='fa fa-eraser' />
|
||||
</button>
|
||||
);
|
||||
|
||||
const displayName = account.get('display_name').length > 0 ? account.get('display_name') : account.get('username');
|
||||
const displayNameHTML = { __html: emojify(escapeTextContentForBrowser(displayName)) };
|
||||
const link = <Permalink className='notification__display-name' href={account.get('url')} title={account.get('acct')} to={`/accounts/${account.get('id')}`} dangerouslySetInnerHTML={displayNameHTML} />;
|
||||
return (
|
||||
<div className='notification notification-follow'>
|
||||
<div className='notification__message'>
|
||||
<div className='notification__favourite-icon-wrapper'>
|
||||
<i className='fa fa-fw fa-user-plus' />
|
||||
</div>
|
||||
|
||||
<FormattedMessage id='notification.follow' defaultMessage='{name} followed you' values={{ name: link }} />
|
||||
|
||||
{dismiss}
|
||||
</div>
|
||||
|
||||
<AccountContainer id={account.get('id')} withNote={false} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue