Skip to content

Commit

Permalink
Change design of modal loading and error screens in web UI (mastodon#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Gargron authored Nov 29, 2024
1 parent eef8d2c commit 7f2cfcc
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 234 deletions.
22 changes: 22 additions & 0 deletions app/javascript/mastodon/components/gif.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useHovering } from '@/hooks/useHovering';
import { autoPlayGif } from 'mastodon/initial_state';

export const GIF: React.FC<{
src: string;
staticSrc: string;
className: string;
animate?: boolean;
}> = ({ src, staticSrc, className, animate = autoPlayGif }) => {
const { hovering, handleMouseEnter, handleMouseLeave } = useHovering(animate);

return (
<img
className={className}
src={hovering || animate ? src : staticSrc}
alt=''
role='presentation'
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,58 +9,7 @@ import { Link } from 'react-router-dom';

import { Button } from 'mastodon/components/button';
import Column from 'mastodon/components/column';
import { autoPlayGif } from 'mastodon/initial_state';

class GIF extends PureComponent {

static propTypes = {
src: PropTypes.string.isRequired,
staticSrc: PropTypes.string.isRequired,
className: PropTypes.string,
animate: PropTypes.bool,
};

static defaultProps = {
animate: autoPlayGif,
};

state = {
hovering: false,
};

handleMouseEnter = () => {
const { animate } = this.props;

if (!animate) {
this.setState({ hovering: true });
}
};

handleMouseLeave = () => {
const { animate } = this.props;

if (!animate) {
this.setState({ hovering: false });
}
};

render () {
const { src, staticSrc, className, animate } = this.props;
const { hovering } = this.state;

return (
<img
className={className}
src={(hovering || animate) ? src : staticSrc}
alt=''
role='presentation'
onMouseEnter={this.handleMouseEnter}
onMouseLeave={this.handleMouseLeave}
/>
);
}

}
import { GIF } from 'mastodon/components/gif';

class CopyButton extends PureComponent {

Expand Down

This file was deleted.

18 changes: 0 additions & 18 deletions app/javascript/mastodon/features/ui/components/modal_loading.jsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { useCallback } from 'react';

import { FormattedMessage } from 'react-intl';

import { Button } from 'mastodon/components/button';
import { GIF } from 'mastodon/components/gif';
import { LoadingIndicator } from 'mastodon/components/loading_indicator';

export const ModalPlaceholder: React.FC<{
loading: boolean;
onClose: (arg0: string | undefined, arg1: boolean) => void;
onRetry?: () => void;
}> = ({ loading, onClose, onRetry }) => {
const handleClose = useCallback(() => {
onClose(undefined, false);
}, [onClose]);

const handleRetry = useCallback(() => {
if (onRetry) onRetry();
}, [onRetry]);

return (
<div className='modal-root__modal modal-placeholder' aria-busy={loading}>
{loading ? (
<LoadingIndicator />
) : (
<div className='modal-placeholder__error'>
<GIF
src='/oops.gif'
staticSrc='/oops.png'
className='modal-placeholder__error__image'
/>

<div className='modal-placeholder__error__message'>
<p>
<FormattedMessage
id='bundle_modal_error.message'
defaultMessage='Something went wrong while loading this screen.'
/>
</p>

<div className='modal-placeholder__error__message__actions'>
<Button onClick={handleRetry}>
<FormattedMessage
id='bundle_modal_error.retry'
defaultMessage='Try again'
/>
</Button>
<Button onClick={handleClose} className='button button-tertiary'>
<FormattedMessage
id='bundle_modal_error.close'
defaultMessage='Close'
/>
</Button>
</div>
</div>
</div>
)}
</div>
);
};
13 changes: 7 additions & 6 deletions app/javascript/mastodon/features/ui/components/modal_root.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import BundleContainer from '../containers/bundle_container';
import ActionsModal from './actions_modal';
import AudioModal from './audio_modal';
import { BoostModal } from './boost_modal';
import BundleModalError from './bundle_modal_error';
import {
ConfirmationModal,
ConfirmDeleteStatusModal,
Expand All @@ -40,7 +39,7 @@ import {
import FocalPointModal from './focal_point_modal';
import ImageModal from './image_modal';
import MediaModal from './media_modal';
import ModalLoading from './modal_loading';
import { ModalPlaceholder } from './modal_placeholder';
import VideoModal from './video_modal';

export const MODAL_COMPONENTS = {
Expand Down Expand Up @@ -105,14 +104,16 @@ export default class ModalRoot extends PureComponent {
this.setState({ backgroundColor: color });
};

renderLoading = modalId => () => {
return ['MEDIA', 'VIDEO', 'BOOST', 'CONFIRM', 'ACTIONS'].indexOf(modalId) === -1 ? <ModalLoading /> : null;
renderLoading = () => {
const { onClose } = this.props;

return <ModalPlaceholder loading onClose={onClose} />;
};

renderError = (props) => {
const { onClose } = this.props;

return <BundleModalError {...props} onClose={onClose} />;
return <ModalPlaceholder {...props} onClose={onClose} />;
};

handleClose = (ignoreFocus = false) => {
Expand All @@ -134,7 +135,7 @@ export default class ModalRoot extends PureComponent {
<Base backgroundColor={backgroundColor} onClose={this.handleClose} ignoreFocus={ignoreFocus}>
{visible && (
<>
<BundleContainer fetchComponent={MODAL_COMPONENTS[type]} loading={this.renderLoading(type)} error={this.renderError} renderDelay={200}>
<BundleContainer fetchComponent={MODAL_COMPONENTS[type]} loading={this.renderLoading} error={this.renderError} renderDelay={200}>
{(SpecificComponent) => {
const ref = typeof SpecificComponent !== 'function' ? this.setModalRef : undefined;
return <SpecificComponent {...props} onChangeBackgroundColor={this.setBackgroundColor} onClose={this.handleClose} ref={ref} />;
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/mastodon/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
"bundle_column_error.routing.body": "The requested page could not be found. Are you sure the URL in the address bar is correct?",
"bundle_column_error.routing.title": "404",
"bundle_modal_error.close": "Close",
"bundle_modal_error.message": "Something went wrong while loading this component.",
"bundle_modal_error.message": "Something went wrong while loading this screen.",
"bundle_modal_error.retry": "Try again",
"closed_registrations.other_server_instructions": "Since Mastodon is decentralized, you can create an account on another server and still interact with this one.",
"closed_registrations_modal.description": "Creating an account on {domain} is currently not possible, but please keep in mind that you do not need an account specifically on {domain} to use Mastodon.",
Expand Down
Loading

0 comments on commit 7f2cfcc

Please sign in to comment.