Skip to content

Commit

Permalink
Use isLoading property instead of function
Browse files Browse the repository at this point in the history
  • Loading branch information
Ifycode committed Feb 19, 2024
1 parent cf0124a commit 8758d0d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion apps/web-mzima-client/src/app/feed/feed.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ <h3 class="menu-title">{{ 'app.mark_as' | translate }}</h3>
(buttonClick)="loadMore()"
class="feed__load-more"
*ngIf="
!postsCheck().stillLoading &&
!isLoading &&
mode === FeedMode.Post &&
params.page !== undefined &&
params.limit !== undefined &&
Expand Down
18 changes: 7 additions & 11 deletions apps/web-mzima-client/src/app/feed/feed.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export class FeedComponent extends MainViewComponent implements OnInit {

this.postsService.postsFilters$.pipe(untilDestroyed(this)).subscribe({
next: () => {
this.postIsLoading(true);
this.isLoading = true; // "There are no posts yet!" flicker is fixed here and for (most) places where isLoading is set to true
if (this.initialLoad) {
this.initialLoad = false;
return;
Expand Down Expand Up @@ -290,7 +290,7 @@ export class FeedComponent extends MainViewComponent implements OnInit {
// if (this.mode === FeedMode.Post) {
// this.currentPage = 1;
// }
this.postIsLoading(true);
this.isLoading = true;
this.postsService.getPosts('', { ...params, ...this.activeSorting }).subscribe({
next: (data) => {
this.posts = add ? [...this.posts, ...data.results] : data.results;
Expand All @@ -303,7 +303,7 @@ export class FeedComponent extends MainViewComponent implements OnInit {
payload: true,
});
setTimeout(() => {
this.postIsLoading(false);
this.isLoading = false;
this.updateMasonry();
setTimeout(() => {
if (this.mode === FeedMode.Post && !isPostsAlreadyExist) {
Expand All @@ -315,13 +315,9 @@ export class FeedComponent extends MainViewComponent implements OnInit {
});
}

public postIsLoading(value: boolean) {
return (this.isLoading = value); // "There are no posts yet!" flicker is fixed for (most) places where the value here is set to true
}

public postsCheck() {
const postsHaveLoaded = this.posts.length > 0;
if (postsHaveLoaded) this.postIsLoading(false); // post card/content area and LoadMore button benefits from this
if (postsHaveLoaded) this.isLoading = false; // post card/content area and LoadMore button benefits from this
const posts = {
atLeastOneExists: postsHaveLoaded,
stillLoading: this.isLoading, // tracks this.isLoading for post card area content display
Expand Down Expand Up @@ -498,7 +494,7 @@ export class FeedComponent extends MainViewComponent implements OnInit {
}

public isPostChecked(post: PostResult): boolean {
this.postIsLoading(true);
this.isLoading = true;
return !!this.selectedPosts.find((p: PostResult) => p.id === post.id);
}

Expand All @@ -509,7 +505,7 @@ export class FeedComponent extends MainViewComponent implements OnInit {
}

public refreshMasonry(): void {
this.postIsLoading(true);
this.isLoading = true;
this.updateMasonryLayout = !this.updateMasonryLayout;
}

Expand All @@ -528,7 +524,7 @@ export class FeedComponent extends MainViewComponent implements OnInit {
}

public switchMode(mode: FeedMode): void {
this.postIsLoading(true);
this.isLoading = true;
this.mode = mode;
if (this.collectionId) {
this.switchCollectionMode();
Expand Down

0 comments on commit 8758d0d

Please sign in to comment.