search: use default categories for non-authed users
This commit is contained in:
parent
0013f76873
commit
2b13085dff
|
@ -1,6 +1,7 @@
|
||||||
import { difference } from 'lodash'
|
import { difference } from 'lodash'
|
||||||
|
|
||||||
export const CATEGORIES_GROUP_SLUG_POSTFIX = '-default'
|
export const CATEGORIES_GROUP_SLUG_POSTFIX = '-default'
|
||||||
|
|
||||||
export const CATEGORIES = {
|
export const CATEGORIES = {
|
||||||
politics: 'Politics',
|
politics: 'Politics',
|
||||||
technology: 'Technology',
|
technology: 'Technology',
|
||||||
|
@ -37,3 +38,8 @@ export const EXCLUDED_CATEGORIES: category[] = [
|
||||||
]
|
]
|
||||||
|
|
||||||
export const DEFAULT_CATEGORIES = difference(CATEGORY_LIST, EXCLUDED_CATEGORIES)
|
export const DEFAULT_CATEGORIES = difference(CATEGORY_LIST, EXCLUDED_CATEGORIES)
|
||||||
|
|
||||||
|
export const DEFAULT_CATEGORY_GROUPS = DEFAULT_CATEGORIES.map((c) => ({
|
||||||
|
slug: c.toLowerCase() + CATEGORIES_GROUP_SLUG_POSTFIX,
|
||||||
|
name: CATEGORIES[c as category],
|
||||||
|
}))
|
||||||
|
|
|
@ -25,9 +25,10 @@ import { useFollows } from 'web/hooks/use-follows'
|
||||||
import { trackCallback } from 'web/lib/service/analytics'
|
import { trackCallback } from 'web/lib/service/analytics'
|
||||||
import ContractSearchFirestore from 'web/pages/contract-search-firestore'
|
import ContractSearchFirestore from 'web/pages/contract-search-firestore'
|
||||||
import { useMemberGroups } from 'web/hooks/use-group'
|
import { useMemberGroups } from 'web/hooks/use-group'
|
||||||
import { NEW_USER_GROUP_SLUGS } from 'common/group'
|
import { Group, NEW_USER_GROUP_SLUGS } from 'common/group'
|
||||||
import { PillButton } from './buttons/pill-button'
|
import { PillButton } from './buttons/pill-button'
|
||||||
import { sortBy } from 'lodash'
|
import { sortBy } from 'lodash'
|
||||||
|
import { DEFAULT_CATEGORY_GROUPS } from 'common/categories'
|
||||||
|
|
||||||
const searchClient = algoliasearch(
|
const searchClient = algoliasearch(
|
||||||
'GJQPAYENIF',
|
'GJQPAYENIF',
|
||||||
|
@ -82,11 +83,21 @@ export function ContractSearch(props: {
|
||||||
const memberGroups = (useMemberGroups(user?.id) ?? []).filter(
|
const memberGroups = (useMemberGroups(user?.id) ?? []).filter(
|
||||||
(group) => !NEW_USER_GROUP_SLUGS.includes(group.slug)
|
(group) => !NEW_USER_GROUP_SLUGS.includes(group.slug)
|
||||||
)
|
)
|
||||||
const memberGroupSlugs = memberGroups.map((g) => g.slug)
|
const memberGroupSlugs =
|
||||||
const pillGroups = sortBy(
|
memberGroups.length > 0
|
||||||
|
? memberGroups.map((g) => g.slug)
|
||||||
|
: DEFAULT_CATEGORY_GROUPS.map((g) => g.slug)
|
||||||
|
|
||||||
|
const memberPillGroups = sortBy(
|
||||||
memberGroups.filter((group) => group.contractIds.length > 0),
|
memberGroups.filter((group) => group.contractIds.length > 0),
|
||||||
(group) => group.contractIds.length
|
(group) => group.contractIds.length
|
||||||
).reverse()
|
).reverse()
|
||||||
|
|
||||||
|
const defaultPillGroups = DEFAULT_CATEGORY_GROUPS as Group[]
|
||||||
|
|
||||||
|
const pillGroups =
|
||||||
|
memberPillGroups.length > 0 ? memberPillGroups : defaultPillGroups
|
||||||
|
|
||||||
const follows = useFollows(user?.id)
|
const follows = useFollows(user?.id)
|
||||||
const { initialSort } = useInitialQueryAndSort(querySortOptions)
|
const { initialSort } = useInitialQueryAndSort(querySortOptions)
|
||||||
|
|
||||||
|
@ -113,9 +124,7 @@ export function ContractSearch(props: {
|
||||||
additionalFilter?.groupSlug
|
additionalFilter?.groupSlug
|
||||||
? `groupSlugs:${additionalFilter.groupSlug}`
|
? `groupSlugs:${additionalFilter.groupSlug}`
|
||||||
: '',
|
: '',
|
||||||
pillFilter && pillFilter !== 'personal'
|
pillFilter && pillFilter !== 'personal' ? `groupSlugs:${pillFilter}` : '',
|
||||||
? `groupSlugs:${pillFilter}`
|
|
||||||
: '',
|
|
||||||
pillFilter === 'personal'
|
pillFilter === 'personal'
|
||||||
? // Show contracts in groups that the user is a member of
|
? // Show contracts in groups that the user is a member of
|
||||||
memberGroupSlugs
|
memberGroupSlugs
|
||||||
|
@ -217,6 +226,7 @@ export function ContractSearch(props: {
|
||||||
>
|
>
|
||||||
For you
|
For you
|
||||||
</PillButton>
|
</PillButton>
|
||||||
|
|
||||||
{pillGroups.map(({ name, slug }) => {
|
{pillGroups.map(({ name, slug }) => {
|
||||||
return (
|
return (
|
||||||
<PillButton
|
<PillButton
|
||||||
|
|
Loading…
Reference in New Issue
Block a user