Skip to content

Commit 3a0d38a

Browse files
committed
✨ loading skeletons added
1 parent 822eb41 commit 3a0d38a

23 files changed

+286
-86
lines changed

src/app/core/components/sidebar/sidebar.component.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ nav .profile {
246246
bottom: 0;
247247
transition: none;
248248
background: var(--bg-color);
249+
border-right: none;
250+
border-top: 1px solid #a5a5a5;
249251
}
250252

251253
nav .profile,

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,7 @@ export class FeedService {
3535
};
3636
}
3737

38-
get getRecentsFeeds(): Feed[] {
39-
return this.recentFeeds;
40-
}
41-
42-
setRecentsFeeds(feeds: Feed[]): void {
43-
this.recentFeeds = feeds;
44-
}
45-
4638
getFeeds(skip = 0, limit = 10, isAuthenticated: boolean = false): Observable<Feed[]> {
47-
4839
const url = (!isAuthenticated) ?
4940
`${base_url}/feed?skip=${skip}&limit=${limit}` :
5041
`${base_url}/feed/byUser/subscription?skip=${skip}&limit=${limit}`;

src/app/features/feed/feed.module.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
import { NgModule } from '@angular/core';
22
import { CommonModule } from '@angular/common';
3-
import { FeedComponent } from './pages/feed/feed.component';
3+
44
import { HtmlPipe } from 'app/core/pipes/html.pipe';
5-
import { SavedComponent } from './pages/saved/saved.component';
65

6+
import { SkeletonsModule } from 'app/shared/skeletons/skeletons.module';
77
import { SharedModule } from 'app/shared/shared.module';
88

9+
import { SavedComponent } from './pages/saved/saved.component';
10+
import { FeedComponent } from './pages/feed/feed.component';
11+
12+
913
@NgModule({
1014
declarations: [
1115
FeedComponent,
1216
SavedComponent,
13-
HtmlPipe,
17+
HtmlPipe
1418
],
1519
imports: [
1620
CommonModule,
17-
SharedModule
21+
SharedModule,
22+
SkeletonsModule
1823
]
1924
})
2025
export class FeedModule { }

src/app/features/feed/pages/feed/feed.component.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
display: grid;
33
grid-template-columns: auto 300px;
44
gap: 0.5rem;
5-
padding-top: 1rem;
65
}
76

87
.feed-wrapper .findings {
98
width: 300px;
109
opacity: 1;
1110
}
1211

12+
.card.news-detail {
13+
margin: 1rem;
14+
}
15+
1316
.card.card-findings {
1417
cursor: default;
1518
opacity: 1;

src/app/features/feed/pages/feed/feed.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<div class="findings">
2121
<div class="card card-findings">
2222
<span class="card-title">Recents</span>
23-
<div class="item" *ngFor="let recentFeed of recentsFeed">
23+
<div (click)="goToFeed(recentFeed._id)" class="item" *ngFor="let recentFeed of recentsFeed">
2424
<div class="item-content">
2525
<span class="title">{{recentFeed.title | slice:0:35}}{{(recentFeed.title.length > 20)?'...':'' }}</span>
2626
<span class="writer">{{recentFeed.writer}}</span>
Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
2-
import { ActivatedRoute } from '@angular/router';
2+
import { ActivatedRoute, Router } from '@angular/router';
33

44
import { FeedService } from '@services/feed.service';
55

66
import { Feed } from '@models/feed.model';
7+
import { forkJoin } from 'rxjs';
78
// use encapsulation to styles works correctly from css files
89
@Component({
910
selector: 'app-feed',
@@ -14,21 +15,34 @@ import { Feed } from '@models/feed.model';
1415
export class FeedComponent implements OnInit {
1516
public feed: Feed;
1617
public recentsFeed: Feed[];
18+
public isLoading: boolean = true;
1719

1820
constructor(
1921
private activatedRoute: ActivatedRoute,
2022
private feedService: FeedService,
23+
private router: Router
2124
) { }
2225

2326
ngOnInit(): void {
24-
this.recentsFeed = this.feedService.getRecentsFeeds;
25-
this.activatedRoute.params.subscribe(({ feedID }) => this.getFeed(feedID));
27+
this.activatedRoute.params.subscribe(({ feedID }) => this.loadData(feedID));
2628
}
2729

28-
getFeed(id: string): void {
29-
this.feedService.getFeed(id).subscribe((feed: Feed) => {
30-
this.feed = feed;
30+
loadData(id: string): void {
31+
this.isLoading = true;
32+
forkJoin({
33+
feed: this.feedService.getFeed(id),
34+
recentFeeds: this.feedService.getFeeds(0, 6, false),
35+
}).subscribe({
36+
next: ({ feed, recentFeeds }) => {
37+
this.feed = feed,
38+
this.recentsFeed = recentFeeds;
39+
},
40+
complete: () => this.isLoading = false,
3141
})
3242
}
3343

44+
goToFeed(id: string): void {
45+
this.router.navigate([`/feed/${id}`]);
46+
}
47+
3448
}

src/app/features/feed/pages/saved/saved.component.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
<span class="title-section">Saved</span>
44
</div>
55
<div class="news-container">
6-
<app-news-container [feeds]="feeds" *ngIf="feeds" (moreItems)="onScroll()"></app-news-container>
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+
<app-news-container [feeds]="feeds" *ngIf="!isLoading" (moreItems)="onScroll()"></app-news-container>
712
</div>
813
</section>

src/app/features/feed/pages/saved/saved.component.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Component, OnInit } from '@angular/core';
22
import { Feed } from '@models/feed.model';
33
import { FeedService } from '@services/feed.service';
4-
import { map, Observable } from 'rxjs';
4+
import { debounceTime, map, Observable, Subject } from 'rxjs';
55

66
@Component({
77
selector: 'app-saved',
@@ -12,14 +12,24 @@ export class SavedComponent implements OnInit {
1212
private skip: number = 0;
1313
private limit: number = 10;
1414
public feeds: Feed[];
15+
public isLoading: boolean = true;
16+
private loadingNews: Subject<boolean> = new Subject();
17+
1518
constructor(
1619
private feedService: FeedService,
17-
) { }
20+
) {
21+
this.loadingNews.pipe(debounceTime(2000)).subscribe(() => this.getFeedsSaved());
22+
}
1823

1924
ngOnInit(): void {
20-
this.getSavedFeeds().subscribe(feeds => {
21-
console.log(feeds);
22-
this.feeds = feeds
25+
this.loadingNews.next(true);
26+
}
27+
28+
getFeedsSaved() {
29+
this.isLoading = true;
30+
this.getSavedFeeds().subscribe({
31+
next: (feeds) => this.feeds = feeds,
32+
complete: () => this.isLoading = false,
2333
});
2434
}
2535

src/app/features/home/components/websites-card/websites-card.component.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
max-width: 300px;
88
display: flex;
99
flex-direction: column;
10-
transform: translate(0, 65px);
10+
transform: translate(0, 78px);
1111
}
1212

1313
.card.card-websites .card-title {

src/app/features/home/home.component.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
opacity: 1;
1010
}
1111

12+
.skeletons {
13+
margin-top: 0.5rem;
14+
}
15+
1216
@media (max-width: 1200px) {
1317
.home-section .recently .news {
1418
grid-template-columns: repeat(1, 100%);

0 commit comments

Comments
 (0)