Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fav fix #1622

Merged
merged 3 commits into from
Sep 2, 2022
Merged

Fav fix #1622

Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/app/header/progress-bar/progress-bar.component.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<div
*ngIf="isLoadingResultPage || isLoadingMetaData || isLoadingCabinet || isLoadingAdminData || isLoadingMainPage"
*ngIf="
isLoadingResultPage ||
isLoadingMetaData ||
isLoadingCabinet ||
isLoadingAdminData ||
isLoadingMainPage ||
isLoadingProvider ||
isAutorizationLoading
"
class="progress-bar">
<mat-progress-bar mode="indeterminate"> </mat-progress-bar>
</div>
38 changes: 30 additions & 8 deletions src/app/header/progress-bar/progress-bar.component.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { RegistrationState } from 'src/app/shared/store/registration.state';
import { ProviderState } from './../../shared/store/provider.state';
import { MainPageState } from 'src/app/shared/store/main-page.state';
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Select } from '@ngxs/store';
Expand All @@ -24,13 +26,19 @@ export class ProgressBarComponent implements OnInit, OnDestroy {
isLoadingAdminData$: Observable<boolean>;
@Select(MainPageState.isLoadingData)
isLoadingMainPage$: Observable<boolean>;
@Select(ProviderState.isLoading)
isLoadingProvider$: Observable<boolean>;
@Select(RegistrationState.isAutorizationLoading)
isAutorizationLoading$: Observable<boolean>;

isLoadingResultPage: boolean;
isLoadingCabinet: boolean;
isLoadingMetaData: boolean;
isLoadingAdminData: boolean;
isLoadingNotifications: boolean;
isLoadingMainPage: boolean;
isAutorizationLoading: boolean;
isLoadingProvider: boolean;

private destroy$: Subject<boolean> = new Subject<boolean>();

Expand All @@ -42,16 +50,30 @@ export class ProgressBarComponent implements OnInit, OnDestroy {
this.isLoadingMetaData$,
this.isLoadingCabinet$,
this.isLoadingAdminData$,
this.isLoadingMainPage$
this.isLoadingMainPage$,
this.isAutorizationLoading$,
this.isLoadingProvider$,
])
.pipe(takeUntil(this.destroy$), delay(0))
.subscribe(([isLoadingResult, isLoadingMeta, isLoadingCabinet, isLoadingAdminData, isLoadingMainPage]) => {
this.isLoadingResultPage = isLoadingResult;
this.isLoadingMetaData = isLoadingMeta;
this.isLoadingCabinet = isLoadingCabinet;
this.isLoadingAdminData = isLoadingAdminData;
this.isLoadingMainPage = isLoadingMainPage;
});
.subscribe(
([
isLoadingResult,
isLoadingMeta,
isLoadingCabinet,
isLoadingAdminData,
isLoadingMainPage,
isAutorizationLoading,
isLoadingProvider,
]) => {
this.isLoadingResultPage = isLoadingResult;
this.isLoadingMetaData = isLoadingMeta;
this.isLoadingCabinet = isLoadingCabinet;
this.isLoadingAdminData = isLoadingAdminData;
this.isLoadingMainPage = isLoadingMainPage;
this.isAutorizationLoading = isAutorizationLoading;
this.isLoadingProvider = isLoadingProvider;
}
);
}

ngOnDestroy(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<ng-template #favorite>
<div
class="actions_btn action-icon favorite-icon"
(click)="role === Role.parent && onDisLike(this.favoriteWorkshopId?.id)">
(click)="role === Role.parent && onDisLike()">
<mat-icon>favorite</mat-icon>
</div>
</ng-template>
Expand Down
14 changes: 10 additions & 4 deletions src/app/shared/components/workshop-card/workshop-card.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ export class WorkshopCardComponent implements OnInit, OnDestroy {
readonly recruitmentStatusUkr = RecruitmentStatusUkr;
readonly modalConfirmationType = ModalConfirmationType;

isFavorite: boolean;
isFavorite = false;
canChangeWorkshopStatus: boolean;
workshopData: ProviderWorkshopCard | WorkshopCard;

private favoriteWorkshopId: string;

@Input() set workshop(workshop: WorkshopCard) {
this.workshopData = workshop;
this.imagesService.setWorkshopCoverImage(workshop);
Expand Down Expand Up @@ -95,9 +97,9 @@ export class WorkshopCardComponent implements OnInit, OnDestroy {
this.isFavorite = !this.isFavorite;
}

onDisLike(id: string): void {
onDisLike(): void {
this.store.dispatch([
new DeleteFavoriteWorkshop(id),
new DeleteFavoriteWorkshop(this.favoriteWorkshopId),
new ShowMessageBar({ message: `Гурток ${this.workshopData.title} видалено з Улюблених`, type: 'success' }),
]);
this.isFavorite = !this.isFavorite;
Expand Down Expand Up @@ -139,7 +141,11 @@ export class WorkshopCardComponent implements OnInit, OnDestroy {
filter((favorites: Favorite[]) => !!favorites)
)
.subscribe((favorites: Favorite[]) => {
this.isFavorite = !!favorites.find((item: Favorite) => item.workshopId === this.workshopData.workshopId);
const favorite = favorites.find((item: Favorite) => item.workshopId === this.workshopData.workshopId);
if (!!favorite) {
this.favoriteWorkshopId = favorite.id;
this.isFavorite = true;
}
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/app/shell/main/main.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FilterState } from 'src/app/shared/store/filter.state';
import { RegistrationState } from '../../shared/store/registration.state';
import { DirectionsStatistic } from 'src/app/shared/models/category.model';
import { WorkshopCard } from '../../shared/models/workshop.model';
import { filter, takeUntil } from 'rxjs/operators';
import { filter, take, takeUntil } from 'rxjs/operators';
import { UserState } from 'src/app/shared/store/user.state';
import { Favorite } from 'src/app/shared/models/favorite.model';
import { Role } from 'src/app/shared/enum/role';
Expand Down Expand Up @@ -74,8 +74,8 @@ export class MainComponent implements OnInit, OnDestroy {
if (role === Role.parent) {
this.favoriteWorkshops$
.pipe(
take(1),
filter((favorite: Favorite[]) => !!favorite?.length || favorite === null),
takeUntil(this.destroy$)
)
.subscribe((favorite: Favorite[]) => this.getMainPageData());
} else {
Expand Down