Show 'checkmark' icon when saved in editor
This commit is contained in:
@ -89,11 +89,12 @@ type KeyData = {
|
|||||||
case 's':
|
case 's':
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
return this.props.onSave({ redirect: false });
|
this.props.onSave();
|
||||||
|
return state;
|
||||||
case 'enter':
|
case 'enter':
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
this.props.onSave();
|
this.props.onSave({ redirect: false });
|
||||||
return state;
|
return state;
|
||||||
case 'escape':
|
case 'escape':
|
||||||
return this.props.onCancel();
|
return this.props.onCancel();
|
||||||
|
21
frontend/components/Icon/CheckIcon.js
Normal file
21
frontend/components/Icon/CheckIcon.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// @flow
|
||||||
|
import React from 'react';
|
||||||
|
import Icon from './Icon';
|
||||||
|
import type { Props } from './Icon';
|
||||||
|
|
||||||
|
export default function CheckIcon(props: Props) {
|
||||||
|
return (
|
||||||
|
<Icon {...props}>
|
||||||
|
<svg
|
||||||
|
fill="#000000"
|
||||||
|
height="24"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
width="24"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
>
|
||||||
|
<path d="M0 0h24v24H0z" fill="none" />
|
||||||
|
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z" />
|
||||||
|
</svg>
|
||||||
|
</Icon>
|
||||||
|
);
|
||||||
|
}
|
@ -1,14 +1,17 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { observer } from 'mobx-react';
|
import styled from 'styled-components';
|
||||||
|
import CheckIcon from 'components/Icon/CheckIcon';
|
||||||
|
import { fadeAndScaleIn } from 'styles/animations';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
onClick: Function,
|
onClick: Function,
|
||||||
|
showCheckmark: boolean,
|
||||||
disabled?: boolean,
|
disabled?: boolean,
|
||||||
isNew?: boolean,
|
isNew?: boolean,
|
||||||
};
|
};
|
||||||
|
|
||||||
@observer class SaveAction extends React.Component {
|
class SaveAction extends React.Component {
|
||||||
props: Props;
|
props: Props;
|
||||||
|
|
||||||
onClick = (event: MouseEvent) => {
|
onClick = (event: MouseEvent) => {
|
||||||
@ -19,21 +22,38 @@ type Props = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { disabled, isNew } = this.props;
|
const { showCheckmark, disabled, isNew } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<Link
|
||||||
<a
|
href
|
||||||
href
|
onClick={this.onClick}
|
||||||
onClick={this.onClick}
|
style={{ opacity: disabled ? 0.5 : 1 }}
|
||||||
style={{ opacity: disabled ? 0.5 : 1 }}
|
title="Save changes (Cmd+Enter)"
|
||||||
title="Save changes (Cmd+Enter)"
|
>
|
||||||
>
|
{showCheckmark && <SavedIcon />}
|
||||||
{isNew ? 'Publish' : 'Save'}
|
{isNew ? 'Publish' : 'Save'}
|
||||||
</a>
|
</Link>
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Link = styled.a`
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
`;
|
||||||
|
|
||||||
|
const SavedIcon = styled(CheckIcon)`
|
||||||
|
animation: ${fadeAndScaleIn} 250ms ease;
|
||||||
|
display: inline-block;
|
||||||
|
margin-right: 4px;
|
||||||
|
width: 18px;
|
||||||
|
height: 18px;
|
||||||
|
|
||||||
|
svg {
|
||||||
|
width: 18px;
|
||||||
|
height: 18px;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
export default SaveAction;
|
export default SaveAction;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import ReactModal from 'react-modal';
|
import ReactModal from 'react-modal';
|
||||||
import { modalFadeIn } from 'styles/animations';
|
import { fadeAndScaleIn } from 'styles/animations';
|
||||||
|
|
||||||
import CloseIcon from 'components/Icon/CloseIcon';
|
import CloseIcon from 'components/Icon/CloseIcon';
|
||||||
import Flex from 'components/Flex';
|
import Flex from 'components/Flex';
|
||||||
@ -46,7 +46,7 @@ const Content = styled(Flex)`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
const StyledModal = styled(ReactModal)`
|
const StyledModal = styled(ReactModal)`
|
||||||
animation: ${modalFadeIn} 250ms ease;
|
animation: ${fadeAndScaleIn} 250ms ease;
|
||||||
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0;
|
top: 0;
|
||||||
|
@ -37,6 +37,7 @@ type Props = {
|
|||||||
|
|
||||||
@observer class DocumentScene extends Component {
|
@observer class DocumentScene extends Component {
|
||||||
props: Props;
|
props: Props;
|
||||||
|
savedTimeout: number;
|
||||||
state: {
|
state: {
|
||||||
newDocument?: Document,
|
newDocument?: Document,
|
||||||
};
|
};
|
||||||
@ -44,6 +45,7 @@ type Props = {
|
|||||||
isDragging: false,
|
isDragging: false,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
newDocument: undefined,
|
newDocument: undefined,
|
||||||
|
showAsSaved: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@ -108,9 +110,19 @@ type Props = {
|
|||||||
|
|
||||||
if (redirect || this.props.newDocument) {
|
if (redirect || this.props.newDocument) {
|
||||||
this.props.history.push(document.url);
|
this.props.history.push(document.url);
|
||||||
|
} else {
|
||||||
|
this.showAsSaved();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
showAsSaved() {
|
||||||
|
this.setState({ showAsSaved: true });
|
||||||
|
this.savedTimeout = setTimeout(
|
||||||
|
() => this.setState({ showAsSaved: false }),
|
||||||
|
2000
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
onImageUploadStart() {
|
onImageUploadStart() {
|
||||||
this.setState({ isLoading: true });
|
this.setState({ isLoading: true });
|
||||||
}
|
}
|
||||||
@ -204,6 +216,7 @@ type Props = {
|
|||||||
<HeaderAction>
|
<HeaderAction>
|
||||||
{isEditing
|
{isEditing
|
||||||
? <SaveAction
|
? <SaveAction
|
||||||
|
showCheckmark={this.state.showAsSaved}
|
||||||
onClick={this.onSave.bind(this, true)}
|
onClick={this.onSave.bind(this, true)}
|
||||||
disabled={get(this.document, 'isSaving')}
|
disabled={get(this.document, 'isSaving')}
|
||||||
isNew={!!isNew}
|
isNew={!!isNew}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import { keyframes } from 'styled-components';
|
import { keyframes } from 'styled-components';
|
||||||
|
|
||||||
export const modalFadeIn = keyframes`
|
export const fadeAndScaleIn = keyframes`
|
||||||
from {
|
from {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
transform: scale(.98);
|
transform: scale(.98);
|
||||||
|
Reference in New Issue
Block a user