From 693770685cc330b27eb8b1f85cbe5835d474d748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E9=A1=BA=E5=BC=BA?= Date: Mon, 14 Jan 2019 11:38:11 +0800 Subject: [PATCH] optimized tag-item-hover state (#2822) --- .../components/dialog/edit-filetag-dialog.js | 137 ++++++++++++------ frontend/src/css/repo-tag.css | 3 +- 2 files changed, 94 insertions(+), 46 deletions(-) diff --git a/frontend/src/components/dialog/edit-filetag-dialog.js b/frontend/src/components/dialog/edit-filetag-dialog.js index 841609e8e8..c20957c4ff 100644 --- a/frontend/src/components/dialog/edit-filetag-dialog.js +++ b/frontend/src/components/dialog/edit-filetag-dialog.js @@ -5,6 +5,87 @@ import { gettext } from '../../utils/constants'; import { seafileAPI } from '../../utils/seafile-api'; import RepoTag from '../../models/repo-tag'; +const TagItemPropTypes = { + repoTag: PropTypes.object.isRequired, + fileTagList: PropTypes.array.isRequired, + onEditFileTag: PropTypes.func.isRequired, +}; + +class TagItem extends React.Component { + + constructor(props) { + super(props); + this.state = { + showSelectedTag: false + }; + } + + onMouseEnter = () => { + this.setState({ + showSelectedTag: true + }); + } + + onMouseLeave = () => { + this.setState({ + showSelectedTag: false + }); + } + + getRepoTagIdList = () => { + let repoTagIdList = []; + let fileTagList = this.props.fileTagList; + fileTagList.map((fileTag) => { + repoTagIdList.push(fileTag.repo_tag_id); + }); + return repoTagIdList; + } + + onEditFileTag = () => { + let { repoID, repoTag, filePath } = this.props; + let repoTagIdList = this.getRepoTagIdList(); + if (repoTagIdList.indexOf(repoTag.id) === -1) { + let id = repoTag.id; + seafileAPI.addFileTag(repoID, filePath, id).then(() => { + repoTagIdList = this.getRepoTagIdList(); + this.props.onEditFileTag(); + }); + } else { + let fileTag = null; + let fileTagList = this.props.fileTagList; + for(let i = 0; i < fileTagList.length; i++) { + if (fileTagList[i].repo_tag_id === repoTag.id) { + fileTag = fileTagList[i]; + break; + } + } + seafileAPI.deleteFileTag(repoID, fileTag.id).then(() => { + repoTagIdList = this.getRepoTagIdList(); + this.props.onEditFileTag(); + }); + } + } + + render() { + let repoTag = this.props.repoTag; + let repoTagIdList = this.getRepoTagIdList(); + return ( +
  • +
    + + {repoTag.name} + {repoTagIdList.indexOf(repoTag.id) > -1 && + + } +
    +
  • + ) + } + +} + +TagItem.propTypes = TagItemPropTypes; + const propTypes = { repoID: PropTypes.string.isRequired, filePath: PropTypes.string.isRequired, @@ -39,47 +120,15 @@ class EditFileTagDialog extends React.Component { }); } - getRepoTagIdList = () => { - let repoTagIdList = []; - let fileTagList = this.props.fileTagList; - fileTagList.map((fileTag) => { - repoTagIdList.push(fileTag.repo_tag_id); - }); - return repoTagIdList; - } - - editFileTag = (repoTag) => { - let repoID = this.props.repoID; - let repoTagIdList = this.getRepoTagIdList(); - if (repoTagIdList.indexOf(repoTag.id) === -1) { - let id = repoTag.id; - let filePath = this.props.filePath; - seafileAPI.addFileTag(repoID, filePath, id).then(() => { - repoTagIdList = this.getRepoTagIdList(); - this.props.onFileTagChanged(); - }); - } else { - let fileTag = null; - let fileTagList = this.props.fileTagList; - for(let i = 0; i < fileTagList.length; i++) { - if (fileTagList[i].repo_tag_id === repoTag.id) { - fileTag = fileTagList[i]; - break; - } - } - seafileAPI.deleteFileTag(repoID, fileTag.id).then(() => { - repoTagIdList = this.getRepoTagIdList(); - this.props.onFileTagChanged(); - }); - } - } - toggle = () => { this.props.toggleCancel(); } + onEditFileTag = () => { + this.props.onFileTagChanged(); + } + render() { - let repoTagIdList = this.getRepoTagIdList(); return ( {gettext('Select Tags')} @@ -88,14 +137,14 @@ class EditFileTagDialog extends React.Component { diff --git a/frontend/src/css/repo-tag.css b/frontend/src/css/repo-tag.css index 23d0181740..cca3b77c92 100644 --- a/frontend/src/css/repo-tag.css +++ b/frontend/src/css/repo-tag.css @@ -31,11 +31,10 @@ align-items: center; color: #ffffff; overflow: hidden; - padding: 10px; } .show-tag-selected { - width: .5em; + width: 0.5rem; align-self: stretch; }