Merge pull request #250 from chriswmartin/fav-confirm-modal

add favourite confirmation modal
This commit is contained in:
beatrix 2017-12-10 23:10:19 -05:00 committed by GitHub
commit 08b0861b96
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 152 additions and 18 deletions

View file

@ -33,6 +33,7 @@ class Settings::PreferencesController < Settings::BaseController
:setting_default_sensitive, :setting_default_sensitive,
:setting_unfollow_modal, :setting_unfollow_modal,
:setting_boost_modal, :setting_boost_modal,
:setting_favourite_modal,
:setting_delete_modal, :setting_delete_modal,
:setting_auto_play_gif, :setting_auto_play_gif,
:setting_reduce_motion, :setting_reduce_motion,

View file

@ -58,6 +58,7 @@ export default class Status extends ImmutablePureComponent {
'settings', 'settings',
'prepend', 'prepend',
'boostModal', 'boostModal',
'favouriteModal',
'muted', 'muted',
'collapse', 'collapse',
'notification', 'notification',
@ -204,8 +205,8 @@ export default class Status extends ImmutablePureComponent {
this.props.onReply(this.props.status, this.context.router.history); this.props.onReply(this.props.status, this.context.router.history);
} }
handleHotkeyFavourite = () => { handleHotkeyFavourite = (e) => {
this.props.onFavourite(this.props.status); this.props.onFavourite(this.props.status, e);
} }
handleHotkeyBoost = e => { handleHotkeyBoost = e => {

View file

@ -71,8 +71,8 @@ export default class StatusActionBar extends ImmutablePureComponent {
}); });
} }
handleFavouriteClick = () => { handleFavouriteClick = (e) => {
this.props.onFavourite(this.props.status); this.props.onFavourite(this.props.status, e);
} }
handleReblogClick = (e) => { handleReblogClick = (e) => {

View file

@ -20,7 +20,7 @@ import { initMuteModal } from 'flavours/glitch/actions/mutes';
import { initReport } from 'flavours/glitch/actions/reports'; import { initReport } from 'flavours/glitch/actions/reports';
import { openModal } from 'flavours/glitch/actions/modal'; import { openModal } from 'flavours/glitch/actions/modal';
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
import { boostModal, deleteModal } from 'flavours/glitch/util/initial_state'; import { boostModal, favouriteModal, deleteModal } from 'flavours/glitch/util/initial_state';
const messages = defineMessages({ const messages = defineMessages({
deleteConfirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' }, deleteConfirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' },
@ -78,11 +78,19 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
} }
}, },
onFavourite (status) { onModalFavourite (status) {
dispatch(favourite(status));
},
onFavourite (status, e) {
if (status.get('favourited')) { if (status.get('favourited')) {
dispatch(unfavourite(status)); dispatch(unfavourite(status));
} else { } else {
dispatch(favourite(status)); if (e.shiftKey || !favouriteModal) {
this.onModalFavourite(status);
} else {
dispatch(openModal('FAVOURITE', { status, onFavourite: this.onModalFavourite }));
}
} }
}, },

View file

@ -48,8 +48,8 @@ export default class ActionBar extends React.PureComponent {
this.props.onReblog(this.props.status, e); this.props.onReblog(this.props.status, e);
} }
handleFavouriteClick = () => { handleFavouriteClick = (e) => {
this.props.onFavourite(this.props.status); this.props.onFavourite(this.props.status, e);
} }
handleDeleteClick = () => { handleDeleteClick = () => {

View file

@ -30,7 +30,7 @@ import { openModal } from 'flavours/glitch/actions/modal';
import { defineMessages, injectIntl } from 'react-intl'; import { defineMessages, injectIntl } from 'react-intl';
import ImmutablePureComponent from 'react-immutable-pure-component'; import ImmutablePureComponent from 'react-immutable-pure-component';
import { HotKeys } from 'react-hotkeys'; import { HotKeys } from 'react-hotkeys';
import { boostModal, deleteModal } from 'flavours/glitch/util/initial_state'; import { boostModal, favouriteModal, deleteModal } from 'flavours/glitch/util/initial_state';
import { attachFullscreenListener, detachFullscreenListener, isFullscreen } from 'flavours/glitch/util/fullscreen'; import { attachFullscreenListener, detachFullscreenListener, isFullscreen } from 'flavours/glitch/util/fullscreen';
const messages = defineMessages({ const messages = defineMessages({
@ -95,11 +95,19 @@ export default class Status extends ImmutablePureComponent {
} }
}; };
handleFavouriteClick = (status) => { handleModalFavourite = (status) => {
this.props.dispatch(favourite(status));
}
handleFavouriteClick = (status, e) => {
if (status.get('favourited')) { if (status.get('favourited')) {
this.props.dispatch(unfavourite(status)); this.props.dispatch(unfavourite(status));
} else { } else {
this.props.dispatch(favourite(status)); if (e.shiftKey || !favouriteModal) {
this.handleModalFavourite(status);
} else {
this.props.dispatch(openModal('FAVOURITE', { status, onFavourite: this.handleModalFavourite }));
}
} }
} }

View file

@ -0,0 +1,84 @@
import React from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes';
import PropTypes from 'prop-types';
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
import Button from 'flavours/glitch/components/button';
import StatusContent from 'flavours/glitch/components/status_content';
import Avatar from 'flavours/glitch/components/avatar';
import RelativeTimestamp from 'flavours/glitch/components/relative_timestamp';
import DisplayName from 'flavours/glitch/components/display_name';
import ImmutablePureComponent from 'react-immutable-pure-component';
const messages = defineMessages({
favourite: { id: 'status.favourite', defaultMessage: 'Favourite' },
});
@injectIntl
export default class FavouriteModal extends ImmutablePureComponent {
static contextTypes = {
router: PropTypes.object,
};
static propTypes = {
status: ImmutablePropTypes.map.isRequired,
onFavourite: PropTypes.func.isRequired,
onClose: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
};
componentDidMount() {
this.button.focus();
}
handleFavourite = () => {
this.props.onFavourite(this.props.status);
this.props.onClose();
}
handleAccountClick = (e) => {
if (e.button === 0) {
e.preventDefault();
this.props.onClose();
this.context.router.history.push(`/accounts/${this.props.status.getIn(['account', 'id'])}`);
}
}
setRef = (c) => {
this.button = c;
}
render () {
const { status, intl } = this.props;
return (
<div className='modal-root__modal favourite-modal'>
<div className='favourite-modal__container'>
<div className='status light'>
<div className='favourite-modal__status-header'>
<div className='favourite-modal__status-time'>
<a href={status.get('url')} className='status__relative-time' target='_blank' rel='noopener'><RelativeTimestamp timestamp={status.get('created_at')} /></a>
</div>
<a onClick={this.handleAccountClick} href={status.getIn(['account', 'url'])} className='status__display-name'>
<div className='status__avatar'>
<Avatar account={status.get('account')} size={48} />
</div>
<DisplayName account={status.get('account')} />
</a>
</div>
<StatusContent status={status} />
</div>
</div>
<div className='favourite-modal__action-bar'>
<div><FormattedMessage id='favourite_modal.combo' defaultMessage='You can press {combo} to skip this next time' values={{ combo: <span>Shift + <i className='fa fa-star' /></span> }} /></div>
<Button text={intl.formatMessage(messages.favourite)} onClick={this.handleFavourite} ref={this.setRef} />
</div>
</div>
);
}
}

View file

@ -7,6 +7,7 @@ import ActionsModal from './actions_modal';
import MediaModal from './media_modal'; import MediaModal from './media_modal';
import VideoModal from './video_modal'; import VideoModal from './video_modal';
import BoostModal from './boost_modal'; import BoostModal from './boost_modal';
import FavouriteModal from './favourite_modal';
import DoodleModal from './doodle_modal'; import DoodleModal from './doodle_modal';
import ConfirmationModal from './confirmation_modal'; import ConfirmationModal from './confirmation_modal';
import { import {
@ -23,6 +24,7 @@ const MODAL_COMPONENTS = {
'ONBOARDING': OnboardingModal, 'ONBOARDING': OnboardingModal,
'VIDEO': () => Promise.resolve({ default: VideoModal }), 'VIDEO': () => Promise.resolve({ default: VideoModal }),
'BOOST': () => Promise.resolve({ default: BoostModal }), 'BOOST': () => Promise.resolve({ default: BoostModal }),
'FAVOURITE': () => Promise.resolve({ default: FavouriteModal }),
'DOODLE': () => Promise.resolve({ default: DoodleModal }), 'DOODLE': () => Promise.resolve({ default: DoodleModal }),
'CONFIRM': () => Promise.resolve({ default: ConfirmationModal }), 'CONFIRM': () => Promise.resolve({ default: ConfirmationModal }),
'MUTE': MuteModal, 'MUTE': MuteModal,
@ -92,7 +94,7 @@ export default class ModalRoot extends React.PureComponent {
} }
renderLoading = modalId => () => { renderLoading = modalId => () => {
return ['MEDIA', 'VIDEO', 'BOOST', 'DOODLE', 'CONFIRM', 'ACTIONS'].indexOf(modalId) === -1 ? <ModalLoading /> : null; return ['MEDIA', 'VIDEO', 'BOOST', 'FAVOURITE', 'DOODLE', 'CONFIRM', 'ACTIONS'].indexOf(modalId) === -1 ? <ModalLoading /> : null;
} }
renderError = (props) => { renderError = (props) => {

View file

@ -34,6 +34,8 @@ const messages = {
'status.collapse': 'Collapse', 'status.collapse': 'Collapse',
'status.uncollapse': 'Uncollapse', 'status.uncollapse': 'Uncollapse',
'favourite_modal.combo': 'You can press {combo} to skip this next time',
'home.column_settings.show_direct': 'Show DMs', 'home.column_settings.show_direct': 'Show DMs',
'notification.markForDeletion': 'Mark for deletion', 'notification.markForDeletion': 'Mark for deletion',

View file

@ -3913,6 +3913,7 @@ button.icon-button.active i.fa-retweet {
} }
.boost-modal, .boost-modal,
.favourite-modal,
.confirmation-modal, .confirmation-modal,
.report-modal, .report-modal,
.actions-modal, .actions-modal,
@ -3944,7 +3945,8 @@ button.icon-button.active i.fa-retweet {
} }
} }
.boost-modal__container { .boost-modal__container,
.favourite-modal__container{
overflow-x: scroll; overflow-x: scroll;
padding: 10px; padding: 10px;
@ -3955,6 +3957,7 @@ button.icon-button.active i.fa-retweet {
} }
.boost-modal__action-bar, .boost-modal__action-bar,
.favourite-modal__action-bar,
.confirmation-modal__action-bar, .confirmation-modal__action-bar,
.mute-modal__action-bar, .mute-modal__action-bar,
.report-modal__action-bar { .report-modal__action-bar {
@ -3976,11 +3979,13 @@ button.icon-button.active i.fa-retweet {
} }
} }
.boost-modal__status-header { .boost-modal__status-header,
.favourite-modal__status-header {
font-size: 15px; font-size: 15px;
} }
.boost-modal__status-time { .boost-modal__status-time,
.favourite-modal__status-time {
float: right; float: right;
font-size: 14px; font-size: 14px;
} }

View file

@ -15,6 +15,7 @@ export const reduceMotion = getMeta('reduce_motion');
export const autoPlayGif = getMeta('auto_play_gif'); export const autoPlayGif = getMeta('auto_play_gif');
export const unfollowModal = getMeta('unfollow_modal'); export const unfollowModal = getMeta('unfollow_modal');
export const boostModal = getMeta('boost_modal'); export const boostModal = getMeta('boost_modal');
export const favouriteModal = getMeta('favourite_modal');
export const deleteModal = getMeta('delete_modal'); export const deleteModal = getMeta('delete_modal');
export const me = getMeta('me'); export const me = getMeta('me');

View file

@ -1293,6 +1293,19 @@
], ],
"path": "app/javascript/mastodon/features/ui/components/boost_modal.json" "path": "app/javascript/mastodon/features/ui/components/boost_modal.json"
}, },
{
"descriptors": [
{
"defaultMessage": "Favourite",
"id": "status.favourite"
},
{
"defaultMessage": "You can press {combo} to skip this next time",
"id": "favourite_modal.combo"
}
],
"path": "app/javascript/mastodon/features/ui/components/favourite_modal.json"
},
{ {
"descriptors": [ "descriptors": [
{ {
@ -1601,4 +1614,4 @@
], ],
"path": "app/javascript/mastodon/features/video/index.json" "path": "app/javascript/mastodon/features/video/index.json"
} }
] ]

