Skip to content

Commit

Permalink
Merge pull request #68 from fs-jun24-team-3/hotfix/change-hot-prices-…
Browse files Browse the repository at this point in the history
…title

hotfix/now Hot Prices firstly shows products with the highest discounts
  • Loading branch information
NIKaragu authored Sep 24, 2024
2 parents 6f38544 + 9fefab5 commit 29d7da7
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/components/Main/Main.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
import React, { useEffect } from 'react';
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';
// 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);
const phonesWithHighestDiscounts = useMemo(() => {
return sortByHighDiscounts(phones);
}, [phones]);

useEffect(() => {
dispatch(loadPhones());
Expand All @@ -24,7 +32,10 @@ export const Main: React.FC<Props> = () => {
<MainBannerSlider />
<GoodsSlider sliderTitle={'Brand new models'} productsList={phones} />
<CategoriesList />
<GoodsSlider sliderTitle={'Brand new models'} productsList={phones} />
<GoodsSlider
sliderTitle={'HotPrices'}
productsList={phonesWithHighestDiscounts}
/>
</div>
</>
);
Expand Down

0 comments on commit 29d7da7

Please sign in to comment.