Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
13 changes: 13 additions & 0 deletions browser/components/TodoListPercentage.styl
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
27 changes: 27 additions & 0 deletions browser/components/TodolistPercentage.js
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>
Copy link
Contributor

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 😄

</div>
</div>
)

TodoListPercentage.propTypes = {
percentageOfTodo: PropTypes.number.isRequired
}

export default CSSModules(TodoListPercentage, styles)
22 changes: 22 additions & 0 deletions browser/main/Detail/MarkdownNoteDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -95,6 +96,24 @@ class MarkdownNoteDetail extends React.Component {
return title
}

getPercentageOfCompleteTodo (value) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer the name of the argument is noteContent.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for commenting ! Surely it is difficult to understand it mean. I'll fix it.

let splitted = value.split('\n')
let numberOfTodo = 0
let numberOfCompletedTodo = 0

for (let i = 0; i < splitted.length; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume forEach is better than for in this case.

Copy link
Member Author

@sosukesuzuki sosukesuzuki May 10, 2017

Choose a reason for hiding this comment

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

Thank you for commenting! Surely, It's long to using for than using foreach. So, I'll fix it.

let trimmedLine = splitted[i].trim()
if (trimmedLine.match(/^- \[\s|x\] ./)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to add + and * as statements.

+

screen shot 2017-05-06 at 08 20 40

*

screen shot 2017-05-06 at 08 22 05

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you for telling me. Oh... I had overlooked + and *. I'll add these operator.

numberOfTodo++
}
if (trimmedLine.match(/^- \[x\] ./)) {
numberOfCompletedTodo++
}
}

return Math.floor(numberOfCompletedTodo / numberOfTodo * 100)
}

handleChange (e) {
let { note } = this.state

Expand Down Expand Up @@ -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'>
{(() => {
Expand Down