@@ -3,12 +3,15 @@ import React, { useEffect, useMemo, useRef } from 'react';
33import classNames from 'classnames' ;
44import { useRouter } from 'next/router' ;
55import Link from '../utilities/Link' ;
6+ import { PlusIcon } from '../icons' ;
67import { webappUrl } from '../../lib/constants' ;
78import useCustomDefaultFeed from '../../hooks/feed/useCustomDefaultFeed' ;
89import { ElementPlaceholder } from '../ElementPlaceholder' ;
910import { useLogContext } from '../../contexts/LogContext' ;
1011import type { ExploreCategory } from './exploreCategories' ;
12+ import { findActiveChipId } from './exploreCategories' ;
1113import { LogEvent } from '../../lib/log' ;
14+ import { NewStripCta } from './NewStripCta' ;
1215
1316interface ExploreChipsBarProps {
1417 categories : ExploreCategory [ ] ;
@@ -20,14 +23,6 @@ const PLACEHOLDER_WIDTHS = ['w-20', 'w-16', 'w-24', 'w-20', 'w-28', 'w-16'];
2023
2124const FOR_YOU_CATEGORY_ID = 'foryou' ;
2225
23- const normalizePath = ( p : string ) : string => {
24- const noQuery = p . split ( '?' ) [ 0 ] ;
25- if ( ! noQuery || noQuery === '/' ) {
26- return '/' ;
27- }
28- return noQuery . replace ( / \/ $ / , '' ) ;
29- } ;
30-
3126export function ExploreChipsBar ( {
3227 categories,
3328 isPending,
@@ -37,24 +32,34 @@ export function ExploreChipsBar({
3732 const { isCustomDefaultFeed } = useCustomDefaultFeed ( ) ;
3833 const { logEvent } = useLogContext ( ) ;
3934
40- const forYouCategory : ExploreCategory = useMemo (
41- ( ) => ( {
35+ const forYouCategory : ExploreCategory = useMemo ( ( ) => {
36+ const path = isCustomDefaultFeed ? `${ webappUrl } my-feed` : webappUrl ;
37+ return {
4238 id : FOR_YOU_CATEGORY_ID ,
4339 label : 'For you' ,
44- path : isCustomDefaultFeed ? `${ webappUrl } my-feed` : webappUrl ,
45- } ) ,
46- [ isCustomDefaultFeed ] ,
47- ) ;
48- const activePath = useMemo (
49- ( ) => normalizePath ( router . asPath ) ,
50- [ router . asPath ] ,
51- ) ;
40+ path,
41+ // When a custom feed is the default, `/` shows that feed (not "For you"
42+ // content) — restrict matching to `/my-feed`. Without a custom default
43+ // `/` is MyFeed, so include both.
44+ matchPaths : isCustomDefaultFeed
45+ ? [ `${ webappUrl } my-feed` ]
46+ : [ path , webappUrl , `${ webappUrl } my-feed` ] ,
47+ } ;
48+ } , [ isCustomDefaultFeed ] ) ;
5249
5350 const allCategories = useMemo (
5451 ( ) => [ forYouCategory , ...categories ] ,
5552 [ forYouCategory , categories ] ,
5653 ) ;
5754
55+ const activeId = useMemo (
56+ ( ) =>
57+ findActiveChipId ( allCategories , router . asPath , {
58+ preferId : FOR_YOU_CATEGORY_ID ,
59+ } ) ,
60+ [ allCategories , router . asPath ] ,
61+ ) ;
62+
5863 const scrollRef = useRef < HTMLDivElement > ( null ) ;
5964 useEffect ( ( ) => {
6065 const active = scrollRef . current ?. querySelector < HTMLElement > (
@@ -64,25 +69,17 @@ export function ExploreChipsBar({
6469 return ;
6570 }
6671 active . scrollIntoView ( { block : 'nearest' , inline : 'center' } ) ;
67- } , [ activePath , allCategories ] ) ;
72+ } , [ activeId , allCategories ] ) ;
6873
6974 return (
7075 < div className = { classNames ( 'relative' , className ) } >
7176 < div
7277 ref = { scrollRef }
7378 className = "no-scrollbar flex items-center gap-2 overflow-x-auto pr-12"
7479 >
80+ < NewStripCta className = "h-10 rounded-12 px-3" />
7581 { allCategories . map ( ( category ) => {
76- // For You owns the homepage. Match it against both `/` and `/my-feed`
77- // so the user's default custom feed (also at `/`) doesn't steal the
78- // active state.
79- const isForYou = category . id === FOR_YOU_CATEGORY_ID ;
80- const candidates = isForYou
81- ? [ category . path , webappUrl , `${ webappUrl } my-feed` ]
82- : [ category . path ] ;
83- const isActive = candidates . some (
84- ( candidate ) => normalizePath ( candidate ) === activePath ,
85- ) ;
82+ const isActive = category . id === activeId ;
8683 return (
8784 < Link key = { category . id } href = { category . path } >
8885 < a
@@ -121,6 +118,15 @@ export function ExploreChipsBar({
121118 className = { classNames ( 'h-10 shrink-0 rounded-12' , width ) }
122119 />
123120 ) ) }
121+ < Link href = { `${ webappUrl } feeds/new` } >
122+ < a
123+ href = { `${ webappUrl } feeds/new` }
124+ aria-label = "New feed"
125+ className = "inline-flex h-10 shrink-0 items-center justify-center rounded-12 border border-transparent bg-background-subtle px-3 text-text-tertiary transition-colors hover:bg-surface-hover hover:text-text-primary"
126+ >
127+ < PlusIcon />
128+ </ a >
129+ </ Link >
124130 </ div >
125131 < div
126132 aria-hidden
0 commit comments