-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e71683f
commit 73fc859
Showing
10 changed files
with
94 additions
and
44 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
32 changes: 25 additions & 7 deletions
32
marketplace-ui/src/app/core/services/loading/loading.service.ts
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 |
---|---|---|
@@ -1,17 +1,35 @@ | ||
import { computed, Injectable, signal } from '@angular/core'; | ||
import { Injectable } from '@angular/core'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class LoadingService { | ||
private readonly isShow = signal(false); | ||
isLoading = computed(() => this.isShow()); | ||
private readonly loadingSubject = new BehaviorSubject<{ | ||
[key: string]: boolean; | ||
}>({}); | ||
loading$ = this.loadingSubject.asObservable; | ||
|
||
show() { | ||
this.isShow.set(true); | ||
private setLoading(componentIds: string[], isLoading: boolean): void { | ||
const currentState = this.loadingSubject.value; | ||
|
||
// Update the loading state for each component ID | ||
componentIds.forEach(id => { | ||
currentState[id] = isLoading; | ||
}); | ||
|
||
this.loadingSubject.next({ ...currentState }); | ||
} | ||
|
||
showLoading(...componentIds: string[]): void { | ||
this.setLoading(componentIds, true); | ||
} | ||
|
||
hideLoading(...componentIds: string[]) { | ||
this.setLoading(componentIds, false); | ||
} | ||
|
||
hide() { | ||
this.isShow.set(false); | ||
isLoading(compnentId: string): boolean { | ||
return this.loadingSubject.value[compnentId] || false; | ||
} | ||
} |
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
10 changes: 7 additions & 3 deletions
10
marketplace-ui/src/app/shared/components/loading-spinner/loading-spinner.component.html
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 |
---|---|---|
@@ -1,5 +1,9 @@ | ||
<div class="d-flex justify-content-center" data-title="dot-stretching"> | ||
<div class="stage"> | ||
<div class="dot-stretching"></div> | ||
@if (isLoading()) { | ||
<div [className]="containerClasses"> | ||
<div class="d-flex justify-content-center" data-title="dot-stretching"> | ||
<div class="stage"> | ||
<div class="dot-stretching"></div> | ||
</div> | ||
</div> | ||
</div> | ||
} |
12 changes: 6 additions & 6 deletions
12
marketplace-ui/src/app/shared/components/loading-spinner/loading-spinner.component.ts
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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
import { Component } from '@angular/core'; | ||
import { NgClass } from '@angular/common'; | ||
import { Component, computed, inject, Input } from '@angular/core'; | ||
import { LoadingService } from '../../../core/services/loading/loading.service'; | ||
|
||
@Component({ | ||
selector: 'app-loading-spinner', | ||
standalone: true, | ||
imports: [ | ||
NgClass | ||
], | ||
templateUrl: './loading-spinner.component.html', | ||
styleUrl: './loading-spinner.component.scss' | ||
}) | ||
export class LoadingSpinnerComponent { | ||
spinners = Array(5).fill(null); | ||
@Input() key: string = ''; | ||
@Input() containerClasses: string = ''; | ||
loadingService = inject(LoadingService); | ||
isLoading = computed(() => this.loadingService.loadingSubject.value[this.key]); | ||
} |
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,7 @@ | ||
export enum LoadingComponentId { | ||
LANDING_PAGE = 'landing-page', | ||
PRODUCT_DETAIL = 'product-detial', | ||
PRODUCT_VERSION = 'product-version', | ||
DETAIL_PAGE = 'detail-page', | ||
DETAIL_INFORMATION_TAB = 'detail-information-tab' | ||
} |