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
e128a64
commit a0415b1
Showing
9 changed files
with
381 additions
and
145 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
import {Authentication} from "../auth/authentication"; | ||
export class ArticlePreviewBannerComponent extends HTMLElement { | ||
|
||
constructor() { | ||
super(); | ||
this.auth = Authentication.instance.auth; | ||
this.followButtonAction = this.followButtonAction.bind(this); | ||
this._title = null; | ||
this._username = null; | ||
this._favoritesCount = null; | ||
this._date = null; | ||
this._image = null; | ||
} | ||
|
||
static get observedAttributes() { | ||
return ['title', 'username', 'favorites-count', 'date', 'image']; | ||
} | ||
|
||
attributeChangedCallback(name, oldValue, newValue) { | ||
if (newValue) { | ||
switch (name) { | ||
case 'title': { | ||
this._title = newValue; | ||
break; | ||
} | ||
case 'username': { | ||
this._username = newValue; | ||
break; | ||
} | ||
case 'favorites-count' : { | ||
this._favoritesCount = newValue; | ||
break; | ||
} | ||
case 'date' : { | ||
this._date = newValue; | ||
break; | ||
} | ||
case 'image': { | ||
this._image = newValue; | ||
break; | ||
} | ||
} | ||
this.innerHTML = this.render(); | ||
} | ||
} | ||
|
||
connectedCallback() { | ||
this.innerHTML = this.render(); | ||
} | ||
|
||
followButtonAction(e) { | ||
|
||
} | ||
|
||
disconnectedCallback() { | ||
if (this.$followButton) { | ||
this.$followButton.removeEventListener('click', this.followButtonAction); | ||
} | ||
} | ||
|
||
|
||
render() { | ||
return ` | ||
<div class="banner"> | ||
<div class="container"> | ||
<h1 id="article-title"> | ||
${this.title} | ||
</h1> | ||
<div class="article-meta"> | ||
<a href=""> | ||
<img src="${this.image}" alt="no img" /> | ||
</a> | ||
<div class="info"> | ||
<a id="profile-username" href="" class="author">${this._username}</a> | ||
<span id="article-date" class="date">${this.date}</span> | ||
</div> | ||
${ | ||
this.auth && this.auth.username === this.username ? | ||
` | ||
<span> | ||
<a class="btn btn-outline-secondary btn-sm" href="#/editor/asdasd-d1z1f3"> | ||
<i class="ion-edit"></i>TODO Edit Article | ||
</a> | ||
<button class="btn btn-outline-danger btn-sm"><i class="ion-trash-a"> | ||
</i>TODO Delete Article</button> | ||
</span>` : ` | ||
<button class="btn btn-sm btn-outline-secondary"> | ||
<i class="ion-plus-round"></i> | ||
| ||
TODO Follow ${this._username} | ||
</button> | ||
| ||
<button class="btn btn-sm btn-outline-secondary"> | ||
<i class="ion-heart"></i> | ||
| ||
TODO Favorite Post <span class="counter">${this.favoritesCount}</span> | ||
</button>` | ||
} | ||
</div> | ||
</div> | ||
</div> | ||
`; | ||
} | ||
|
||
set title(value) { | ||
this.setAttribute('title', value); | ||
} | ||
|
||
get title() { | ||
return this._title; | ||
} | ||
|
||
set username(value) { | ||
this.setAttribute('username', value); | ||
} | ||
|
||
get username() { | ||
return this._username; | ||
} | ||
|
||
set favoritesCount(value) { | ||
this.setAttribute('favorites-count', value); | ||
} | ||
|
||
get favoritesCount() { | ||
return this._favoritesCount; | ||
} | ||
|
||
set date(value) { | ||
this.setAttribute('date', value); | ||
} | ||
|
||
get date() { | ||
return this._date; | ||
} | ||
|
||
set image(value) { | ||
this.setAttribute('image', value); | ||
} | ||
|
||
get image() { | ||
return this._image; | ||
} | ||
} |
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,74 @@ | ||
import {Authentication} from "../auth/authentication"; | ||
export class CommentCreateComponent extends HTMLElement { | ||
constructor() { | ||
super(); | ||
this.postComment = this.postComment.bind(this); | ||
this.auth = Authentication.instance.auth; | ||
this.image = "https://static.productionready.io/images/smiley-cyrus.jpg"; | ||
if (this.auth) { | ||
this.image = this.auth.image; | ||
} | ||
} | ||
|
||
static get observedAttributes() { | ||
return []; | ||
} | ||
|
||
attributeChangedCallback(name, oldValue, newValue) { | ||
} | ||
|
||
connectedCallback() { | ||
if (this.auth) { | ||
this.innerHTML = this.renderCommentForm(); | ||
this.$postCommentBtn = this.querySelector('#postCommentBtn'); | ||
this.$commentValue = this.querySelector('#comment-value'); | ||
this.$postCommentBtn.addEventListener('click', this.postComment) | ||
} else { | ||
this.innerHTML = this.renderLoginButtons(); | ||
} | ||
} | ||
|
||
postComment(e) { | ||
e.preventDefault(); | ||
var event = new CustomEvent('comment', {'detail': this.$commentValue.value}); | ||
this.dispatchEvent(event); | ||
} | ||
|
||
disconnectedCallback() { | ||
if (this.auth) { | ||
this.$postCommentBtn.removeEventListener('click', this.postComment) | ||
} | ||
} | ||
|
||
renderCommentForm() { | ||
return ` | ||
<form class="card comment-form"> | ||
<div class="card-block"> | ||
<textarea id="comment-value" class="form-control" placeholder="TODO - Write a comment..." rows="3"></textarea> | ||
</div> | ||
<div class="card-footer"> | ||
<img src="${this.image ? this.image : 'https://static.productionready.io/images/smiley-cyrus.jpg'}" class="comment-author-img" /> | ||
<button id="postCommentBtn" class="btn btn-sm btn-primary"> | ||
Post Comment | ||
</button> | ||
</div> | ||
</form> | ||
`; | ||
} | ||
|
||
renderLoginButtons() { | ||
return ` | ||
<div class="col-xs-12 col-md-8 offset-md-2"> | ||
<p> | ||
<a class="" href="#/login">Sign in</a> | ||
or | ||
<a class="" href="#/register">sign up</a> | ||
to add comments on this article. | ||
</p> | ||
<div> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import {Authentication} from "../auth/authentication"; | ||
export class UserInfoComponent extends HTMLElement { | ||
|
||
constructor() { | ||
super(); | ||
this.auth = Authentication.instance.auth; | ||
this.followButtonAction = this.followButtonAction.bind(this); | ||
} | ||
|
||
static get observedAttributes() { | ||
return []; | ||
} | ||
|
||
attributeChangedCallback(name, oldValue, newValue) { | ||
|
||
} | ||
|
||
connectedCallback() { | ||
this.username = this.getAttribute('username'); | ||
fetch('https://conduit.productionready.io/api/profiles/' + this.username).then((response) => { | ||
return response.json(); | ||
}).then(r => { | ||
this.model = r.profile; | ||
this.innerHTML = this.render(); | ||
this.$followButton = this.querySelector('#follow-button'); | ||
if(this.$followButton) { | ||
this.$followButton.addEventListener('click', this.followButtonAction); | ||
} | ||
}); | ||
} | ||
|
||
followButtonAction(e) { | ||
|
||
} | ||
|
||
disconnectedCallback() { | ||
if(this.$followButton) { | ||
this.$followButton.removeEventListener('click', this.followButtonAction); | ||
} | ||
} | ||
|
||
// this.$username = document.getElementById('username'); | ||
// this.$bio = document.getElementById('bio'); | ||
// this.userImg = document.getElementById('user-img'); | ||
|
||
// this.followButtonUsername = document.getElementById('follow-button-username'); | ||
|
||
// updateUserProfileDom() { | ||
// this.$username.textContent = this.model.username; | ||
// if(this.followButtonUsername) { | ||
// this.followButtonUsername.textContent = this.model.username; | ||
// } | ||
// this.$bio.textContent = this.model.bio; | ||
// this.userImg.setAttribute('src', this.model.image); | ||
// } | ||
|
||
render() { | ||
return ` | ||
<div class="user-info"> | ||
<div class="container"> | ||
<div class="row"> | ||
<div class="col-xs-12 col-md-10 offset-md-1"> | ||
<img id="user-img" src="${this.model.image}" class="user-img" /> | ||
<h4 id="username">${this.username}</h4> | ||
<p id="bio"> | ||
${this.model.bio ? this.model.bio : ''} | ||
</p> | ||
${!this.auth ? | ||
`<button id="follow-button" class="btn btn-sm btn-outline-secondary action-btn"> | ||
<i class="ion-plus-round"></i> | ||
| ||
Follow ${this.username} | ||
</button>` : | ||
`<a class="btn btn-sm btn-outline-secondary action-btn" href="/#/settings"><i class="ion-gear-a"></i> Edit Profile Settings</a>` | ||
} | ||
</div> | ||
</div> | ||
</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
Oops, something went wrong.