-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Frédéric Collonval
committed
Mar 2, 2021
1 parent
57d080e
commit f5bd606
Showing
6 changed files
with
159 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { IRenderMime, IRenderMimeRegistry } from '@jupyterlab/rendermime'; | ||
import { Widget } from '@lumino/widgets'; | ||
import moment from 'moment'; | ||
import { IComment } from '../../tokens'; | ||
import { generateNode } from '../../utils'; | ||
|
||
export class CommentWidget extends Widget { | ||
constructor(comment: IComment, renderMime: IRenderMimeRegistry) { | ||
const markdownRenderer = renderMime.createRenderer('text/markdown'); | ||
super({ | ||
node: CommentWidget.createNode(comment, markdownRenderer) | ||
}); | ||
this._markdownRenderer = markdownRenderer; | ||
this._markdownRenderer.renderModel({ | ||
data: { | ||
'text/markdown': comment.text | ||
}, | ||
trusted: false, | ||
metadata: {}, | ||
setData: () => null | ||
}); | ||
} | ||
|
||
protected static createNode( | ||
comment: IComment, | ||
markdownRenderer: IRenderMime.IRenderer | ||
): HTMLElement { | ||
const head = generateNode('div', { class: 'jp-PullRequestCommentItem' }); | ||
head | ||
.appendChild( | ||
generateNode('div', { class: 'jp-PullRequestCommentItemImg' }) | ||
) | ||
.appendChild( | ||
generateNode('img', { src: comment.userPicture, altText: 'Avatar' }) | ||
); | ||
const content = head.appendChild( | ||
generateNode('div', { class: 'jp-PullRequestCommentItemContent' }) | ||
); | ||
const div = content.appendChild( | ||
generateNode('div', { class: 'jp-PullRequestCommentItemContentTitle' }) | ||
); | ||
div.appendChild(generateNode('h2', null, comment.userName)); | ||
div.appendChild( | ||
generateNode( | ||
'p', | ||
{ title: new Date(comment.updatedAt).toString() }, | ||
moment(comment.updatedAt).fromNow() | ||
) | ||
); | ||
|
||
// Add rendered comment | ||
content.appendChild(markdownRenderer.node); | ||
|
||
return head; | ||
} | ||
|
||
dispose(): void { | ||
if (this.isDisposed) { | ||
return; | ||
} | ||
this._markdownRenderer.dispose(); | ||
super.dispose(); | ||
} | ||
|
||
protected _markdownRenderer: IRenderMime.IRenderer; | ||
} |
Oops, something went wrong.