Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Commit

Permalink
profile preview
Browse files Browse the repository at this point in the history
  • Loading branch information
criticalbh committed May 18, 2017
1 parent 5e8b228 commit 3cb18ca
Show file tree
Hide file tree
Showing 15 changed files with 280 additions and 289 deletions.
18 changes: 10 additions & 8 deletions client/components/article.comp.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export class ArticleComponent extends HTMLElement {
heart: 0
};
this.updateHearts = this.updateHearts.bind(this);

this.$tagList = null;
}

static get observedAttributes() {
Expand All @@ -27,6 +29,7 @@ export class ArticleComponent extends HTMLElement {

connectedCallback() {
this.innerHTML = this.render();
// this.$tagList = this.querySelector('ul.tag-list');
const button = this.querySelector('#ion-heart');
button.addEventListener('click', this.updateHearts);

Expand All @@ -41,8 +44,6 @@ export class ArticleComponent extends HTMLElement {
e.preventDefault();
RouterHandler.getInstance.router.navigate(previewLink.getAttribute('href'));
});


}


Expand Down Expand Up @@ -73,12 +74,13 @@ export class ArticleComponent extends HTMLElement {
<p>${this.model.description ? this.model.description : ''}</p>
<span>Read more...</span>
<ul class="tag-list">
<li class="tag-default tag-pill tag-outline">
well
</li>
<li class="tag-default tag-pill tag-outline">
well
</li>
${this.model.tagList.map(tag => {
return `
<li class="tag-default tag-pill tag-outline">
${tag}
</li>
`;
}).join(' ')}
</ul>
</a>
</div>
Expand Down
18 changes: 11 additions & 7 deletions client/components/comment-preview.comp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import {RouterHandler} from "../router/router-handler";

export class CommentPreviewComponent extends HTMLElement {

constructor(username, content) {
constructor() {
super();
this._username = username;
this._content = content;
this._username = null;
this._content = null;
this.authorImage = null;
this.createdAt = null;

Expand All @@ -23,6 +23,7 @@ export class CommentPreviewComponent extends HTMLElement {
}

attributeChangedCallback(name, oldValue, newValue) {

switch (name) {
case 'username' : {
this._username = newValue;
Expand All @@ -31,6 +32,7 @@ export class CommentPreviewComponent extends HTMLElement {
this._content = newValue;
}
}

this.updateScreen();
}

Expand Down Expand Up @@ -68,10 +70,12 @@ export class CommentPreviewComponent extends HTMLElement {


updateScreen() {
this.$authorUsername.textContent = this._username;
this.$authorImage.textContent = this.authorImage;
this.$createdAt.textContent = this.createdAt;
this.$content.textContent = this.content;
if (this.$authorUsername) {//dom is rendered
this.$authorUsername.textContent = this._username;
this.$authorImage.textContent = this.authorImage;
this.$createdAt.textContent = this.createdAt;
this.$content.textContent = this.content;
}
}

navigateToUser(e) {
Expand Down
42 changes: 42 additions & 0 deletions client/components/comments-container.comp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
export class CommentsContainerComponent extends HTMLElement {
constructor() {
super();
this.comments = [];
}

static get observedAttributes() {
return [];
}

attributeChangedCallback(name, oldValue, newValue) {

}

connectedCallback() {
this.slug = this.getAttribute('slug');
fetch('https://conduit.productionready.io/api/articles/' + this.slug + '/comments').then((response) => {
return response.json();
}).then(r => {
this.comments = r.comments;
this.innerHTML = this.render();
});
}

disconnectedCallback() {

}

render() {
return `
${this.comments.map(comment => {
return `
<comment-preview
username="${comment.author.username}"
content="${comment.body}">
</comment-preview>
`;
}).join(' ')}
`;
}
}
76 changes: 0 additions & 76 deletions client/components/component.dec.js

This file was deleted.

15 changes: 7 additions & 8 deletions client/components/layout/c-nav.comp.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ export class CNavComponent extends HTMLElement {
}

createProfileLinks(user) {
let newArticle = this.createNavItemLink('/editor', '<i class="ion-compose"></i>&nbsp;New Post');
let newArticle = this.createNavItemLink('#/editor', '<i class="ion-compose"></i>&nbsp;New Post');
this.$navUl.appendChild(newArticle);

let settings = this.createNavItemLink('/settings', '<i class="ion-gear-a"></i>&nbsp;Settings');
let settings = this.createNavItemLink('#/settings', '<i class="ion-gear-a"></i>&nbsp;Settings');
this.$navUl.appendChild(settings);

let userProfile = this.createNavItemLink('/profile/' + user.username, user.username);
let userProfile = this.createNavItemLink('#/profile/' + user.username, user.username);
this.$navUl.appendChild(userProfile);
}

Expand All @@ -83,7 +83,6 @@ export class CNavComponent extends HTMLElement {

setCurrentActive() {
let curUrl = location.hash;
curUrl = curUrl.substring(1);
console.log(curUrl);
this.updateActive(curUrl);
}
Expand Down Expand Up @@ -116,16 +115,16 @@ export class CNavComponent extends HTMLElement {
return `
<nav class="navbar navbar-light">
<div class="container">
<a class="navbar-brand" href="/" data-navigo >conduit</a>
<a class="navbar-brand" href="#/" data-navigo >conduit</a>
<ul class="nav navbar-nav pull-xs-right">
<li class="nav-item">
<a href="/" data-navigo class="nav-link">Home</a>
<a href="#/" data-navigo class="nav-link">Home</a>
</li>
<li id="signin" class="nav-item">
<a href="/login" data-navigo class="nav-link">Sign in</a>
<a href="#/login" data-navigo class="nav-link">Sign in</a>
</li>
<li id="signup" class="nav-item">
<a href="/register" data-navigo class="nav-link">Sign up</a>
<a href="#/register" data-navigo class="nav-link">Sign up</a>
</li>
</ul>
</div>
Expand Down
9 changes: 0 additions & 9 deletions client/components/popular-tags.comp.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ export class PopularTagsComponent extends HTMLElement {

constructor() {
super();
// var event = new CustomEvent('build', { 'detail': elem.dataset.time });
//
// // Listen for the event.
// elem.addEventListener('build', function (e) { ... }, false);
//
// // Dispatch the event.
// elem.dispatchEvent(event);
}

static get observedAttributes() {
Expand All @@ -36,11 +29,9 @@ export class PopularTagsComponent extends HTMLElement {
fetch('https://conduit.productionready.io/api/tags').then(function (response) {
return response.json();
}).then(r => {
if (tagList) {
while (tagList.firstChild) {
tagList.removeChild(tagList.firstChild);
}
}
r.tags.forEach(tag => {
let tagEl = this.createNewTagElement(tag);
tagEl.addEventListener('click', () => {
Expand Down
6 changes: 6 additions & 0 deletions client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {Authentication} from "./auth/authentication";
import {EditorComponent} from "./pages/editor.comp";
import {SettingsComponent} from "./pages/settings.comp";
import {PopularTagsComponent} from "./components/popular-tags.comp";
import {CommentsContainerComponent} from "./components/comments-container.comp";


class App {
constructor() {
Expand Down Expand Up @@ -56,6 +58,10 @@ class App {
tagName: 'comment-preview',
component: CommentPreviewComponent
},
{
tagName: 'comments-container',
component: CommentsContainerComponent
},
{
tagName: 'c-editor',
component: EditorComponent
Expand Down
Loading

0 comments on commit 3cb18ca

Please sign in to comment.