Skip to content

Commit afbca36

Browse files
committed
fix filters for vacancy & feed to dynamic
1 parent ff5d7e0 commit afbca36

5 files changed

Lines changed: 138 additions & 112 deletions

File tree

projects/social_platform/src/app/office/feed/filter/feed-filter.component.html

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ <h3>Фильтр</h3>
66
<a class="text-body-12" (click)="resetFilter()">Сбросить фильтр</a>
77
</div>
88
<ng-container *ngTemplateOutlet="filter"></ng-container>
9-
<div class="desktop__actions">
10-
<app-button class="" customTypographyClass="text-body-12" (click)="applyFilter()"
11-
>Применить</app-button
12-
>
13-
</div>
149
</div>
1510

1611
<div class="mobile">
@@ -36,9 +31,6 @@ <h3>Фильтр</h3>
3631
</div>
3732
}
3833
</div>
39-
<app-button class="" customTypographyClass="text-body-14" (click)="applyFilter()"
40-
>Применить</app-button
41-
>
4234
</div>
4335

4436
<app-button [routerLink]="'/office/profile/' + profile()?.id">Написать новость</app-button>

projects/social_platform/src/app/office/feed/filter/feed-filter.component.ts

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ import { Subscription } from "rxjs";
2323
*
2424
* Предоставляет интерфейс для фильтрации элементов ленты по типам контента.
2525
* Позволяет пользователю выбирать, какие типы элементов отображать в ленте.
26+
* Обновления URL происходят мгновенно при каждом изменении фильтра.
2627
*
2728
* ОСНОВНЫЕ ФУНКЦИИ:
2829
* - Отображение выпадающего меню с опциями фильтрации
2930
* - Управление состоянием активных фильтров
30-
* - Синхронизация фильтров с URL параметрами
31+
* - Мгновенная синхронизация фильтров с URL параметрами
3132
* - Применение и сброс фильтров
3233
*
3334
* ДОСТУПНЫЕ ФИЛЬТРЫ:
@@ -82,12 +83,15 @@ export class FeedFilterComponent implements OnInit, OnDestroy {
8283
});
8384

