Rename to "useFollowedFoldIds"
This commit is contained in:
parent
d326ae5c30
commit
6185e3b740
|
@ -1,6 +1,6 @@
|
||||||
import clsx from 'clsx'
|
import clsx from 'clsx'
|
||||||
import { Fold } from '../../../common/fold'
|
import { Fold } from '../../../common/fold'
|
||||||
import { useFollowedFolds } from '../../hooks/use-fold'
|
import { useFollowedFoldIds } from '../../hooks/use-fold'
|
||||||
import { useUser } from '../../hooks/use-user'
|
import { useUser } from '../../hooks/use-user'
|
||||||
import { followFold, unfollowFold } from '../../lib/firebase/folds'
|
import { followFold, unfollowFold } from '../../lib/firebase/folds'
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ export function FollowFoldButton(props: { fold: Fold; className?: string }) {
|
||||||
|
|
||||||
const user = useUser()
|
const user = useUser()
|
||||||
|
|
||||||
const followedFoldIds = useFollowedFolds(user)
|
const followedFoldIds = useFollowedFoldIds(user)
|
||||||
const following = followedFoldIds
|
const following = followedFoldIds
|
||||||
? followedFoldIds.includes(fold.id)
|
? followedFoldIds.includes(fold.id)
|
||||||
: undefined
|
: undefined
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { Comment, getRecentComments } from '../lib/firebase/comments'
|
||||||
import { Contract, getActiveContracts } from '../lib/firebase/contracts'
|
import { Contract, getActiveContracts } from '../lib/firebase/contracts'
|
||||||
import { listAllFolds } from '../lib/firebase/folds'
|
import { listAllFolds } from '../lib/firebase/folds'
|
||||||
import { useInactiveContracts } from './use-contracts'
|
import { useInactiveContracts } from './use-contracts'
|
||||||
import { useFollowedFolds } from './use-fold'
|
import { useFollowedFoldIds } from './use-fold'
|
||||||
import { useSeenContracts } from './use-seen-contracts'
|
import { useSeenContracts } from './use-seen-contracts'
|
||||||
import { useUserBetContracts } from './use-user-bets'
|
import { useUserBetContracts } from './use-user-bets'
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ export const useFilterYourContracts = (
|
||||||
folds: Fold[],
|
folds: Fold[],
|
||||||
contracts: Contract[]
|
contracts: Contract[]
|
||||||
) => {
|
) => {
|
||||||
const followedFoldIds = useFollowedFolds(user)
|
const followedFoldIds = useFollowedFoldIds(user)
|
||||||
|
|
||||||
const followedFolds = filterDefined(
|
const followedFolds = filterDefined(
|
||||||
(followedFoldIds ?? []).map((id) => folds.find((fold) => fold.id === id))
|
(followedFoldIds ?? []).map((id) => folds.find((fold) => fold.id === id))
|
||||||
|
|
|
@ -50,7 +50,7 @@ export const useFollowingFold = (fold: Fold, user: User | null | undefined) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: We cache FollowedFolds in localstorage to speed up the initial load
|
// Note: We cache FollowedFolds in localstorage to speed up the initial load
|
||||||
export const useFollowedFolds = (user: User | null | undefined) => {
|
export const useFollowedFoldIds = (user: User | null | undefined) => {
|
||||||
const [followedFoldIds, setFollowedFoldIds] = useState<string[] | undefined>(
|
const [followedFoldIds, setFollowedFoldIds] = useState<string[] | undefined>(
|
||||||
undefined
|
undefined
|
||||||
)
|
)
|
||||||
|
|
|
@ -7,11 +7,10 @@ import { FollowFoldButton } from '../components/folds/follow-fold-button'
|
||||||
import { Col } from '../components/layout/col'
|
import { Col } from '../components/layout/col'
|
||||||
import { Row } from '../components/layout/row'
|
import { Row } from '../components/layout/row'
|
||||||
import { Page } from '../components/page'
|
import { Page } from '../components/page'
|
||||||
import { SiteLink } from '../components/site-link'
|
|
||||||
import { TagsList } from '../components/tags-list'
|
import { TagsList } from '../components/tags-list'
|
||||||
import { Title } from '../components/title'
|
import { Title } from '../components/title'
|
||||||
import { UserLink } from '../components/user-page'
|
import { UserLink } from '../components/user-page'
|
||||||
import { useFolds, useFollowedFolds } from '../hooks/use-fold'
|
import { useFolds, useFollowedFoldIds } from '../hooks/use-fold'
|
||||||
import { useUser } from '../hooks/use-user'
|
import { useUser } from '../hooks/use-user'
|
||||||
import { foldPath, listAllFolds } from '../lib/firebase/folds'
|
import { foldPath, listAllFolds } from '../lib/firebase/folds'
|
||||||
import { getUser, User } from '../lib/firebase/users'
|
import { getUser, User } from '../lib/firebase/users'
|
||||||
|
@ -44,7 +43,7 @@ export default function Folds(props: {
|
||||||
|
|
||||||
let folds = useFolds() ?? props.folds
|
let folds = useFolds() ?? props.folds
|
||||||
const user = useUser()
|
const user = useUser()
|
||||||
const followedFoldIds = useFollowedFolds(user) || []
|
const followedFoldIds = useFollowedFoldIds(user) || []
|
||||||
// First sort by follower count, then list followed folds first
|
// First sort by follower count, then list followed folds first
|
||||||
folds = _.sortBy(folds, (fold) => -1 * fold.followCount)
|
folds = _.sortBy(folds, (fold) => -1 * fold.followCount)
|
||||||
folds = _.sortBy(folds, (fold) => !followedFoldIds.includes(fold.id))
|
folds = _.sortBy(folds, (fold) => !followedFoldIds.includes(fold.id))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user