Skip to content
This repository was archived by the owner on Dec 18, 2024. It is now read-only.

Commit 0cba7e7

Browse files
committed
feat(news): add news comment condition to news view
Add news comment condition to the news view based on user authentication. Only logged in users are able to see the comment functionality. --- scss/include/modules/_news.scss | 6 ++++++ src/view-models/news/view.js | 10 ++++++++-- src/views/news/view.html | 4 ++-- 3 files changed, 16 insertions(+), 4 deletions(-)
1 parent 521133f commit 0cba7e7

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

scss/include/modules/_news.scss

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
}
1818

1919
.news-card-comment {
20+
margin-top: 15px;
21+
22+
&:first-child {
23+
margin-top: 0;
24+
}
25+
2026
img {
2127
margin-right: 10px;
2228
width: 32px;

src/view-models/news/view.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import {inject} from 'aurelia-framework';
2+
import {AuthService} from 'aurelia-auth';
23
import {NewsService} from '../../services/news/news-service';
34

4-
@inject(NewsService)
5+
@inject(NewsService, AuthService)
56
export class View {
6-
constructor(newsService) {
7+
constructor(newsService, authService) {
78
this.newsService = newsService;
9+
this.authService = authService;
810
}
911

1012
activate(params, routeConfig) {
@@ -17,4 +19,8 @@ export class View {
1719
this.news = null;
1820
});
1921
}
22+
23+
get isAuthenticated() {
24+
return this.authService.isAuthenticated();
25+
}
2026
}

src/views/news/view.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ <h4><a href="#/news/view/${news.id}">${news.title}</a></h4>
2121
</div>
2222
<div class="card-text">${news.text}</div>
2323
</div>
24-
<div class="card-footer">
25-
<div class="news-card-comment">
24+
<div class="card-footer" if.bind="isAuthenticated">
25+
<div class="news-card-comment" if.bind="isAuthenticated">
2626
<!-- Todo: add logged in user data -->
2727
<a href="#/profiles/view/${news.user_id}" class="pull-left">
2828
<img alt="${news.user.username}" src="http://lr.local/img/avatar/${news.user.avatar}">

0 commit comments

Comments
 (0)