Skip to content

Commit

Permalink
Align to standardjs + fix comments edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
berzniz committed May 8, 2018
1 parent 013ae48 commit 624e547
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/js/components/branch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React from 'react'
import TreeView from 'react-treeview'
import File from './file'

const Branch = ({ nodeLabel, list, href, has_comments }) => {
const Branch = ({ nodeLabel, list, href, hasComments }) => {
if (href) {
return <File name={nodeLabel} href={href} has_comments={has_comments}/>
return <File name={nodeLabel} href={href} hasComments={hasComments} />
}

return (
Expand Down
4 changes: 2 additions & 2 deletions src/js/components/file.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react'
import fileIcons from 'file-icons-js'

const File = ({ name, href, has_comments }) => {
const File = ({ name, href, hasComments }) => {
const className = fileIcons.getClassWithColor(name)
return (
<div className='github-pr-file'>
<span className={`icon ${className}`} />
<a href={href} className='link-gray-dark'>{name}{has_comments ? ' 💬' : ''}</a>
<a href={href} className='link-gray-dark'>{name}</a> {hasComments ? ' 💬' : ''}
</div>
)
}
Expand Down
15 changes: 12 additions & 3 deletions src/js/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ const sorter = (a, b) => {
}
}

const hasCommentsForFileIndex = (fileIndex) => {
const diffTable = document.getElementById(`diff-${fileIndex}`)
if (!diffTable) {
return 0
}

return diffTable.querySelectorAll('.inline-comments').length
}

export const createFileTree = () => {
const fileInfo = [...document.querySelectorAll('.file-info > a')]
const files = fileInfo.map(({ title, href }) => {
Expand All @@ -36,13 +45,13 @@ export const createFileTree = () => {
list: []
}

files.forEach(({ parts, href }, index) => {
let has_comments = !!document.getElementsByClassName('diff-table')[index].querySelectorAll('.inline-comments').length;
files.forEach(({ parts, href }, fileIndex) => {
let location = tree
parts.forEach((part, index) => {
let node = location.list.find(node => node.nodeLabel === part)
if (!node) {
node = { nodeLabel: part, list: [], href: (index === parts.length - 1) ? href : null, has_comments }
const hasComments = (hasCommentsForFileIndex(fileIndex) > 0)
node = { nodeLabel: part, list: [], href: (index === parts.length - 1) ? href : null, hasComments }
location.list.push(node)
}
location.list = location.list.sort(sorter)
Expand Down

0 comments on commit 624e547

Please sign in to comment.