From efbb61a6cb04e3e1a5eaf7f3a393c4629630f50f Mon Sep 17 00:00:00 2001 From: Danial Nickford Date: Tue, 8 May 2018 13:36:40 +1200 Subject: [PATCH 1/2] add comment icon to files with comments --- src/js/components/branch.jsx | 4 ++-- src/js/components/file.jsx | 4 ++-- src/js/lib.js | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/js/components/branch.jsx b/src/js/components/branch.jsx index 5608af2..700aaef 100644 --- a/src/js/components/branch.jsx +++ b/src/js/components/branch.jsx @@ -2,9 +2,9 @@ import React from 'react' import TreeView from 'react-treeview' import File from './file' -const Branch = ({ nodeLabel, list, href }) => { +const Branch = ({ nodeLabel, list, href, has_comments }) => { if (href) { - return + return } return ( diff --git a/src/js/components/file.jsx b/src/js/components/file.jsx index c99f37f..a518620 100644 --- a/src/js/components/file.jsx +++ b/src/js/components/file.jsx @@ -1,12 +1,12 @@ import React from 'react' import fileIcons from 'file-icons-js' -const File = ({ name, href }) => { +const File = ({ name, href, has_comments }) => { const className = fileIcons.getClassWithColor(name) return (
- {name} + {name}{has_comments ? ' 💬' : ''}
) } diff --git a/src/js/lib.js b/src/js/lib.js index 8ed5b29..bdcc890 100644 --- a/src/js/lib.js +++ b/src/js/lib.js @@ -36,12 +36,13 @@ export const createFileTree = () => { list: [] } - files.forEach(({ parts, href }) => { + files.forEach(({ parts, href }, index) => { + let has_comments = !!document.getElementsByClassName('diff-table')[index].querySelectorAll('.inline-comments').length; 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 } + node = { nodeLabel: part, list: [], href: (index === parts.length - 1) ? href : null, has_comments } location.list.push(node) } location.list = location.list.sort(sorter) From 624e547de39643678bdf3a8fdf18befb2471d3bc Mon Sep 17 00:00:00 2001 From: Tal Bereznitskey Date: Tue, 8 May 2018 10:38:57 +0300 Subject: [PATCH 2/2] Align to standardjs + fix comments edge cases --- src/js/components/branch.jsx | 4 ++-- src/js/components/file.jsx | 4 ++-- src/js/lib.js | 15 ++++++++++++--- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/js/components/branch.jsx b/src/js/components/branch.jsx index 700aaef..62b7c67 100644 --- a/src/js/components/branch.jsx +++ b/src/js/components/branch.jsx @@ -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 + return } return ( diff --git a/src/js/components/file.jsx b/src/js/components/file.jsx index a518620..02cbdde 100644 --- a/src/js/components/file.jsx +++ b/src/js/components/file.jsx @@ -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 (
- {name}{has_comments ? ' 💬' : ''} + {name} {hasComments ? ' 💬' : ''}
) } diff --git a/src/js/lib.js b/src/js/lib.js index 1dfe282..58178d1 100644 --- a/src/js/lib.js +++ b/src/js/lib.js @@ -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 }) => { @@ -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)