Skip to content

Commit 93ceb1b

Browse files
committed
✨ skeletons added to websites page
1 parent 6dee4f1 commit 93ceb1b

File tree

4 files changed

+56
-29
lines changed

4 files changed

+56
-29
lines changed

src/app/core/services/auth.service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ import { environment } from 'environments/environment';
44
import { HttpClient } from '@angular/common/http';
55

66
import { ILogin } from '@interfaces/login.interface';
7+
import { IModalAuth } from '@interfaces/modal.interface';
78
import { IResponseLogin } from '@interfaces/response.interface';
9+
810
import Storage from "@utils/storage.util";
11+
912
import { User } from '@models/user.model';
13+
1014
import { SettingService } from './setting.service';
11-
import { IModalAuth } from '@interfaces/modal.interface';
15+
1216

1317
const base_url = environment.base_url;
1418

src/app/features/website/pages/websites/websites.component.html

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
1-
<section class="websites-section" *ngIf="websites">
1+
<section class="websites-section">
22
<div class="title-wrapper">
33
<span class="title-section">Websites availables</span>
44
</div>
5-
65
<div class="websites-wrapper">
7-
<div class="card card-website" *ngFor="let website of websites">
8-
<figure>
9-
<img [src]="website.image" alt="website-image" onerror="this.src='/assets/images/not-found-image.jpg'">
10-
</figure>
11-
<div class="card-body">
12-
<div class="website-title">
13-
<span class="title">{{website.name}}</span>
14-
<button (click)="subscribeWebsite(website._id)" [class.btn-following]="website.inUser"
15-
class="btn btn-primary btn-subscribe">{{ (website.inUser) ?
16-
'Following' : 'Subscribe' }}</button>
17-
</div>
18-
<p class="w-desc">{{website.description}}</p>
19-
<div class="link">
20-
<a [href]="website.link" target="_blank" class="w-link">View original site</a>
6+
<div class="skeletons" *ngIf="isLoading">
7+
<app-card-new></app-card-new>
8+
<app-card-new></app-card-new>
9+
<app-card-new></app-card-new>
10+
</div>
11+
<div *ngIf="!isLoading">
12+
<div class="card card-website" *ngFor="let website of websites">
13+
<figure>
14+
<img [src]="website.image" alt="website-image" onerror="this.src='/assets/images/not-found-image.jpg'">
15+
</figure>
16+
<div class="card-body">
17+
<div class="website-title">
18+
<span class="title">{{website.name}}</span>
19+
<button (click)="subscribeWebsite(website._id)" [class.btn-following]="website.inUser"
20+
class="btn btn-primary btn-subscribe">{{ (website.inUser) ?
21+
'Following' : 'Subscribe' }}</button>
22+
</div>
23+
<p class="w-desc">{{website.description}}</p>
24+
<div class="link">
25+
<a [href]="website.link" target="_blank" class="w-link">View original site</a>
26+
</div>
2127
</div>
2228
</div>
2329
</div>

src/app/features/website/pages/websites/websites.component.ts

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, OnDestroy, OnInit } from '@angular/core';
2+
import { debounceTime, Subject, Subscription } from 'rxjs';
23

34
import { WebsiteService } from '@services/website.service';
45

56
import { Website } from '@models/website.model';
7+
68
import { AuthService } from '@services/auth.service';
79
import { UserService } from '@services/user.service';
810

@@ -11,36 +13,49 @@ import { UserService } from '@services/user.service';
1113
templateUrl: './websites.component.html',
1214
styleUrls: ['./websites.component.css']
1315
})
14-
export class WebsitesComponent implements OnInit {
16+
export class WebsitesComponent implements OnInit, OnDestroy {
1517

1618
public websites: Website[];
17-
private isAuthenticated: boolean;
19+
private websiteSub: Subscription;
20+
private loadingWebsites: Subject<boolean> = new Subject();
21+
public isLoading: boolean = false;
1822

1923
constructor(
2024
private websiteService: WebsiteService,
2125
private authService: AuthService,
2226
private userService: UserService
23-
) { }
27+
) {
28+
this.isLoading = true;
29+
this.loadingWebsites.pipe(debounceTime(1000)).subscribe(() => this.getWebsites());
30+
}
31+
32+
ngOnDestroy(): void {
33+
this.websiteSub.unsubscribe();
34+
}
2435

2536
ngOnInit(): void {
26-
this.isAuthenticated = this.authService.isAuthenticated();
27-
this.getWebsites();
37+
this.loadingWebsites.next(true);
38+
this.websiteSub = this.authService.isAuthenticatedEmitter.subscribe(({isAuth}) =>{
39+
if(isAuth) {
40+
this.isLoading = true;
41+
this.loadingWebsites.next(true);
42+
}
43+
});
2844
}
2945

3046
getWebsites(): void {
3147
this.websiteService.getWebsites(true).subscribe({
3248
next: (websites) => {
3349
this.websites = websites;
34-
console.log(this.websites);
3550
},
36-
error: (e) => {
37-
console.log(e);
51+
complete: () => {
52+
this.isLoading = false;
3853
}
3954
})
4055
}
4156

4257
subscribeWebsite(id: string){
43-
if(!this.isAuthenticated) {
58+
if(!this.authService.isAuthenticated()) {
4459
return this.authService.showModalAuth('init');
4560
}
4661
this.userService.modifyPreferences(id, 'subscription').subscribe(resp => {
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import { NgModule } from '@angular/core';
22
import { CommonModule } from '@angular/common';
3-
import { WebsitesComponent } from './pages/websites/websites.component';
43

4+
import { WebsitesComponent } from './pages/websites/websites.component';
55

6+
import { SkeletonsModule } from 'app/shared/skeletons/skeletons.module';
67

78
@NgModule({
89
declarations: [
910
WebsitesComponent
1011
],
1112
imports: [
12-
CommonModule
13+
CommonModule,
14+
SkeletonsModule
1315
]
1416
})
1517
export class WebsiteModule { }

0 commit comments

Comments
 (0)