View file

@ -21,6 +21,7 @@ class UserSettingsDecorator
user.settings['default_sensitive'] = default_sensitive_preference if change?('setting_default_sensitive') user.settings['default_sensitive'] = default_sensitive_preference if change?('setting_default_sensitive')
user.settings['unfollow_modal'] = unfollow_modal_preference if change?('setting_unfollow_modal') user.settings['unfollow_modal'] = unfollow_modal_preference if change?('setting_unfollow_modal')
user.settings['boost_modal'] = boost_modal_preference if change?('setting_boost_modal') user.settings['boost_modal'] = boost_modal_preference if change?('setting_boost_modal')
user.settings['favourite_modal'] = favourite_modal_preference if change?('setting_favourite_modal')
user.settings['delete_modal'] = delete_modal_preference if change?('setting_delete_modal') user.settings['delete_modal'] = delete_modal_preference if change?('setting_delete_modal')
user.settings['auto_play_gif'] = auto_play_gif_preference if change?('setting_auto_play_gif') user.settings['auto_play_gif'] = auto_play_gif_preference if change?('setting_auto_play_gif')
user.settings['reduce_motion'] = reduce_motion_preference if change?('setting_reduce_motion') user.settings['reduce_motion'] = reduce_motion_preference if change?('setting_reduce_motion')
@ -53,6 +54,10 @@ class UserSettingsDecorator
def boost_modal_preference def boost_modal_preference
boolean_cast_setting 'setting_boost_modal' boolean_cast_setting 'setting_boost_modal'
end end
def favourite_modal_preference
boolean_cast_setting 'setting_favourite_modal'
end
def delete_modal_preference def delete_modal_preference
boolean_cast_setting 'setting_delete_modal' boolean_cast_setting 'setting_delete_modal'

