Show followed folds first
This commit is contained in:
parent
8773bf7624
commit
14e2071b1d
|
@ -49,6 +49,7 @@ export const useFollowingFold = (fold: Fold, user: User | null | undefined) => {
|
||||||
return following
|
return following
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Note: We cache FollowedFolds in localstorage to speed up the initial load
|
||||||
export const useFollowedFolds = (user: User | null | undefined) => {
|
export const useFollowedFolds = (user: User | null | undefined) => {
|
||||||
const [followedFoldIds, setFollowedFoldIds] = useState<string[] | undefined>(
|
const [followedFoldIds, setFollowedFoldIds] = useState<string[] | undefined>(
|
||||||
undefined
|
undefined
|
||||||
|
|
|
@ -11,7 +11,7 @@ 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 } from '../hooks/use-fold'
|
import { useFolds, useFollowedFolds } 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'
|
||||||
|
@ -43,8 +43,11 @@ export default function Folds(props: {
|
||||||
const [curatorsDict, setCuratorsDict] = useState(props.curatorsDict)
|
const [curatorsDict, setCuratorsDict] = useState(props.curatorsDict)
|
||||||
|
|
||||||
let folds = useFolds() ?? props.folds
|
let folds = useFolds() ?? props.folds
|
||||||
folds = _.sortBy(folds, (fold) => -1 * fold.followCount)
|
|
||||||
const user = useUser()
|
const user = useUser()
|
||||||
|
const followedFoldIds = useFollowedFolds(user) || []
|
||||||
|
// First sort by follower count, then list followed folds first
|
||||||
|
folds = _.sortBy(folds, (fold) => -1 * fold.followCount)
|
||||||
|
folds = _.sortBy(folds, (fold) => !followedFoldIds.includes(fold.id))
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Load User object for curator of new Folds.
|
// Load User object for curator of new Folds.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user