'Discover' => 'Similar' and shows recs based on user you have open

This commit is contained in:
James Grugett 2022-06-08 14:38:04 -05:00
parent d7e52c1969
commit f809acd6fd
3 changed files with 13 additions and 16 deletions

View File

@ -23,7 +23,7 @@ export function FollowingButton(props: { user: User }) {
Following Following
</TextButton> </TextButton>
<FollowingFollowersDialog <FollowsDialog
user={user} user={user}
defaultTab="following" defaultTab="following"
followingIds={followingIds ?? []} followingIds={followingIds ?? []}
@ -45,7 +45,7 @@ export function EditFollowingButton(props: { user: User; className?: string }) {
<TextButton className={className} onClick={() => setIsOpen(true)}> <TextButton className={className} onClick={() => setIsOpen(true)}>
<PencilIcon className="inline h-4 w-4" /> <PencilIcon className="inline h-4 w-4" />
Following Following
<FollowingFollowersDialog <FollowsDialog
user={user} user={user}
defaultTab="following" defaultTab="following"
followingIds={followingIds ?? []} followingIds={followingIds ?? []}
@ -70,7 +70,7 @@ export function FollowersButton(props: { user: User }) {
Followers Followers
</TextButton> </TextButton>
<FollowingFollowersDialog <FollowsDialog
user={user} user={user}
defaultTab="followers" defaultTab="followers"
followingIds={followingIds ?? []} followingIds={followingIds ?? []}
@ -82,7 +82,7 @@ export function FollowersButton(props: { user: User }) {
) )
} }
function FollowingFollowersDialog(props: { function FollowsDialog(props: {
user: User user: User
followingIds: string[] followingIds: string[]
followerIds: string[] followerIds: string[]
@ -99,7 +99,7 @@ function FollowingFollowersDialog(props: {
const currentUser = useUser() const currentUser = useUser()
const discoverUserIds = useDiscoverUsers() const discoverUserIds = useDiscoverUsers(user?.id)
useEffect(() => { useEffect(() => {
prefetchUsers(discoverUserIds) prefetchUsers(discoverUserIds)
}, [discoverUserIds]) }, [discoverUserIds])
@ -122,7 +122,7 @@ function FollowingFollowersDialog(props: {
...(currentUser ...(currentUser
? [ ? [
{ {
title: 'Discover', title: 'Similar',
content: <FollowList userIds={discoverUserIds} />, content: <FollowList userIds={discoverUserIds} />,
}, },
] ]

View File

@ -1,7 +1,7 @@
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { listenForFollowers, listenForFollows } from 'web/lib/firebase/users' import { listenForFollowers, listenForFollows } from 'web/lib/firebase/users'
export const useFollows = (userId: string | undefined) => { export const useFollows = (userId: string | null | undefined) => {
const [followIds, setFollowIds] = useState<string[] | undefined>() const [followIds, setFollowIds] = useState<string[] | undefined>()
useEffect(() => { useEffect(() => {

View File

@ -5,7 +5,6 @@ import {
listenForAllUsers, listenForAllUsers,
listenForPrivateUsers, listenForPrivateUsers,
} from 'web/lib/firebase/users' } from 'web/lib/firebase/users'
import { useUser } from './use-user'
import { groupBy, sortBy, difference } from 'lodash' import { groupBy, sortBy, difference } from 'lodash'
import { getContractsOfUserBets } from 'web/lib/firebase/bets' import { getContractsOfUserBets } from 'web/lib/firebase/bets'
import { useFollows } from './use-follows' import { useFollows } from './use-follows'
@ -42,14 +41,12 @@ export const usePrivateUsers = () => {
return users return users
} }
export const useDiscoverUsers = () => { export const useDiscoverUsers = (userId: string | null | undefined) => {
const user = useUser()
const [discoverUserIds, setDiscoverUserIds] = useState<string[]>([]) const [discoverUserIds, setDiscoverUserIds] = useState<string[]>([])
useEffect(() => { useEffect(() => {
if (user) if (userId)
getContractsOfUserBets(user.id).then((contracts) => { getContractsOfUserBets(userId).then((contracts) => {
const creatorCounts = Object.entries( const creatorCounts = Object.entries(
groupBy(contracts, 'creatorId') groupBy(contracts, 'creatorId')
).map(([id, contracts]) => [id, contracts.length] as const) ).map(([id, contracts]) => [id, contracts.length] as const)
@ -60,10 +57,10 @@ export const useDiscoverUsers = () => {
setDiscoverUserIds(topCreatorIds) setDiscoverUserIds(topCreatorIds)
}) })
}, [user]) }, [userId])
const followedUserIds = useFollows(user?.id) const followedUserIds = useFollows(userId)
const nonSuggestions = [user?.id ?? '', ...(followedUserIds ?? [])] const nonSuggestions = [userId ?? '', ...(followedUserIds ?? [])]
return difference(discoverUserIds, nonSuggestions).slice(0, 50) return difference(discoverUserIds, nonSuggestions).slice(0, 50)
} }