-
Notifications
You must be signed in to change notification settings - Fork 44
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
Showing
23 changed files
with
1,179 additions
and
266 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { memo } from 'react'; | ||
import { useRouter } from 'next/router'; | ||
import { t } from 'ttag'; | ||
import BaseFilter from './BaseFilter'; | ||
import { goToUrlQueryAndResetPagination } from 'lib/listPage'; | ||
|
||
/** | ||
* URL param name to read from and write to | ||
*/ | ||
const PARAM_NAME = 'articleTypes'; | ||
|
||
const OPTIONS = [ | ||
{ value: 'TEXT', label: t`Text` }, | ||
{ value: 'IMAGE', label: t`Image` }, | ||
{ value: 'VIDEO', label: t`Video` }, | ||
{ value: 'AUDIO', label: t`Audio` }, | ||
]; | ||
|
||
/** | ||
* @param {object} query - query from router | ||
* @returns {Arary<keyof TYPE_NAME>} list of selected reply types; see constants/replyType for all possible values | ||
*/ | ||
function getValues(query) { | ||
return query[PARAM_NAME] ? query[PARAM_NAME].split(',') : []; | ||
} | ||
|
||
function ArticleTypeFilter() { | ||
const { query } = useRouter(); | ||
const selectedValues = getValues(query); | ||
|
||
return ( | ||
<BaseFilter | ||
title={t`Format`} | ||
selected={selectedValues} | ||
options={OPTIONS} | ||
onChange={selected => | ||
goToUrlQueryAndResetPagination({ | ||
...query, | ||
[PARAM_NAME]: selected.join(','), | ||
}) | ||
} | ||
/> | ||
); | ||
} | ||
|
||
const MemoizedArticleTypeFilter = memo(ArticleTypeFilter); | ||
MemoizedArticleTypeFilter.getValues = getValues; | ||
export default MemoizedArticleTypeFilter; |
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
Oops, something went wrong.