-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
display percentage of achievement of todo in markdown #557
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
Changes from 3 commits
b58df2f
e0dc62c
34da152
e23707f
7c9d390
1c31ff4
c28980c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| .percentageBar | ||
| position absolute | ||
| background-color #bcbcbc | ||
| height 20px | ||
| width 100% | ||
|
|
||
| .progressBar | ||
| background-color #52d8a5 | ||
| height 20px | ||
| text-align center | ||
|
|
||
| .progressBar p | ||
| color white |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /** | ||
| * @fileoverview Percentage of todo achievement. | ||
| */ | ||
|
|
||
| import React, { PropTypes } from 'react' | ||
| import CSSModules from 'browser/lib/CSSModules' | ||
| import styles from './TodoListPercentage.styl' | ||
|
|
||
| /** | ||
| * @param {number} percentageOfTodo | ||
| */ | ||
|
|
||
| const TodoListPercentage = ({ | ||
| percentageOfTodo | ||
| }) => ( | ||
| <div styleName='percentageBar' style={{display: isNaN(percentageOfTodo) ? 'none' : ''}}> | ||
| <div styleName='progressBar' style={{width: percentageOfTodo + '%'}}> | ||
| <p styleName='percentageText'>{percentageOfTodo + '%'}</p> | ||
| </div> | ||
| </div> | ||
| ) | ||
|
|
||
| TodoListPercentage.propTypes = { | ||
| percentageOfTodo: PropTypes.number.isRequired | ||
| } | ||
|
|
||
| export default CSSModules(TodoListPercentage, styles) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ import React, { PropTypes } from 'react' | |
| import CSSModules from 'browser/lib/CSSModules' | ||
| import styles from './MarkdownNoteDetail.styl' | ||
| import MarkdownEditor from 'browser/components/MarkdownEditor' | ||
| import TodoListPercentage from 'browser/components/TodoListPercentage' | ||
| import StarButton from './StarButton' | ||
| import TagSelect from './TagSelect' | ||
| import FolderSelect from './FolderSelect' | ||
|
|
@@ -95,6 +96,24 @@ class MarkdownNoteDetail extends React.Component { | |
| return title | ||
| } | ||
|
|
||
| getPercentageOfCompleteTodo (value) { | ||
|
||
| let splitted = value.split('\n') | ||
| let numberOfTodo = 0 | ||
| let numberOfCompletedTodo = 0 | ||
|
|
||
| for (let i = 0; i < splitted.length; i++) { | ||
|
||
| let trimmedLine = splitted[i].trim() | ||
| if (trimmedLine.match(/^- \[\s|x\] ./)) { | ||
|
||
| numberOfTodo++ | ||
| } | ||
| if (trimmedLine.match(/^- \[x\] ./)) { | ||
| numberOfCompletedTodo++ | ||
| } | ||
| } | ||
|
|
||
| return Math.floor(numberOfCompletedTodo / numberOfTodo * 100) | ||
| } | ||
|
|
||
| handleChange (e) { | ||
| let { note } = this.state | ||
|
|
||
|
|
@@ -263,6 +282,9 @@ class MarkdownNoteDetail extends React.Component { | |
| value={this.state.note.tags} | ||
| onChange={(e) => this.handleChange(e)} | ||
| /> | ||
| <TodoListPercentage | ||
| percentageOfTodo={this.getPercentageOfCompleteTodo(note.content)} | ||
| /> | ||
| </div> | ||
| <div styleName='info-right'> | ||
| {(() => { | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use string literal 😄