From 1ad66fccd0fafe4c256444be02560d4006d7cf8b Mon Sep 17 00:00:00 2001 From: infinite-persistence Date: Mon, 25 Apr 2022 13:44:22 +0800 Subject: [PATCH] Category: Hide "Repost" from ContentType filter, except for WildWest ## Ticket 1368 > can we remove the repost filter option on categories outside of wildwest/following? ## Approach Using `context` to: - reduce the amount of files that need to change. - avoid prop-drilling. - allow the ability to dynamically define the Filter's allowed values in a contained manner. Clients that don't need customization simply does not need to wrap their component with the context. The context only contains Content Type for now, but can include anything that future clients need to dynamically adjust. --- .flowconfig | 1 + ui/component/claimListHeader/view.jsx | 4 +- ui/contexts/claimSearchFilterContext.jsx | 9 +++ ui/page/discover/view.jsx | 73 +++++++++++++----------- 4 files changed, 54 insertions(+), 33 deletions(-) create mode 100644 ui/contexts/claimSearchFilterContext.jsx diff --git a/.flowconfig b/.flowconfig index b6992488b..246a00038 100644 --- a/.flowconfig +++ b/.flowconfig @@ -16,6 +16,7 @@ suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe suppress_comment=\\(.\\|\n\\)*\\$FlowIssue module.name_mapper='^constants\(.*\)$' -> '/ui/constants\1' +module.name_mapper='^contexts\(.*\)$' -> '/ui/contexts\1' module.name_mapper='^util\(.*\)$' -> '/ui/util\1' module.name_mapper='^redux\(.*\)$' -> '/ui/redux\1' module.name_mapper='^types\(.*\)$' -> '/ui/types\1' diff --git a/ui/component/claimListHeader/view.jsx b/ui/component/claimListHeader/view.jsx index 978423210..b6ba05bb3 100644 --- a/ui/component/claimListHeader/view.jsx +++ b/ui/component/claimListHeader/view.jsx @@ -11,6 +11,7 @@ import { FormField } from 'component/common/form'; import Button from 'component/button'; import { toCapitalCase } from 'util/string'; import SEARCHABLE_LANGUAGES from 'constants/searchable_languages'; +import { ClaimSearchFilterContext } from 'contexts/claimSearchFilterContext'; type Props = { defaultTags: string, @@ -62,6 +63,7 @@ function ClaimListHeader(props: Props) { languageSetting, scrollAnchor, } = props; + const filterCtx = React.useContext(ClaimSearchFilterContext); const { action, push, location } = useHistory(); const { search } = location; const [expanded, setExpanded] = usePersistedState(`expanded-${location.pathname}`, false); @@ -345,7 +347,7 @@ function ClaimListHeader(props: Props) { }) } > - {CS.CONTENT_TYPES.map((type) => { + {filterCtx.contentTypes.map((type) => { if (type !== CS.CLAIM_CHANNEL || (type === CS.CLAIM_CHANNEL && !channelIdsParam)) { return (