Implement status hotkeys + spoiler expanding
This commit is contained in:
parent
36452d6127
commit
fac7e31101
6 changed files with 84 additions and 80 deletions
|
@ -9,6 +9,7 @@ import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||||
import { MediaGallery, Video } from 'themes/glitch/util/async-components';
|
import { MediaGallery, Video } from 'themes/glitch/util/async-components';
|
||||||
import { HotKeys } from 'react-hotkeys';
|
import { HotKeys } from 'react-hotkeys';
|
||||||
import NotificationOverlayContainer from 'themes/glitch/features/notifications/containers/overlay_container';
|
import NotificationOverlayContainer from 'themes/glitch/features/notifications/containers/overlay_container';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
|
||||||
// We use the component (and not the container) since we do not want
|
// We use the component (and not the container) since we do not want
|
||||||
// to use the progress bar to show download progress
|
// to use the progress bar to show download progress
|
||||||
|
@ -21,6 +22,7 @@ export default class Status extends ImmutablePureComponent {
|
||||||
};
|
};
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
|
containerId: PropTypes.string,
|
||||||
id: PropTypes.string,
|
id: PropTypes.string,
|
||||||
status: ImmutablePropTypes.map,
|
status: ImmutablePropTypes.map,
|
||||||
account: ImmutablePropTypes.map,
|
account: ImmutablePropTypes.map,
|
||||||
|
@ -188,7 +190,9 @@ export default class Status extends ImmutablePureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
handleExpandedToggle = () => {
|
handleExpandedToggle = () => {
|
||||||
this.setExpansion(this.state.isExpanded || !this.props.status.get('spoiler') ? null : true);
|
if (this.props.status.get('spoiler_text')) {
|
||||||
|
this.setExpansion(this.state.isExpanded ? null : true);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
handleOpenVideo = startTime => {
|
handleOpenVideo = startTime => {
|
||||||
|
@ -222,11 +226,11 @@ export default class Status extends ImmutablePureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
handleHotkeyMoveUp = () => {
|
handleHotkeyMoveUp = () => {
|
||||||
this.props.onMoveUp(this.props.status.get('id'));
|
this.props.onMoveUp(this.props.containerId || this.props.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleHotkeyMoveDown = () => {
|
handleHotkeyMoveDown = () => {
|
||||||
this.props.onMoveDown(this.props.status.get('id'));
|
this.props.onMoveDown(this.props.containerId || this.props.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleRef = c => {
|
handleRef = c => {
|
||||||
|
@ -371,31 +375,24 @@ export default class Status extends ImmutablePureComponent {
|
||||||
openProfile: this.handleHotkeyOpenProfile,
|
openProfile: this.handleHotkeyOpenProfile,
|
||||||
moveUp: this.handleHotkeyMoveUp,
|
moveUp: this.handleHotkeyMoveUp,
|
||||||
moveDown: this.handleHotkeyMoveDown,
|
moveDown: this.handleHotkeyMoveDown,
|
||||||
|
toggleSpoiler: this.handleExpandedToggle,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const computedClass = classNames('status', `status-${status.get('visibility')}`, {
|
||||||
|
collapsed: isExpanded === false,
|
||||||
|
'has-background': isExpanded === false && background,
|
||||||
|
'marked-for-delete': this.state.markedForDelete,
|
||||||
|
muted,
|
||||||
|
}, 'focusable');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<HotKeys handlers={handlers}>
|
<HotKeys handlers={handlers}>
|
||||||
<div
|
<div
|
||||||
className={
|
className={computedClass}
|
||||||
`status${
|
style={isExpanded === false && background ? { backgroundImage: `url(${background})` } : null}
|
||||||
muted ? ' muted' : ''
|
|
||||||
} status-${status.get('visibility')}${
|
|
||||||
isExpanded === false ? ' collapsed' : ''
|
|
||||||
}${
|
|
||||||
isExpanded === false && background ? ' has-background' : ''
|
|
||||||
}${
|
|
||||||
this.state.markedForDelete ? ' marked-for-delete' : ''
|
|
||||||
}`
|
|
||||||
}
|
|
||||||
style={{
|
|
||||||
backgroundImage: (
|
|
||||||
isExpanded === false && background ?
|
|
||||||
`url(${background})` :
|
|
||||||
'none'
|
|
||||||
),
|
|
||||||
}}
|
|
||||||
{...selectorAttribs}
|
{...selectorAttribs}
|
||||||
ref={handleRef}
|
ref={handleRef}
|
||||||
|
tabIndex='0'
|
||||||
>
|
>
|
||||||
{prepend && account ? (
|
{prepend && account ? (
|
||||||
<StatusPrepend
|
<StatusPrepend
|
||||||
|
|
|
@ -45,6 +45,7 @@ const makeMapStateToProps = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
containerId : props.containerId || props.id, // Should match reblogStatus's id for reblogs
|
||||||
status : status,
|
status : status,
|
||||||
account : account || props.account,
|
account : account || props.account,
|
||||||
settings : state.get('local_settings'),
|
settings : state.get('local_settings'),
|
||||||
|
|
|
@ -14,6 +14,7 @@ import NotificationOverlayContainer from '../containers/overlay_container';
|
||||||
export default class NotificationFollow extends ImmutablePureComponent {
|
export default class NotificationFollow extends ImmutablePureComponent {
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
|
hidden: PropTypes.bool,
|
||||||
id: PropTypes.string.isRequired,
|
id: PropTypes.string.isRequired,
|
||||||
account: ImmutablePropTypes.map.isRequired,
|
account: ImmutablePropTypes.map.isRequired,
|
||||||
notification: ImmutablePropTypes.map.isRequired,
|
notification: ImmutablePropTypes.map.isRequired,
|
||||||
|
@ -57,7 +58,7 @@ export default class NotificationFollow extends ImmutablePureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { account, notification } = this.props;
|
const { account, notification, hidden } = this.props;
|
||||||
|
|
||||||
// Links to the display name.
|
// Links to the display name.
|
||||||
const displayName = account.get('display_name_html') || account.get('username');
|
const displayName = account.get('display_name_html') || account.get('username');
|
||||||
|
@ -87,7 +88,7 @@ export default class NotificationFollow extends ImmutablePureComponent {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<AccountContainer id={account.get('id')} withNote={false} />
|
<AccountContainer hidden={hidden} id={account.get('id')} withNote={false} />
|
||||||
<NotificationOverlayContainer notification={notification} />
|
<NotificationOverlayContainer notification={notification} />
|
||||||
</div>
|
</div>
|
||||||
</HotKeys>
|
</HotKeys>
|
||||||
|
|
|
@ -16,70 +16,75 @@ export default class Notification extends ImmutablePureComponent {
|
||||||
onMoveUp: PropTypes.func.isRequired,
|
onMoveUp: PropTypes.func.isRequired,
|
||||||
onMoveDown: PropTypes.func.isRequired,
|
onMoveDown: PropTypes.func.isRequired,
|
||||||
onMention: PropTypes.func.isRequired,
|
onMention: PropTypes.func.isRequired,
|
||||||
settings: ImmutablePropTypes.map.isRequired,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
renderFollow () {
|
render () {
|
||||||
const { notification } = this.props;
|
const {
|
||||||
|
hidden,
|
||||||
|
notification,
|
||||||
|
onMoveDown,
|
||||||
|
onMoveUp,
|
||||||
|
onMention,
|
||||||
|
} = this.props;
|
||||||
|
|
||||||
|
switch(notification.get('type')) {
|
||||||
|
case 'follow':
|
||||||
return (
|
return (
|
||||||
<NotificationFollow
|
<NotificationFollow
|
||||||
|
hidden={hidden}
|
||||||
id={notification.get('id')}
|
id={notification.get('id')}
|
||||||
account={notification.get('account')}
|
account={notification.get('account')}
|
||||||
notification={notification}
|
notification={notification}
|
||||||
|
onMoveDown={onMoveDown}
|
||||||
|
onMoveUp={onMoveUp}
|
||||||
|
onMention={onMention}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
case 'mention':
|
||||||
|
|
||||||
renderMention () {
|
|
||||||
const { notification } = this.props;
|
|
||||||
return (
|
return (
|
||||||
<StatusContainer
|
<StatusContainer
|
||||||
|
containerId={notification.get('id')}
|
||||||
|
hidden={hidden}
|
||||||
id={notification.get('status')}
|
id={notification.get('status')}
|
||||||
notification={notification}
|
notification={notification}
|
||||||
|
onMoveDown={onMoveDown}
|
||||||
|
onMoveUp={onMoveUp}
|
||||||
|
onMention={onMention}
|
||||||
withDismiss
|
withDismiss
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
case 'favourite':
|
||||||
|
|
||||||
renderFavourite () {
|
|
||||||
const { notification } = this.props;
|
|
||||||
return (
|
return (
|
||||||
<StatusContainer
|
<StatusContainer
|
||||||
|
containerId={notification.get('id')}
|
||||||
|
hidden={hidden}
|
||||||
id={notification.get('status')}
|
id={notification.get('status')}
|
||||||
account={notification.get('account')}
|
account={notification.get('account')}
|
||||||
prepend='favourite'
|
prepend='favourite'
|
||||||
muted
|
muted
|
||||||
notification={notification}
|
notification={notification}
|
||||||
|
onMoveDown={onMoveDown}
|
||||||
|
onMoveUp={onMoveUp}
|
||||||
|
onMention={onMention}
|
||||||
withDismiss
|
withDismiss
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
case 'reblog':
|
||||||
|
|
||||||
renderReblog () {
|
|
||||||
const { notification } = this.props;
|
|
||||||
return (
|
return (
|
||||||
<StatusContainer
|
<StatusContainer
|
||||||
|
containerId={notification.get('id')}
|
||||||
|
hidden={hidden}
|
||||||
id={notification.get('status')}
|
id={notification.get('status')}
|
||||||
account={notification.get('account')}
|
account={notification.get('account')}
|
||||||
prepend='reblog'
|
prepend='reblog'
|
||||||
muted
|
muted
|
||||||
notification={notification}
|
notification={notification}
|
||||||
|
onMoveDown={onMoveDown}
|
||||||
|
onMoveUp={onMoveUp}
|
||||||
|
onMention={onMention}
|
||||||
withDismiss
|
withDismiss
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
render () {
|
|
||||||
const { notification } = this.props;
|
|
||||||
switch(notification.get('type')) {
|
|
||||||
case 'follow':
|
|
||||||
return this.renderFollow();
|
|
||||||
case 'mention':
|
|
||||||
return this.renderMention();
|
|
||||||
case 'favourite':
|
|
||||||
return this.renderFavourite();
|
|
||||||
case 'reblog':
|
|
||||||
return this.renderReblog();
|
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,6 @@ const makeMapStateToProps = () => {
|
||||||
|
|
||||||
const mapStateToProps = (state, props) => ({
|
const mapStateToProps = (state, props) => ({
|
||||||
notification: getNotification(state, props.notification, props.accountId),
|
notification: getNotification(state, props.notification, props.accountId),
|
||||||
settings: state.get('local_settings'),
|
|
||||||
notifCleaning: state.getIn(['notifications', 'cleaningMode']),
|
notifCleaning: state.getIn(['notifications', 'cleaningMode']),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -84,6 +84,7 @@ const keyMap = {
|
||||||
goToProfile: 'g u',
|
goToProfile: 'g u',
|
||||||
goToBlocked: 'g b',
|
goToBlocked: 'g b',
|
||||||
goToMuted: 'g m',
|
goToMuted: 'g m',
|
||||||
|
toggleSpoiler: 'x',
|
||||||
};
|
};
|
||||||
|
|
||||||
@connect(mapStateToProps)
|
@connect(mapStateToProps)
|
||||||
|
|
Loading…
Reference in a new issue