-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#8 - basically implement view read news
- Loading branch information
Showing
12 changed files
with
234 additions
and
17 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 |
---|---|---|
|
@@ -123,5 +123,22 @@ | |
"content": "Rất xinh đẹp tuyệt vời ạ 🥰", | ||
"id": 14 | ||
} | ||
], | ||
"read-posts": [ | ||
{ | ||
"email": "[email protected]", | ||
"posts":[ | ||
{"title":"title1","link":"demo link"}, | ||
{"title":"title2","link":"demo link1"} | ||
], | ||
"id":1 | ||
}, | ||
{ | ||
"email": "[email protected]", | ||
"posts":[ | ||
{"title":"title2","link":"demo link2"} | ||
], | ||
"id":2 | ||
} | ||
] | ||
} |
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
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,32 @@ | ||
<app-navbar></app-navbar> | ||
<div class="container mt-5"> | ||
<div class="left-panel "> | ||
<div class="img-group"> | ||
<img src="https://mdbootstrap.com/img/new/standard/city/047.webp" class="profile-img " alt="" /> | ||
<i class="fas fa-camera fa-lg"><a href=""></a></i> | ||
</div> | ||
<div><strong>{{currentUser.name}}</strong></div> | ||
<div class="link-group"> | ||
<div><a href="/change-password">Thay đổi mật khẩu</a></div> | ||
<div><a href="/read-posts">Tin đã lưu</a></div> | ||
<div><a href="#">Tin đã đọc</a></div> | ||
<div><a (click)="openPopconfirm($event)" class="red">Xóa tài khoản</a></div> | ||
</div> | ||
</div> | ||
<div class="right-panel w-50 "> | ||
<div class="row border-bottom"> | ||
<h1 class="title">Tin đã đọc</h1> | ||
</div> | ||
<div *ngIf="isExisted"> | ||
<div class="row mt-2" *ngFor="let item of read_news"> | ||
<div class="col-md-11"> | ||
<a href="{{item.link}}" class="news-title">{{item.title}}</a> | ||
</div> | ||
<div class="col-md-1"> | ||
<i class="fas fa-trash text-danger delete__action"></i> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<app-footer></app-footer> |
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,55 @@ | ||
.container { | ||
display: flex; | ||
justify-content: center; | ||
|
||
.left-panel { | ||
display: flex; | ||
width: 20%; | ||
justify-content: flex-start; | ||
flex-direction: column; | ||
align-items: center; | ||
|
||
.img-group { | ||
display: flex; | ||
align-items: baseline; | ||
.fa-camera { | ||
position: relative; | ||
right: 30px; | ||
} | ||
.profile-img { | ||
width: 150px; | ||
height: 150px; | ||
border-radius: 50%; | ||
margin-bottom: 20px; | ||
} | ||
} | ||
|
||
.link-group { | ||
margin-top: 80px; | ||
|
||
.red { | ||
color: red; | ||
} | ||
} | ||
} | ||
|
||
.right-panel { | ||
border: 1px solid black; | ||
padding: 30px 20px 60px; | ||
.title { | ||
color: #467fd7; | ||
} | ||
} | ||
} | ||
.news-title { | ||
color: black; | ||
text-decoration: none; | ||
font-weight: bold; | ||
&:hover { | ||
text-decoration: underline; | ||
color: black; | ||
} | ||
} | ||
.delete__action { | ||
cursor: pointer; | ||
} |
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,25 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { ReadPostsComponent } from './read-posts.component'; | ||
|
||
describe('ReadPostsComponent', () => { | ||
let component: ReadPostsComponent; | ||
let fixture: ComponentFixture<ReadPostsComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [ ReadPostsComponent ] | ||
}) | ||
.compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(ReadPostsComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
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,53 @@ | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Component, OnInit } from '@angular/core'; | ||
import { Router } from '@angular/router'; | ||
import { MdbPopconfirmRef, MdbPopconfirmService } from "mdb-angular-ui-kit/popconfirm"; | ||
import { PopupConfirmComponent } from 'src/app/profile/popup-confirm/popup-confirm.component'; | ||
import { TokenStorageService } from 'src/app/_service/token-storage.service'; | ||
import { PostService } from '../post.service'; | ||
|
||
@Component({ | ||
selector: 'app-read-posts', | ||
templateUrl: './read-posts.component.html', | ||
styleUrls: ['./read-posts.component.scss'] | ||
}) | ||
|
||
|
||
export class ReadPostsComponent implements OnInit { | ||
currentUser: any; | ||
popconfirmRef: MdbPopconfirmRef<PopupConfirmComponent> | null = null; | ||
read_news!: Array<any>; | ||
data: any; | ||
isExisted = false; | ||
|
||
constructor(private postService: PostService, private router: Router, private tokenStorage: TokenStorageService, private http: HttpClient, private popconfirmService: MdbPopconfirmService) { } | ||
|
||
ngOnInit(): void { | ||
this.currentUser = this.tokenStorage.getUser(); | ||
this.get_data(); | ||
} | ||
|
||
get_data() { | ||
this.postService.get_read_news(this.currentUser.email).subscribe(res => { | ||
this.data = res; | ||
this.read_news = this.data[0]?.posts | ||
this.isExisted = this.read_news.length > 0; | ||
}); | ||
} | ||
|
||
openPopconfirm(event: Event) { | ||
const target = event.target as HTMLElement; | ||
|
||
this.popconfirmRef = this.popconfirmService.open(PopupConfirmComponent, target) | ||
this.popconfirmRef.onConfirm.subscribe(() => { | ||
this.http.delete<any>("http://localhost:3000/user/" | ||
+ this.tokenStorage.getUser()['id'] | ||
).subscribe(() => { | ||
alert("http://localhost:3000/user/" | ||
+ this.tokenStorage.getUser()['id']) | ||
this.tokenStorage.signOut(); | ||
this.router.navigate(['home']) | ||
}) | ||
}) | ||
} | ||
} |