(activeFeed: AllFeedPages)
| 17 | } |
| 18 | |
| 19 | export default function useActiveNav(activeFeed: AllFeedPages): UseActiveNav { |
| 20 | const router = useRouter(); |
| 21 | const isMobile = useViewSize(ViewSize.MobileL); |
| 22 | const isHomeActive = useMemo(() => { |
| 23 | const homePages = [ |
| 24 | SharedFeedPage.MyFeed, |
| 25 | SharedFeedPage.Popular, |
| 26 | SharedFeedPage.Upvoted, |
| 27 | OtherFeedPage.Discussed, |
| 28 | OtherFeedPage.History, |
| 29 | SharedFeedPage.Custom, |
| 30 | SharedFeedPage.CustomForm, |
| 31 | OtherFeedPage.Tags, |
| 32 | OtherFeedPage.Sources, |
| 33 | OtherFeedPage.Leaderboard, |
| 34 | OtherFeedPage.Following, |
| 35 | ]; |
| 36 | |
| 37 | if (!isMobile) { |
| 38 | homePages.push(OtherFeedPage.Notifications); |
| 39 | } |
| 40 | |
| 41 | if (homePages.includes(activeFeed)) { |
| 42 | return true; |
| 43 | } |
| 44 | |
| 45 | if (router?.route?.startsWith('/explore/')) { |
| 46 | return true; |
| 47 | } |
| 48 | |
| 49 | return router?.route?.startsWith('/posts/[id]'); // if post page the [id] was expected |
| 50 | }, [activeFeed, isMobile, router?.route]); |
| 51 | |
| 52 | const explorePages: AllFeedPages[] = [ |
| 53 | SharedFeedPage.Search, |
| 54 | OtherFeedPage.Explore, |
| 55 | OtherFeedPage.ExploreLatest, |
| 56 | OtherFeedPage.ExploreUpvoted, |
| 57 | OtherFeedPage.ExploreDiscussed, |
| 58 | ]; |
| 59 | const isProfileActive = router.pathname?.includes('/[userId]'); |
| 60 | const isJobsActive = router.pathname?.startsWith('/jobs'); |
| 61 | const isHighlightsActive = router.pathname?.startsWith('/highlights'); |
| 62 | const isExploreActive = explorePages.includes(activeFeed); |
| 63 | const bookmarksPages: AllFeedPages[] = [ |
| 64 | OtherFeedPage.Bookmarks, |
| 65 | OtherFeedPage.BookmarkLater, |
| 66 | OtherFeedPage.BookmarkFolder, |
| 67 | ]; |
| 68 | const isBookmarksActive = bookmarksPages.includes(activeFeed); |
| 69 | const isNotificationsActive = activeFeed === OtherFeedPage.Notifications; |
| 70 | const isSquadsActive = activeFeed.includes(OtherFeedPage.Squad); |
| 71 | |
| 72 | return { |
| 73 | home: isHomeActive, |
| 74 | profile: isProfileActive, |
| 75 | bookmarks: isBookmarksActive, |
| 76 | notifications: isNotificationsActive, |
no test coverage detected