From 50ccc684063c0e61e2b10c2a43405525dfc6d35a Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Tue, 29 Mar 2022 10:10:40 -0700 Subject: [PATCH] Cache followed folds in localstorage --- web/components/nav/sidebar.tsx | 15 +++++++++---- web/hooks/use-fold.ts | 39 +++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/web/components/nav/sidebar.tsx b/web/components/nav/sidebar.tsx index cc735227..fd70541a 100644 --- a/web/components/nav/sidebar.tsx +++ b/web/components/nav/sidebar.tsx @@ -5,8 +5,11 @@ import { BookOpenIcon, } from '@heroicons/react/outline' import clsx from 'clsx' +import _ from 'lodash' import Link from 'next/link' import { useRouter } from 'next/router' +import { useFollowedFolds } from '../../hooks/use-fold' +import { useUser } from '../../hooks/use-user' const navigation = [ { name: 'Home', href: '/home', icon: HomeIcon }, @@ -65,6 +68,10 @@ export default function Sidebar() { const router = useRouter() const currentPage = router.pathname + const user = useUser() + let folds = useFollowedFolds(user) || [] + folds = _.sortBy(folds, 'followCount').reverse() + return (