This repository has been archived by the owner on Sep 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
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
1 parent
e07e2b2
commit 7e57754
Showing
5 changed files
with
121 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import {RouterHandler} from "../router/router-handler"; | ||
"use strict"; | ||
|
||
export class CommentPreviewComponent extends HTMLElement { | ||
|
||
constructor(username, content) { | ||
super(); | ||
this._username = username; | ||
this._content = content; | ||
this.authorImage = null; | ||
this.createdAt = null; | ||
|
||
this.$authorUsername = null; | ||
this.$authorImage = null; | ||
this.$createdAt = null; | ||
this.$content = null; | ||
|
||
this.navigateToUser = this.navigateToUser.bind(this); | ||
} | ||
|
||
static get observedAttributes() { | ||
return ['username', 'content']; //, 'authorImage', 'createdAt', 'content' | ||
} | ||
|
||
attributeChangedCallback(name, oldValue, newValue) { | ||
switch (name) { | ||
case 'username' : { | ||
this._username = newValue; | ||
} | ||
case 'content': { | ||
this._content = newValue; | ||
} | ||
} | ||
this.updateScreen(); | ||
} | ||
|
||
disconnectedCallback() { | ||
this.$authorUsername.removeEventListener('click', this.navigateToUser); | ||
} | ||
|
||
connectedCallback() { | ||
this.innerHTML = this.render(); | ||
this.$authorUsername = this.querySelector('#author-username'); | ||
this.$authorImage = this.querySelector('#author-image'); | ||
this.$createdAt = this.querySelector('#createdAt'); | ||
this.$content = this.querySelector('#comment-content'); | ||
this.updateScreen(); | ||
|
||
|
||
this.$authorUsername.addEventListener('click', this.navigateToUser); | ||
} | ||
|
||
set username(value) { | ||
this.setAttribute('username', value); | ||
} | ||
|
||
get username() { | ||
return this._username; | ||
} | ||
|
||
get content() { | ||
return this._content; | ||
} | ||
|
||
set content(value) { | ||
this.setAttribute('content', value) | ||
} | ||
|
||
|
||
updateScreen() { | ||
this.$authorUsername.textContent = this._username; | ||
this.$authorImage.textContent = this.authorImage; | ||
this.$createdAt.textContent = this.createdAt; | ||
this.$content.textContent = this.content; | ||
} | ||
|
||
navigateToUser(e) { | ||
e.preventDefault(); | ||
RouterHandler.getInstance.router.navigate(this.$authorUsername.getAttribute('href')); | ||
} | ||
|
||
|
||
render() { | ||
return ` | ||
<div class="card"> | ||
<div class="card-block"> | ||
<p id="comment-content" class="card-text"></p> | ||
</div> | ||
<div class="card-footer"> | ||
<a href="" class="comment-author"> | ||
<img id="author-image" src="http://i.imgur.com/Qr71crq.jpg" class="comment-author-img" /> | ||
</a> | ||
| ||
<a id="author-username" href="#/profile/${this.username}" class="comment-author"></a> | ||
<span id="createdAt" class="date-posted">Dec 29th</span> | ||
</div> | ||
</div> | ||
`; | ||
} | ||
|
||
} |
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