- Better unified reblogs, statuses, and notifications - Polished up collapsed toots greatly - Apologies to bea if this makes everything more difficultth-downstream
parent
e00724a4fc
commit
3cd65539da
@ -0,0 +1,229 @@
|
||||
/*
|
||||
|
||||
`<StatusHeader>`
|
||||
================
|
||||
|
||||
Originally a part of `<Status>`, but extracted into a separate
|
||||
component for better documentation and maintainance by
|
||||
@kibi@glitch.social as a part of glitch-soc/mastodon.
|
||||
|
||||
*/
|
||||
|
||||
/* * * * */
|
||||
|
||||
/*
|
||||
|
||||
Imports:
|
||||
--------
|
||||
|
||||
*/
|
||||
|
||||
// Our standard React imports:
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||
|
||||
// We will need internationalization in this component:
|
||||
import { defineMessages, injectIntl } from 'react-intl';
|
||||
|
||||
// The various components used when constructing our header:
|
||||
import Avatar from './avatar';
|
||||
import AvatarOverlay from './avatar_overlay';
|
||||
import DisplayName from './display_name';
|
||||
import IconButton from './icon_button';
|
||||
|
||||
/* * * * */
|
||||
|
||||
/*
|
||||
|
||||
Inital setup:
|
||||
-------------
|
||||
|
||||
The `messages` constant is used to define any messages that we need
|
||||
from inside props. In our case, these are the `collapse` and
|
||||
`uncollapse` messages used with our collapse/uncollapse buttons.
|
||||
|
||||
*/
|
||||
|
||||
const messages = defineMessages({
|
||||
collapse: { id: 'status.collapse', defaultMessage: 'Collapse' },
|
||||
uncollapse: { id: 'status.uncollapse', defaultMessage: 'Uncollapse' },
|
||||
});
|
||||
|
||||
/* * * * */
|
||||
|
||||
/*
|
||||
|
||||
The `<StatusHeader>` component:
|
||||
-------------------------------
|
||||
|
||||
The `<StatusHeader>` component wraps together the header information
|
||||
(avatar, display name) and upper buttons and icons (collapsing, media
|
||||
icons) into a single `<header>` element.
|
||||
|
||||
### Props
|
||||
|
||||
- __`account`, `friend` (`ImmutablePropTypes.map`) :__
|
||||
These give the accounts associated with the status. `account` is
|
||||
the author of the post; `friend` will have their avatar appear
|
||||
in the overlay if provided.
|
||||
|
||||
- __`mediaIcon` (`PropTypes.string`) :__
|
||||
If a mediaIcon should be placed in the header, this string
|
||||
specifies it.
|
||||
|
||||
- __`collapsible`, `collapsed` (`PropTypes.bool`) :__
|
||||
These props tell whether a post can be, and is, collapsed.
|
||||
|
||||
- __`parseClick` (`PropTypes.func`) :__
|
||||
This function will be called when the user clicks inside the header
|
||||
information.
|
||||
|
||||
- __`setExpansion` (`PropTypes.func`) :__
|
||||
This function is used to set the expansion state of the post.
|
||||
|
||||
- __`intl` (`PropTypes.object`) :__
|
||||
This is our internationalization object, provided by
|
||||
`injectIntl()`.
|
||||
|
||||
*/
|
||||
|
||||
@injectIntl
|
||||
export default class StatusHeader extends React.PureComponent {
|
||||
|
||||
static propTypes = {
|
||||
account: ImmutablePropTypes.map.isRequired,
|
||||
friend: ImmutablePropTypes.map,
|
||||
mediaIcon: PropTypes.string,
|
||||
collapsible: PropTypes.bool,
|
||||
collapsed: PropTypes.bool,
|
||||
parseClick: PropTypes.func.isRequired,
|
||||
setExpansion: PropTypes.func.isRequired,
|
||||
intl: PropTypes.object.isRequired,
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
### Implementation
|
||||
|
||||
#### `handleCollapsedClick()`.
|
||||
|
||||
`handleCollapsedClick()` is just a simple callback for our collapsing
|
||||
button. It calls `setExpansion` to set the collapsed state of the
|
||||
status.
|
||||
|
||||
*/
|
||||
|
||||
handleCollapsedClick = (e) => {
|
||||
const { collapsed, setExpansion } = this.props;
|
||||
if (e.button === 0) {
|
||||
setExpansion(collapsed ? null : false);
|
||||
e.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
#### `handleAccountClick()`.
|
||||
|
||||
`handleAccountClick()` handles any clicks on the header info. It calls
|
||||
`parseClick()` with our `account` as the anticipatory `destination`.
|
||||
|
||||
*/
|
||||
|
||||
handleAccountClick = (e) => {
|
||||
const { account, parseClick } = this.props;
|
||||
parseClick(e, `/accounts/${+account.get('id')}`);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
#### `render()`.
|
||||
|
||||
`render()` actually puts our element on the screen. `<StatusHeader>`
|
||||
has a very straightforward rendering process.
|
||||
|
||||
*/
|
||||
|
||||
render () {
|
||||
const {
|
||||
account,
|
||||
friend,
|
||||
mediaIcon,
|
||||
collapsible,
|
||||
collapsed,
|
||||
intl,
|
||||
} = this.props;
|
||||
|
||||
return (
|
||||
<header className='status__info'>
|
||||
{
|
||||
|
||||
/*
|
||||
|
||||
We have to include the status icons before the header content because
|
||||
it is rendered as a float.
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
<div className='status__info__icons'>
|
||||
{mediaIcon ? (
|
||||
<i
|
||||
className={`fa fa-fw fa-${mediaIcon}`}
|
||||
aria-hidden='true'
|
||||
/>
|
||||
) : null}
|
||||
{collapsible ? (
|
||||
<IconButton
|
||||
className='status__collapse-button'
|
||||
animate flip
|
||||
active={collapsed}
|
||||
title={
|
||||
collapsed ?
|
||||
intl.formatMessage(messages.uncollapse) :
|
||||
intl.formatMessage(messages.collapse)
|
||||
}
|
||||
icon='angle-double-up'
|
||||
onClick={this.handleCollapsedClick}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
{
|
||||
|
||||
/*
|
||||
|
||||
This begins our header content. It is all wrapped inside of a link
|
||||
which gets handled by `handleAccountClick`. We use an `<AvatarOverlay>`
|
||||
if we have a `friend` and a normal `<Avatar>` if we don't.
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
<a
|
||||
href={account.get('url')}
|
||||
className='status__display-name'
|
||||
onClick={this.handleAccountClick}
|
||||
>
|
||||
<div className='status__avatar'>{
|
||||
friend ? (
|
||||
<AvatarOverlay
|
||||
staticSrc={account.get('avatar_static')}
|
||||
overlaySrc={friend.get('avatar_static')}
|
||||
/>
|
||||
) : (
|
||||
<Avatar
|
||||
src={account.get('avatar')}
|
||||
staticSrc={account.get('avatar_static')}
|
||||
size={48}
|
||||
/>
|
||||
)
|
||||
}</div>
|
||||
<DisplayName account={account} />
|
||||
</a>
|
||||
|
||||
</header>
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,164 @@
|
||||
/*
|
||||
|
||||
`<StatusPrepend>`
|
||||
=================
|
||||
|
||||
Originally a part of `<Status>`, but extracted into a separate
|
||||
component for better documentation and maintainance by
|
||||
@kibi@glitch.social as a part of glitch-soc/mastodon.
|
||||
|
||||
*/
|
||||
|
||||
/* * * * */
|
||||
|
||||
/*
|
||||
|
||||
Imports:
|
||||
--------
|
||||
|
||||
*/
|
||||
|
||||
// Our standard React imports:
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||
|
||||
// This helps us process our text:
|
||||
import emojify from '../emoji';
|
||||
import escapeTextContentForBrowser from 'escape-html';
|
||||
import { FormattedMessage } from 'react-intl';
|
||||
|
||||
/* * * * */
|
||||
|
||||
/*
|
||||
|
||||
The `<StatusPrepend>` component:
|
||||
--------------------------------
|
||||
|
||||
The `<StatusPrepend>` component holds a status's prepend, ie the text
|
||||
that says “X reblogged this,” etc. It is represented by an `<aside>`
|
||||
element.
|
||||
|
||||
### Props
|
||||
|
||||
- __`type` (`PropTypes.string`) :__
|
||||
The type of prepend. One of `'reblogged_by'`, `'reblog'`,
|
||||
`'favourite'`.
|
||||
|
||||
- __`account` (`ImmutablePropTypes.map`) :__
|
||||
The account associated with the prepend.
|
||||
|
||||
- __`parseClick` (`PropTypes.func.isRequired`) :__
|
||||
Our click parsing function.
|
||||
|
||||
*/
|
||||
|
||||
export default class StatusPrepend extends React.PureComponent {
|
||||
|
||||
static propTypes = {
|
||||
type: PropTypes.string.isRequired,
|
||||
account: ImmutablePropTypes.map.isRequired,
|
||||
parseClick: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
### Implementation
|
||||
|
||||
#### `handleClick()`.
|
||||
|
||||
This is just a small wrapper for `parseClick()` that gets fired when
|
||||
an account link is clicked.
|
||||
|
||||
*/
|
||||
|
||||
handleClick = (e) => {
|
||||
const { account, parseClick } = this.props;
|
||||
parseClick(e, `/accounts/${+account.get('id')}`);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
#### `<Message>`.
|
||||
|
||||
`<Message>` is a quick functional React component which renders the
|
||||
actual prepend message based on our provided `type`. First we create a
|
||||
`link` for the account's name, and then use `<FormattedMessage>` to
|
||||
generate the message.
|
||||
|
||||
*/
|
||||
|
||||
Message = () => {
|
||||
const { type, account } = this.props;
|
||||
let link = (
|
||||
<a
|
||||
onClick={this.handleClick}
|
||||
href={account.get('url')}
|
||||
className='status__display-name'
|
||||
>
|
||||
<b
|
||||
dangerouslySetInnerHTML={{
|
||||
__html : emojify(escapeTextContentForBrowser(
|
||||
account.get('display_name') || account.get('username')
|
||||
)),
|
||||
}}
|
||||
/>
|
||||
</a>
|
||||
);
|
||||
switch (type) {
|
||||
case 'reblogged_by':
|
||||
return (
|
||||
<FormattedMessage
|
||||
id='status.reblogged_by'
|
||||
defaultMessage='{name} boosted'
|
||||
values={{ name : link }}
|
||||
/>
|
||||
);
|
||||
case 'favourite':
|
||||
return (
|
||||
<FormattedMessage
|
||||
id='notification.favourite'
|
||||
defaultMessage='{name} favourited your status'
|
||||
values={{ name : link }}
|
||||
/>
|
||||
);
|
||||
case 'reblog':
|
||||
return (
|
||||
<FormattedMessage
|
||||
id='notification.reblog'
|
||||
defaultMessage='{name} boosted your status'
|
||||
values={{ name : link }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
#### `render()`.
|
||||
|
||||
Our `render()` is incredibly simple; we just render the icon and then
|
||||
the `<Message>` inside of an <aside>.
|
||||
|
||||
*/
|
||||
|
||||
render () {
|
||||
const { Message } = this;
|
||||
const { type } = this.props;
|
||||
|
||||
return !type ? null : (
|
||||
<aside className={type === 'reblogged_by' ? 'status__prepend' : 'notification__message'}>
|
||||
<div className={type === 'reblogged_by' ? 'status__prepend-icon-wrapper' : 'notification__favourite-icon-wrapper'}>
|
||||
<i
|
||||
className={`fa fa-fw fa-${
|
||||
type === 'favourite' ? 'star star-icon' : 'retweet'
|
||||
} status__prepend-icon`}
|
||||
/>
|
||||
</div>
|
||||
<Message />
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue