From fad00989f1e8cb55a01aac21a401c870e1842caf Mon Sep 17 00:00:00 2001 From: LeoSirius <851958789@qq.com> Date: Fri, 19 Apr 2019 11:57:07 +0800 Subject: [PATCH] optimize save button's status --- .../src/components/file-view/file-toolbar.js | 31 ++++++++++++------- .../src/components/file-view/file-view.js | 6 +++- frontend/src/view-file-text.js | 16 ++++++++-- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/frontend/src/components/file-view/file-toolbar.js b/frontend/src/components/file-view/file-toolbar.js index 7d06f6b2f0..ae644458f9 100644 --- a/frontend/src/components/file-view/file-toolbar.js +++ b/frontend/src/components/file-view/file-toolbar.js @@ -11,6 +11,8 @@ const propTypes = { isLocked: PropTypes.bool.isRequired, lockedByMe: PropTypes.bool.isRequired, onSaveChangedContent: PropTypes.func.isRequired, + isSaving: PropTypes.bool.isRequired, + isContentChangedButNotSaved: PropTypes.bool.isRequired, toggleLockFile: PropTypes.func.isRequired, toggleCommentPanel: PropTypes.func.isRequired }; @@ -95,17 +97,24 @@ class FileToolbar extends React.Component { /> )} {(canEditFile && !err) && - ( - )} + ( this.props.isSaving ? + : + ( + this.props.isContentChangedButNotSaved ? + : + + ) + )} {canDownloadFile && ( diff --git a/frontend/src/view-file-text.js b/frontend/src/view-file-text.js index cc54f4396a..a45ffd5009 100644 --- a/frontend/src/view-file-text.js +++ b/frontend/src/view-file-text.js @@ -43,7 +43,9 @@ class ViewFileText extends React.Component { constructor(props) { super(props); this.state = { - content: fileContent + content: fileContent, + isContentChangedButNotSaved: false, + isSaving: false, }; this.onSaveChangedContent=this.onSaveChangedContent.bind(this); } @@ -51,7 +53,8 @@ class ViewFileText extends React.Component { updateContent = (newContent) => { this.setState({ - content: newContent + isContentChangedButNotSaved: true, + content: newContent, }); } @@ -60,6 +63,9 @@ class ViewFileText extends React.Component { return ( seafileAPI.getUpdateLink(repoID, dirPath).then((res) => { const uploadLink = res.data; + this.setState({ + isSaving: true + }); return seafileAPI.updateFile( uploadLink, filePath, @@ -69,6 +75,10 @@ class ViewFileText extends React.Component { toaster.success(gettext('Successfully saved'), { duration: 3 }); + this.setState({ + isSaving: false, + isContentChangedButNotSaved: false + }); }) }) ); @@ -83,6 +93,8 @@ class ViewFileText extends React.Component { updateContent={this.updateContent} /> } + isSaving={this.state.isSaving} + isContentChangedButNotSaved={this.state.isContentChangedButNotSaved} onSaveChangedContent={this.onSaveChangedContent} /> );