Skip to content

Commit

Permalink
fix: range price slider
Browse files Browse the repository at this point in the history
  • Loading branch information
Kleostro committed May 31, 2024
1 parent 6001804 commit a83659d
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 40 deletions.
3 changes: 0 additions & 3 deletions src/entities/ProductCard/view/productCardView.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@
width: var(--small-offset);
height: var(--small-offset);
background-color: var(--noble-gray-1000);
transition:
transform 0.2s,
outline 0.2s;
backdrop-filter: blur(10px);

svg {
Expand Down
2 changes: 1 addition & 1 deletion src/entities/UserAddress/model/UserAddressModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class UserAddressModel {
}
}

// eslint-disable-next-line max-lines-per-function
private async handleAddressType(user: User, activeType: AddressTypeType, inactive: boolean): Promise<void> {
const customerModel = getCustomerModel();

Expand Down Expand Up @@ -87,7 +88,6 @@ class UserAddressModel {
case ADDRESS_TYPE.DEFAULT_SHIPPING:
await customerModel.editCustomer([CustomerModel.actionRemoveShippingAddress(this.currentAddress)], user);
break;

default:
break;
}
Expand Down
34 changes: 16 additions & 18 deletions src/features/ProductFilters/view/ProductFiltersView.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PriceRange, SizeProductCount } from '@/shared/API/types/type';
import type { SizeProductCount } from '@/shared/API/types/type';
import type { Category } from '@/shared/types/product';
import type ProductFiltersParams from '@/shared/types/productFilters';

Expand Down Expand Up @@ -263,6 +263,7 @@ class ProductFiltersView {

link.getHTML().addEventListener('click', (event) => {
event.preventDefault();

RouterModel.setSearchParams(SEARCH_PARAMS_FIELD.META, id);
RouterModel.deleteSearchParams(SEARCH_PARAMS_FIELD.PAGE);
this.metaLinks.forEach((link) => this.switchSelectedFilter(link, false));
Expand Down Expand Up @@ -556,6 +557,19 @@ class ProductFiltersView {
this.callback();
}

private updatePriceRange(): void {
this.priceSlider.updateOptions(
{
start: [this.params?.priceRange?.min ?? 0, this.params?.priceRange?.max ?? 0],
},
true,
);
const fromInput = this.priceInputs.get(PRICE_RANGE_LABEL[getStore().getState().currentLanguage].FROM);
const toInput = this.priceInputs.get(PRICE_RANGE_LABEL[getStore().getState().currentLanguage].TO);
fromInput?.setValue((this.params?.priceRange?.min ?? 0).toFixed(2));
toInput?.setValue((this.params?.priceRange?.max ?? 0).toFixed(2));
}

private updateSelectedPrice(from: InputModel | null = null, to: InputModel | null = null): void {
RouterModel.setSearchParams(SEARCH_PARAMS_FIELD.MIN_PRICE, from?.getValue() ?? '0');
RouterModel.setSearchParams(SEARCH_PARAMS_FIELD.MAX_PRICE, to?.getValue() ?? '0');
Expand Down Expand Up @@ -638,25 +652,9 @@ class ProductFiltersView {
const currentSpan = span;
currentSpan.innerText = BASE_PRODUCT_COUNT;
});
this.updatePriceRange();
this.redrawProductsCount();
}

public updatePriceRange(params: PriceRange): void {
if (this.params) {
this.params.priceRange = params;
}
this.priceSlider.updateOptions(
{
range: { max: params.max ?? 0, min: params.min ?? 0 },
start: [params.min ?? 0, params.max ?? 0],
},
true,
);
const fromInput = this.priceInputs.get(PRICE_RANGE_LABEL[getStore().getState().currentLanguage].FROM);
const toInput = this.priceInputs.get(PRICE_RANGE_LABEL[getStore().getState().currentLanguage].TO);
fromInput?.setValue(params.min.toFixed(2) ?? '');
toInput?.setValue(params.max.toFixed(2) ?? '');
}
}

export default ProductFiltersView;
4 changes: 2 additions & 2 deletions src/pages/ProductPage/model/ProductPageModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ class ProductPageModel implements Page {
});
}

