-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from mgmman/module6-task2
- Loading branch information
Showing
10 changed files
with
140 additions
and
65 deletions.
There are no files selected for viewing
6 changes: 3 additions & 3 deletions
6
src/Pages/favorites-page.tsx → src/Pages/favorites-page/favorites-page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 13 additions & 13 deletions
26
src/Pages/offer-page.tsx → src/Pages/offer-page/offer-page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React, { useState } from 'react'; | ||
import { Offer } from '../../dataTypes/offer.ts'; | ||
import { SortOffers } from '../../dataTypes/sort-offers.ts'; | ||
import { useAppDispatch } from '../../store/store.ts'; | ||
import { setSorting } from '../../store/actions.ts'; | ||
|
||
const sortingOptions: [string, SortOffers][] = [ | ||
['Popular', (offers: Offer[]) => offers], | ||
[ | ||
'Price: low to high', | ||
(offers: Offer[]) => offers.toSorted((a, b) => a.price - b.price), | ||
], | ||
[ | ||
'Price: high to low', | ||
(offers: Offer[]) => offers.toSorted((a, b) => b.price - a.price), | ||
], | ||
[ | ||
'Top rated first', | ||
(offers: Offer[]) => offers.toSorted((a, b) => b.rating - a.rating), | ||
], | ||
]; | ||
|
||
export function OfferSortSelect(): React.JSX.Element { | ||
const [isOpen, setIsOpen] = useState(false); | ||
const [sortingOption, setSortingOption] = useState('Popular'); | ||
const dispatch = useAppDispatch(); | ||
const handleSortChange = (sort: SortOffers, sortingOptionName: string) => { | ||
setSortingOption(sortingOptionName); | ||
dispatch(setSorting(sort)); | ||
setIsOpen(false); | ||
}; | ||
return ( | ||
<form className="places__sorting" action="#" method="get"> | ||
<span className="places__sorting-caption">Sort by</span> | ||
<span | ||
className="places__sorting-type" | ||
tabIndex={0} | ||
onClick={() => setIsOpen(!isOpen)} | ||
> | ||
{sortingOption} | ||
<svg className="places__sorting-arrow" width="7" height="4"> | ||
<use xlinkHref="#icon-arrow-select"></use> | ||
</svg> | ||
</span> | ||
{isOpen && ( | ||
<ul className="places__options places__options--custom places__options--opened"> | ||
{sortingOptions.map(([name, sort]) => ( | ||
<li | ||
className={`places__option ${name === sortingOption ? 'places__option--active' : ''}`} | ||
tabIndex={0} | ||
key={name} | ||
onClick={() => handleSortChange(sort, name)} | ||
> | ||
{name} | ||
</li> | ||
))} | ||
</ul> | ||
)} | ||
</form> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { Offer } from './offer.ts'; | ||
|
||
export type SortOffers = (offers: Offer[]) => Offer[]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
import { createAction } from '@reduxjs/toolkit'; | ||
import { City } from '../dataTypes/city.ts'; | ||
import { Offer } from '../dataTypes/offer.ts'; | ||
import { SortOffers } from '../dataTypes/sort-offers.ts'; | ||
|
||
export const changeCity = createAction<City>('mainPage/changeCity'); | ||
export const changeCity = createAction<City>('offers/changeCity'); | ||
|
||
export const fillOffers = createAction<Offer[]>('mainPage/fillOffers'); | ||
export const setOffers = createAction<Offer[]>('offers/setOffers'); | ||
|
||
export const setSorting = createAction<SortOffers>('offers/setSorting'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters