Skip to content

Commit

Permalink
Merge pull request #78 from fs-jun24-team-3/hotfix/hot-prices-sorting
Browse files Browse the repository at this point in the history
hotfix/hot-prices-sorting
  • Loading branch information
k-marchuk authored Sep 25, 2024
2 parents 979033f + 5927d9d commit ca1d1f6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/components/Main/Main.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import React, { useEffect, useMemo } from 'react';
import './Main.scss';
import { MainBannerSlider } from './MainBannerSlider';
// import { GoodsSlider } from './GoodsSlider';
import { CategoriesList } from './CategoriesList';
import { GoodsSlider } from './GoodsSlider';
import { loadPhones } from '../../app/slices/phonesSlice';
import { useAppDispatch, useAppSelector } from '../../app/reduxHooks';
import { Phone } from '../../utils/types/Phone';
import { sortByHighDiscounts } from '../../utils/helpers/sortByHighDiscounts';
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
type Props = {};

function sortByHighDiscounts(phones: Phone[]) {
return [...phones].sort((p1, p2) => p2.priceDiscount - p1.priceDiscount);
}

export const Main: React.FC<Props> = () => {
const dispatch = useAppDispatch();
const { phones } = useAppSelector(state => state.phones);
Expand All @@ -33,7 +28,7 @@ export const Main: React.FC<Props> = () => {
<GoodsSlider sliderTitle={'Brand new models'} productsList={phones} />
<CategoriesList />
<GoodsSlider
sliderTitle={'HotPrices'}
sliderTitle={'Hot prices'}
productsList={phonesWithHighestDiscounts}
/>
</div>
Expand Down
9 changes: 9 additions & 0 deletions src/utils/helpers/sortByHighDiscounts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Phone } from '../types/Phone';

export function sortByHighDiscounts(phones: Phone[]) {
return [...phones].sort((p1, p2) => {
return (
p1.priceDiscount - p1.priceRegular - (p2.priceDiscount - p2.priceRegular)
);
});
}

0 comments on commit ca1d1f6

Please sign in to comment.