Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/476 show progress indicator #527

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions src/react/containers/EditorContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class EditorContainer extends Component {
}

publish() {
const { updateEntry, entry, entryEditClose, createEntry, isEditing } = this.props;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we removing entryEditClose?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit explains it: 0ef8038

This function was used to close the editor immediately after clicking 'Publish Update'. When a user on a slower network/server clicked this, the editor disappeared instantly, however it would take several seconds for the entries text to actually update - there was no visual feedback that their action was processing.

By not using this function the editor does not instantly get removed. Not being removed right away allows the editor component to check if the store > user > entries entry has a true isPublishing state, adding necessary indicators of progress.

The editor is already set to close by changing the isEditing state to false, on the UPDATE_ENTRY_SUCCESS Redux action in the user.js reducer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes @sboisvert, I see the problem now, I had that in the wrong commit. My mistake.

const { updateEntry, entry, createEntry, isEditing } = this.props;
const { editorState, authors } = this.state;
const content = this.getContent();
const authorIds = authors.map(author => author.id);
Expand All @@ -101,7 +101,6 @@ class EditorContainer extends Component {
author,
contributors,
});
entryEditClose(entry.id);
return;
}

Expand Down Expand Up @@ -224,7 +223,20 @@ class EditorContainer extends Component {
readOnly,
} = this.state;

const { isEditing, config } = this.props;
const { isEditing, config, api, user, entry } = this.props;

const isPublishingUpdate = (
entry && user.entries[entry.id] && user.entries[entry.id].isPublishing
);
const isPublishingNew = (!isEditing && api.isPublishingNew);
const isPublishing = (isPublishingNew || isPublishingUpdate);

let publishBtnText;
if (isPublishing) {
publishBtnText = 'Publishing...';
} else {
publishBtnText = isEditing ? 'Publish Update' : 'Publish New Entry';
}

return (
<div className="liveblog-editor-container">
Expand Down Expand Up @@ -296,21 +308,22 @@ class EditorContainer extends Component {
clearable={false}
cache={false}
/>
<button className="liveblog-btn liveblog-publish-btn" onClick={this.publish.bind(this)}>
{isEditing ? 'Publish Update' : 'Publish New Entry'}
<button className={`liveblog-btn liveblog-publish-btn ${isPublishing ? 'liveblog-publish-btn--active' : ''}`} onClick={this.publish.bind(this)}>
{ publishBtnText }
</button>
</div>
);
}
}

EditorContainer.propTypes = {
api: PropTypes.object,
config: PropTypes.object,
updateEntry: PropTypes.func,
entry: PropTypes.object,
entryEditClose: PropTypes.func,
createEntry: PropTypes.func,
isEditing: PropTypes.bool,
isPublishing: PropTypes.bool,
authors: PropTypes.array,
getAuthors: PropTypes.func,
};
Expand Down
12 changes: 9 additions & 3 deletions src/react/containers/EntryContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ class EntryContainer extends Component {
constructor(props) {
super(props);

this.state = { isDeleting: false };

this.isEditing = () => {
const { user, entry } = this.props;
return user.entries[entry.id] && user.entries[entry.id].isEditing;
};
this.edit = () => this.props.entryEditOpen(this.props.entry.id);
this.close = () => this.props.entryEditClose(this.props.entry.id);
this.delete = () => this.props.deleteEntry(this.props.entry.id);
this.delete = () => {
this.setState({ isDeleting: true });
this.props.deleteEntry(this.props.entry.id);
};
this.scrollIntoView = () => {
this.node.scrollIntoView({ block: 'start', behavior: 'instant' });
this.props.resetScrollOnEntry(`id_${this.props.entry.id}`);
Expand All @@ -40,6 +45,7 @@ class EntryContainer extends Component {

entryActions() {
const { config } = this.props;
const { isDeleting } = this.state;
if (config.is_liveblog_editable !== '1') return false;

return (
Expand All @@ -54,10 +60,10 @@ class EntryContainer extends Component {
</button>
}
<button
className="liveblog-btn liveblog-btn-small liveblog-btn-delete"
className={`liveblog-btn liveblog-btn-small liveblog-btn-delete ${isDeleting ? 'liveblog-btn-delete--active' : ''}`}
onClick={this.delete}
>
Delete
{ isDeleting ? 'Deleting...' : 'Delete' }
</button>
</footer>
);
Expand Down
8 changes: 8 additions & 0 deletions src/react/reducers/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,25 @@ export const api = (state = initialState, action) => {
: state.newestEntry,
};

case 'CREATE_ENTRY':
return {
...state,
isPublishingNew: true,
};

case 'CREATE_ENTRY_SUCCESS':
return {
...state,
error: false,
nonce: action.payload.nonce,
isPublishingNew: false,
};

case 'CREATE_ENTRY_FAILED':
return {
...state,
error: true,
isPublishingNew: false,
};

case 'DELETE_ENTRY_SUCCESS':
Expand Down
41 changes: 39 additions & 2 deletions src/react/reducers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,50 @@ export const user = (state = initialState, action) => {
case 'ENTRY_EDIT_OPEN':
return {
...state,
entries: { ...state.entries, [action.payload]: { isEditing: true } },
entries: {
...state.entries,
[action.payload]: {
isEditing: true,
isPublishing: false,
},
},
};

case 'ENTRY_EDIT_CLOSE':
return {
...state,
entries: { ...state.entries, [action.payload]: { isEditing: false } },
entries: {
...state.entries,
[action.payload]:
{
isEditing: false,
isPublishing: false,
},
},
};

case 'UPDATE_ENTRY':
return {
...state,
entries: {
...state.entries,
[action.payload.id]: {
isEditing: true,
isPublishing: true,
},
},
};

case 'UPDATE_ENTRY_SUCCESS':
return {
...state,
entries: {
...state.entries,
[action.payload.entries[0].id]: {
isEditing: false,
isPublishing: false,
},
},
};

default:
Expand Down
12 changes: 12 additions & 0 deletions src/styles/core/app/_buttons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,15 @@
background: darken($color-warning, 10%);
}

.liveblog-btn-delete--active {
&, &:hover {
animation: liveblog-btn-delete--active-animation 2.5s infinite linear;
background-size: 100px 100%;
background-image: linear-gradient(-45deg,darken($color-warning, 5%) 28%,$color-warning 0,$color-warning 72%,darken($color-warning, 5%) 0);
}
}
@keyframes liveblog-btn-delete--active-animation {
0% {
background-position: 200px 0;
}
}
13 changes: 13 additions & 0 deletions src/styles/core/editor/_buttons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@
font-size: .9rem;
}

.liveblog-publish-btn--active {
&, &:hover {
animation: liveblog-publish-btn--active-animation 2.5s infinite linear;
background-size: 100px 100%;
background-image: linear-gradient(-45deg,darken($color-primary, 5%) 28%,$color-primary 0,$color-primary 72%,darken($color-primary, 5%) 0);
}
}
@keyframes liveblog-publish-btn--active-animation {
0% {
background-position: 200px 0;
}
}

.liveblog-cancel-btn {
background: $color-grey-light;
color: $color-grey-dark;
Expand Down