View file

@ -75,7 +75,7 @@ class User < ApplicationRecord
has_many :session_activations, dependent: :destroy has_many :session_activations, dependent: :destroy
delegate :auto_play_gif, :default_sensitive, :unfollow_modal, :boost_modal, :delete_modal, delegate :auto_play_gif, :default_sensitive, :unfollow_modal, :boost_modal, :favourite_modal, :delete_modal,
:reduce_motion, :system_font_ui, :noindex, :flavour, :skin, :reduce_motion, :system_font_ui, :noindex, :flavour, :skin,
to: :settings, prefix: :setting, allow_nil: false to: :settings, prefix: :setting, allow_nil: false

View file

@ -28,6 +28,7 @@ class InitialStateSerializer < ActiveModel::Serializer
store[:me] = object.current_account.id.to_s store[:me] = object.current_account.id.to_s
store[:unfollow_modal] = object.current_account.user.setting_unfollow_modal store[:unfollow_modal] = object.current_account.user.setting_unfollow_modal
store[:boost_modal] = object.current_account.user.setting_boost_modal store[:boost_modal] = object.current_account.user.setting_boost_modal
store[:favourite_modal] = object.current_account.user.setting_favourite_modal
store[:delete_modal] = object.current_account.user.setting_delete_modal store[:delete_modal] = object.current_account.user.setting_delete_modal
store[:auto_play_gif] = object.current_account.user.setting_auto_play_gif store[:auto_play_gif] = object.current_account.user.setting_auto_play_gif
store[:reduce_motion] = object.current_account.user.setting_reduce_motion store[:reduce_motion] = object.current_account.user.setting_reduce_motion

