import clsx from 'clsx' import _ from 'lodash' import { User } from '../../../common/user' import { Row } from '../layout/row' import { CATEGORIES, FEED_CATEGORY_LIST } from '../../../common/categories' import { updateUser } from '../../lib/firebase/users' export function CategorySelector(props: { user: User | null | undefined className?: string }) { const { className, user } = props const followedCategories = user?.followedCategories ?? [] return (
Categories
{ if (!user?.id) return await updateUser(user.id, { followedCategories: [], }) }} /> {FEED_CATEGORY_LIST.map((cat) => ( { if (!user?.id) return await updateUser(user.id, { followedCategories: !followedCategories.includes(cat) ? _.union([cat], followedCategories) : _.difference(followedCategories, [cat]), }) }} /> ))}
) } function CategoryButton(props: { category: string isFollowed: boolean toggle: () => void }) { const { toggle, category, isFollowed } = props return (
{category}
) }