display only new annotations

This commit is contained in:
Sebastian Sdorra
2020-06-12 09:08:35 +02:00
parent 9a66efc693
commit e5153b4fa9

View File

@@ -53,12 +53,29 @@ type Props = {
source: AnnotatedSource; source: AnnotatedSource;
}; };
const Author = styled.a` type LineElementProps = {
newAnnotation: boolean;
};
const Author = styled.a<LineElementProps>`
width: 8em; width: 8em;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
float: left; float: left;
visibility: ${({ newAnnotation }) => (newAnnotation ? "visible" : "hidden")};
`;
const When = styled.span<LineElementProps>`
width: 6.5em;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
float: left;
margin: 0 0.5em;
visibility: ${({ newAnnotation }) => (newAnnotation ? "visible" : "hidden")};
`; `;
const LineNumber = styled.span` const LineNumber = styled.span`
@@ -76,19 +93,10 @@ const LineNumber = styled.span`
padding: 0 0.5em; padding: 0 0.5em;
`; `;
const When = styled.span`
width: 90px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
float: left;
margin: 0 0.5em;
`;
const Annotate: FC<Props> = ({ source }) => { const Annotate: FC<Props> = ({ source }) => {
// @ts-ignore // @ts-ignore
const defaultRenderer = ({ rows, stylesheet, useInlineStyles }) => { const defaultRenderer = ({ rows, stylesheet, useInlineStyles }) => {
let lastRevision = "";
// @ts-ignore // @ts-ignore
return rows.map((node, i) => { return rows.map((node, i) => {
const line = createElement({ const line = createElement({
@@ -100,10 +108,12 @@ const Annotate: FC<Props> = ({ source }) => {
if (i + 1 < rows.length) { if (i + 1 < rows.length) {
const annotation = source.lines[i]; const annotation = source.lines[i];
const newAnnotation = annotation.revision !== lastRevision;
lastRevision = annotation.revision;
return ( return (
<span> <span>
<Author>{annotation.author.name}</Author>{" "} <Author newAnnotation={newAnnotation}>{annotation.author.name}</Author>{" "}
<When> <When newAnnotation={newAnnotation}>
<DateShort value={annotation.when} /> <DateShort value={annotation.when} />
</When>{" "} </When>{" "}
<LineNumber>{i + 1}</LineNumber> {line} <LineNumber>{i + 1}</LineNumber> {line}