forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
649863d
commit 6924591
Showing
8 changed files
with
279 additions
and
10 deletions.
There are no files selected for viewing
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
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,82 @@ | ||
import React, { useMemo } from 'react'; | ||
import { useIntl } from '@edx/frontend-platform/i18n'; | ||
import { Icon, Dropdown } from '@openedx/paragon'; | ||
import { Check, SwapVert } from '@openedx/paragon/icons'; | ||
|
||
import messages from './messages'; | ||
import { SearchSortOption } from './data/api'; | ||
import { useSearchContext } from './SearchManager'; | ||
|
||
export const SearchSortWidget: React.FC<Record<never, never>> = () => { | ||
const intl = useIntl(); | ||
const menuItems = useMemo( | ||
() => [ | ||
{ | ||
id: 'search-sort-option-title-az', | ||
name: intl.formatMessage(messages.searchSortTitleAZ), | ||
value: SearchSortOption.TITLE_AZ, | ||
}, | ||
{ | ||
id: 'search-sort-option-title-za', | ||
name: intl.formatMessage(messages.searchSortTitleZA), | ||
value: SearchSortOption.TITLE_ZA, | ||
}, | ||
{ | ||
id: 'search-sort-option-newest', | ||
name: intl.formatMessage(messages.searchSortNewest), | ||
value: SearchSortOption.NEWEST, | ||
}, | ||
{ | ||
id: 'search-sort-option-oldest', | ||
name: intl.formatMessage(messages.searchSortOldest), | ||
value: SearchSortOption.OLDEST, | ||
}, | ||
{ | ||
id: 'search-sort-option-recently-published', | ||
name: intl.formatMessage(messages.searchSortRecentlyPublished), | ||
value: SearchSortOption.RECENTLY_PUBLISHED, | ||
}, | ||
{ | ||
id: 'search-sort-option-recently-modified', | ||
name: intl.formatMessage(messages.searchSortRecentlyModified), | ||
value: SearchSortOption.RECENTLY_MODIFIED, | ||
}, | ||
], | ||
[intl], | ||
); | ||
|
||
const { searchSortOrder, setSearchSortOrder } = useSearchContext(); | ||
const selectedSortOption = menuItems.find((menuItem) => menuItem.value === searchSortOrder); | ||
const searchSortLabel = ( | ||
selectedSortOption ? selectedSortOption.name : intl.formatMessage(messages.searchSortWidgetLabel) | ||
); | ||
|
||
return ( | ||
<Dropdown id="search-sort-dropdown"> | ||
<Dropdown.Toggle | ||
id="search-sort-toggle" | ||
title={intl.formatMessage(messages.searchSortWidgetAltTitle)} | ||
alt={intl.formatMessage(messages.searchSortWidgetAltTitle)} | ||
variant="outline-primary" | ||
className="dropdown-toggle-menu-items d-flex" | ||
size="sm" | ||
> | ||
<Icon src={SwapVert} className="d-inline" /> | ||
{searchSortLabel} | ||
</Dropdown.Toggle> | ||
<Dropdown.Menu> | ||
{menuItems.map(({ id, name, value }) => ( | ||
<Dropdown.Item | ||
key={id} | ||
onClick={() => setSearchSortOrder(value)} | ||
> | ||
{name} | ||
{(value === searchSortOrder) && <Icon src={Check} className="ml-2" />} | ||
</Dropdown.Item> | ||
))} | ||
</Dropdown.Menu> | ||
</Dropdown> | ||
); | ||
}; | ||
|
||
export default SearchSortWidget; |
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
Oops, something went wrong.