if (subcategory) {
if (subcategory && category) {
links.push({
link: '',
link: buildPathName(PAGE_ID.CATALOG_PAGE, null, { category: [category.id], subcategory: [subcategory.id] }),
name: subcategory.name[0].value,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
width: 25%;
height: fit-content;
background-color: var(--white);
gap: var(--extra-small-offset);
}

.accountMenuItem {
Expand All @@ -69,7 +68,7 @@
align-items: center;
align-self: center;
width: 100%;
height: 2.5rem;
height: 4rem;
font: var(--regular-font);
letter-spacing: var(--one);
text-align: center;
Expand All @@ -81,7 +80,7 @@
content: '';
position: absolute;
left: 0;
bottom: -5px;
bottom: 1rem;
width: 100%;
height: var(--two);
background-color: currentcolor;
Expand All @@ -90,7 +89,8 @@
transform-origin: center;
transition:
transform 0.2s,
opacity 0.2s;
opacity 0.2s,
background-color 0.2s;
}

@media (hover: hover) {
Expand Down
17 changes: 7 additions & 10 deletions src/widgets/Catalog/model/CatalogModel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { OptionsRequest, PriceRange, SortOptions } from '@/shared/API/types/type.ts';
import type { OptionsRequest, SortOptions } from '@/shared/API/types/type.ts';
import type ProductFiltersParams from '@/shared/types/productFilters.ts';
import type { SelectedFilters } from '@/shared/types/productFilters.ts';
import type { SelectedSorting } from '@/shared/types/productSorting.ts';
Expand Down Expand Up @@ -54,7 +54,7 @@ class CatalogModel {
}
}

private decodeSearchParams(priceRange: PriceRange): {
private decodeSearchParams(): {
page: string;
searchValue: null | string;
selectedFilters: SelectedFilters;
Expand All @@ -67,8 +67,8 @@ class CatalogModel {
const metaFilter = searchParams.get(SEARCH_PARAMS_FIELD.META) ?? META_FILTERS.en.ALL_PRODUCTS;
const size = searchParams.get(SEARCH_PARAMS_FIELD.SIZE) ?? null;
const price = {
max: parseFloat(searchParams.get(SEARCH_PARAMS_FIELD.MAX_PRICE) ?? priceRange.max.toString()),
min: parseFloat(searchParams.get(SEARCH_PARAMS_FIELD.MIN_PRICE) ?? priceRange.min.toString()),
max: parseFloat(searchParams.get(SEARCH_PARAMS_FIELD.MAX_PRICE) ?? '0'),
min: parseFloat(searchParams.get(SEARCH_PARAMS_FIELD.MIN_PRICE) ?? '0'),
};

const field = searchParams.get(SEARCH_PARAMS_FIELD.FIELD);
Expand All @@ -93,7 +93,7 @@ class CatalogModel {
private async drawProducts(): Promise<void> {
const productList = this.view.getItemsList();
productList.innerHTML = '';
const options = await this.getOptions();
const options = this.getOptions();
const productsInfo = await this.getProductsInfo(options);
this.pagination?.getHTML().remove();
if (productsInfo?.products?.length) {
Expand All @@ -112,16 +112,13 @@ class CatalogModel {
this.view.getRightTopWrapper().append(this.pagination.getHTML());
}
this.productFilters?.getView().updateParams(productsInfo);
const priceRange = await getProductModel().getPriceRange();
this.productFilters?.getView().updatePriceRange(priceRange);
this.view.switchEmptyList(!productsInfo?.products?.length);
}

private async getOptions(): Promise<OptionsRequest> {
private getOptions(): OptionsRequest {
let result = {};
const priceRange = await getProductModel().getPriceRange();

const { page, searchValue, selectedFilters, selectedSorting } = this.decodeSearchParams(priceRange);
const { page, searchValue, selectedFilters, selectedSorting } = this.decodeSearchParams();
this.productFilters?.getView().setInitialActiveFilters({
categoryLinks: Array.from(selectedFilters.category),
metaLinks: selectedFilters.metaFilter ? [selectedFilters.metaFilter] : [],
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/ProductInfo/view/ProductInfoView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class ProductInfoView {

private createProductTitle(): HTMLHeadingElement {
this.title = createBaseElement({
cssClasses: ['title'],
cssClasses: ['productTitle'],
innerContent: this.params.name[Number(getStore().getState().currentLanguage === LANGUAGE_CHOICE.RU)].value,
tag: 'h3',
});
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/ProductInfo/view/productInfoView.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
}
}

.title {
.productTitle {
order: 1;
font: var(--medium-font);
letter-spacing: var(--one);
Expand Down

1 comment on commit a83659d

@Kleostro
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.