diff --git a/common/categories.ts b/common/categories.ts index 9d290d66..2bd6d25a 100644 --- a/common/categories.ts +++ b/common/categories.ts @@ -1,3 +1,5 @@ +import { difference } from 'lodash' + export const CATEGORIES = { politics: 'Politics', technology: 'Technology', @@ -12,10 +14,19 @@ export const CATEGORIES = { crypto: 'Crypto', gaming: 'Gaming', fun: 'Fun', -} as { [category: string]: string } +} + +export type category = keyof typeof CATEGORIES export const TO_CATEGORY = Object.fromEntries( Object.entries(CATEGORIES).map(([k, v]) => [v, k]) ) export const CATEGORY_LIST = Object.keys(CATEGORIES) + +export const EXCLUDED_CATEGORIES: category[] = ['fun', 'manifold', 'personal'] + +export const DEFAULT_CATEGORIES = difference( + CATEGORY_LIST, + EXCLUDED_CATEGORIES +) diff --git a/functions/src/create-user.ts b/functions/src/create-user.ts index 09b1e638..9849fce4 100644 --- a/functions/src/create-user.ts +++ b/functions/src/create-user.ts @@ -15,6 +15,8 @@ import { } from '../../common/util/clean-username' import { sendWelcomeEmail } from './emails' import { isWhitelisted } from '../../common/envs/constants' +import { DEFAULT_CATEGORIES } from '../../common/categories' + import { track } from './analytics' export const createUser = functions @@ -70,6 +72,7 @@ export const createUser = functions createdTime: Date.now(), totalPnLCached: 0, creatorVolumeCached: 0, + followedCategories: DEFAULT_CATEGORIES, } await firestore.collection('users').doc(userId).create(user) diff --git a/web/components/contract-search.tsx b/web/components/contract-search.tsx index afb9c398..34a00b76 100644 --- a/web/components/contract-search.tsx +++ b/web/components/contract-search.tsx @@ -23,7 +23,7 @@ import { ENV } from 'common/envs/constants' import { useUser } from 'web/hooks/use-user' import { useFollows } from 'web/hooks/use-follows' import { EditCategoriesButton } from './feed/category-selector' -import { CATEGORIES } from 'common/categories' +import { CATEGORIES, category } from 'common/categories' import { Tabs } from './layout/tabs' import { EditFollowingButton } from './following-button' import { track } from '@amplitude/analytics-browser' @@ -264,7 +264,7 @@ function CategoryFollowSelector(props: { if (followedCategories.length) { const categoriesLabel = followedCategories .slice(0, 3) - .map((cat) => CATEGORIES[cat]) + .map((cat) => CATEGORIES[cat as category]) .join(', ') const andMoreLabel = followedCategories.length > 3 diff --git a/web/components/feed/category-selector.tsx b/web/components/feed/category-selector.tsx index db9a856a..a39f7402 100644 --- a/web/components/feed/category-selector.tsx +++ b/web/components/feed/category-selector.tsx @@ -3,7 +3,7 @@ import { PencilIcon } from '@heroicons/react/outline' import { union, difference } from 'lodash' import { Row } from '../layout/row' -import { CATEGORIES, CATEGORY_LIST } from '../../../common/categories' +import { CATEGORIES, category, CATEGORY_LIST } from '../../../common/categories' import { Modal } from '../layout/modal' import { Col } from '../layout/col' import { useState } from 'react' @@ -47,7 +47,7 @@ export function CategorySelector(props: { {CATEGORY_LIST.map((cat) => ( { setCategory(cat) @@ -149,7 +149,7 @@ function CategorySelectorModal(props: { { updateUser(user.id, { diff --git a/web/components/tags-list.tsx b/web/components/tags-list.tsx index 073d3947..a13bcd35 100644 --- a/web/components/tags-list.tsx +++ b/web/components/tags-list.tsx @@ -1,5 +1,5 @@ import clsx from 'clsx' -import { CATEGORIES } from '../../common/categories' +import { CATEGORIES, category } from '../../common/categories' import { Col } from './layout/col' import { Row } from './layout/row' @@ -7,7 +7,7 @@ import { SiteLink } from './site-link' function Hashtag(props: { tag: string; noLink?: boolean }) { const { tag, noLink } = props - const category = CATEGORIES[tag.replace('#', '').toLowerCase()] + const category = CATEGORIES[tag.replace('#', '').toLowerCase() as category] const body = (