View file

@ -32,6 +32,7 @@
= f.input :setting_unfollow_modal, as: :boolean, wrapper: :with_label = f.input :setting_unfollow_modal, as: :boolean, wrapper: :with_label
= f.input :setting_boost_modal, as: :boolean, wrapper: :with_label = f.input :setting_boost_modal, as: :boolean, wrapper: :with_label
= f.input :setting_favourite_modal, as: :boolean, wrapper: :with_label
= f.input :setting_delete_modal, as: :boolean, wrapper: :with_label = f.input :setting_delete_modal, as: :boolean, wrapper: :with_label
.fields-group .fields-group

View file

@ -46,6 +46,7 @@ en:
setting_default_privacy: Post privacy setting_default_privacy: Post privacy
setting_default_sensitive: Always mark media as sensitive setting_default_sensitive: Always mark media as sensitive
setting_delete_modal: Show confirmation dialog before deleting a toot setting_delete_modal: Show confirmation dialog before deleting a toot
setting_favourite_modal: Show confirmation dialog before favouriting
setting_flavour: Flavour setting_flavour: Flavour
setting_noindex: Opt-out of search engine indexing setting_noindex: Opt-out of search engine indexing
setting_reduce_motion: Reduce motion in animations setting_reduce_motion: Reduce motion in animations

View file

@ -22,6 +22,7 @@ defaults: &defaults
default_sensitive: false default_sensitive: false
unfollow_modal: false unfollow_modal: false
boost_modal: false boost_modal: false
favourite_modal: false
delete_modal: true delete_modal: true
auto_play_gif: false auto_play_gif: false
reduce_motion: false reduce_motion: false