8485
// Читаем активные фильтры из URL
85-
this.route.queryParams.subscribe(params => {
86-
params["includes"] &&
87-
this.includedFilters.set(params["includes"].split(this.feedService.FILTER_SPLIT_SYMBOL));
86+
const routeSubscription = this.route.queryParams.subscribe(queries => {
87+
if (queries["includes"]) {
88+
this.includedFilters.set(queries["includes"].split(this.feedService.FILTER_SPLIT_SYMBOL));
89+
} else {
90+
this.includedFilters.set([]);
91+
}
8892
});
8993

90-
this.subscriptions.push(profileSubscription);
94+
this.subscriptions.push(profileSubscription, routeSubscription);
9195
}
9296

9397
ngOnDestroy(): void {
@@ -114,18 +118,21 @@ export class FeedFilterComponent implements OnInit, OnDestroy {
114118
includedFilters = signal<string[]>([]);
115119

116120
/**
117-
* ПРИМЕНЕНИЕ ФИЛЬТРОВ
121+
* ОБНОВЛЕНИЕ URL С ТЕКУЩИМИ ФИЛЬТРАМИ
118122
*
119-
* ЧТО ДЕЛАЕТ:
120-
* - Обновляет URL параметры с выбранными фильтрами
121-
* - Инициирует перезагрузку ленты с новыми фильтрами
122-
* - Сохраняет другие параметры запроса
123+
* Приватный метод для обновления URL параметров.
124+
* Вызывается автоматически при любом изменении фильтров.
123125
*/
124-
applyFilter(): void {
126+
private updateUrl(): void {
127+
const includesParam =
128+
this.includedFilters().length > 0
129+
? this.includedFilters().join(this.feedService.FILTER_SPLIT_SYMBOL)
130+
: null;
131+
125132
this.router
126133
.navigate([], {
127134
queryParams: {
128-
includes: this.includedFilters().join(this.feedService.FILTER_SPLIT_SYMBOL),
135+
includes: includesParam,
129136
},
130137
relativeTo: this.route,
131138
queryParamsHandling: "merge",
@@ -134,42 +141,47 @@ export class FeedFilterComponent implements OnInit, OnDestroy {
134141
}
135142

136143
/**
137-
* ПЕРЕКЛЮЧЕНИЕ ФИЛЬТРА
144+
* ПЕРЕКЛЮЧЕНИЕ ФИЛЬТРА С МГНОВЕННЫМ ОБНОВЛЕНИЕМ URL
138145
*
139146
* ЧТО ПРИНИМАЕТ:
140147
* @param keyword - значение фильтра для переключения
141148
*
142149
* ЧТО ДЕЛАЕТ:
143150
* - Добавляет фильтр, если он не активен
144151
* - Удаляет фильтр, если он уже активен
145-
* - Обновляет состояние активных фильтров
152+
* - Мгновенно обновляет URL параметры
146153
*/
147154
setFilter(keyword: string): void {
148155
this.includedFilters.update(included => {
149-
if (included.indexOf(keyword) !== -1) {
156+
const newIncluded = [...included];
157+
158+
if (newIncluded.indexOf(keyword) !== -1) {
150159
// Удаляем фильтр, если он уже активен
151-
const idx = included.indexOf(keyword);
152-
included.splice(idx, 1);
160+
const idx = newIncluded.indexOf(keyword);
161+
newIncluded.splice(idx, 1);
153162
} else {
154163
// Добавляем новый фильтр
155-
included.push(keyword);
164+
newIncluded.push(keyword);
156165
}
157166

158-
return included;
167+
return newIncluded;
159168
});
169+
170+
// Мгновенно обновляем URL
171+
this.updateUrl();
160172
}
161173

162174
/**
163175
* СБРОС ВСЕХ ФИЛЬТРОВ
164176
*
165177
* ЧТО ДЕЛАЕТ:
166178
* - Очищает все активные фильтры
167-
* - Применяет пустой набор фильтров
179+
* - Мгновенно обновляет URL
168180
* - Возвращает ленту к состоянию по умолчанию
169181
*/
170182
resetFilter(): void {
171183
this.includedFilters.set([]);
172-
this.applyFilter();
184+
this.updateUrl();
173185
}
174186

175187
/**

projects/social_platform/src/app/office/feed/shared/open-vacancy/open-vacancy.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ <h3 class="card__title">
4343
} }
4444
</div>
4545

46+
@if (feedItem.description) {
4647
<div class="action card__action">
47-
@if (feedItem.description) {
4848
<div class="text-body-14 about__text">
4949
<p
5050
class="about__text text-body-14"
@@ -57,8 +57,8 @@ <h3 class="card__title">
5757
</div>
5858
}
5959
</div>
60-
}
6160
</div>
61+
}
6262
<div class="action card__action">
6363
<span class="action__job"> {{ feedItem.role }} </span>
6464
<app-button

projects/social_platform/src/app/office/vacancies/shared/filter/vacancy-filter.component.html

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@ <h3>Фильтр</h3>
66
<a class="text-body-12" (click)="resetFilter()">Сбросить фильтр</a>
77
</div>
88
<ng-container *ngTemplateOutlet="filter"></ng-container>
9-
<div class="desktop__actions">
10-
<app-button class="" customTypographyClass="text-body-12" (click)="applyFilter()"
11-
>Применить</app-button
12-
>
13-
</div>
149
</div>
1510

1611
<div class="mobile">
@@ -36,9 +31,6 @@ <h3>Фильтр</h3>
3631
</div>
3732
}
3833
</div>
39-
<app-button class="" customTypographyClass="text-body-14" (click)="applyFilter()"
40-
>Применить</app-button
41-
>
4234
</div>
4335

4436
<ng-template #filter>
@@ -88,15 +80,27 @@ <h3>Фильтр</h3>
8880
</ul>
8981
</div>
9082

91-
<form [formGroup]="salaryForm">
92-
<div class="filter__salary">
93-
<span class="text-body-12">Заработная плата</span>
94-
<div class="filter__amounts">
95-
<app-input type="text" placeholder="от 50000" formControlName="salaryMin"></app-input>
96-
<hr style="transform: rotate(90deg)" class="filter__salary-line" />
97-
<app-input type="text" placeholder="до 150000" formControlName="salaryMax"></app-input>
98-
</div>
83+
<div class="filter__salary">
84+
<span class="text-body-12">Заработная плата</span>
85+
<div class="filter__amounts">
86+
<app-input
87+
type="text"
88+
placeholder="от 50000"
89+
[appValue]="salaryMinValue()"
90+
(appValueChange)="onSalaryMinChange($event)"
91+
>
92+
</app-input>
93+
94+
<hr style="transform: rotate(90deg)" class="filter__salary-line" />
95+
96+
<app-input
97+
type="text"
98+
placeholder="до 150000"
99+
[appValue]="salaryMaxValue()"
100+
(appValueChange)="onSalaryMaxChange($event)"
101+
>
102+
</app-input>
99103
</div>
100-
</form>
104+
</div>
101105
</div>
102106
</ng-template>

0 commit comments

Comments
 (0)