({ forYou }: HomeSegmentsProps = {})
| 182 | } |
| 183 | |
| 184 | export function HomeSegments({ forYou }: HomeSegmentsProps = {}): ReactElement { |
| 185 | const router = useRouter(); |
| 186 | const { user } = useAuthContext(); |
| 187 | const { logEvent } = useLogContext(); |
| 188 | const { feeds } = useFeeds(); |
| 189 | const { isCustomDefaultFeed, defaultFeedId } = useCustomDefaultFeed(); |
| 190 | const sortedFeeds = useSortedFeeds({ edges: feeds?.edges }); |
| 191 | const [isChannelsOpen, setIsChannelsOpen] = useState(false); |
| 192 | const [openFeed, setOpenFeed] = useState<OpenFeed | null>(null); |
| 193 | // From the address rather than the route: with Happening now in place the |
| 194 | // route is still the feed page's. |
| 195 | const path = getAsPathname(router); |
| 196 | const forYouHref = isCustomDefaultFeed ? `${webappUrl}my-feed` : webappUrl; |
| 197 | const isHighlights = path.startsWith('/highlights'); |
| 198 | |
| 199 | const items: RowItem[] = []; |
| 200 | |
| 201 | const feedMenu = (title: string, editHref: string): RowItem['menu'] => ({ |
| 202 | ariaLabel: `${title}, feed options`, |
| 203 | onOpen: () => setOpenFeed({ title, editHref }), |
| 204 | }); |
| 205 | |
| 206 | // For you lights on `/` even when a custom default feed is the page, and |
| 207 | // then it must stay a link to /my-feed: the menu is the feed on screen's. |
| 208 | const isForYouMenu = |
| 209 | !!user && |
| 210 | !!forYou && |
| 211 | (path === '/my-feed' || (path === '/' && !isCustomDefaultFeed)); |
| 212 | |
| 213 | // A caller with its own For you sheet owns that tab's menu, and shows the |
| 214 | // feed's settings itself while a custom default feed is the page. |
| 215 | const forYouMenu = (isDefaultCustom: boolean): RowItem['menu'] => { |
| 216 | if (forYou) { |
| 217 | return isForYouMenu |
| 218 | ? { ariaLabel: forYou.ariaLabel, onOpen: forYou.onMenu } |
| 219 | : undefined; |
| 220 | } |
| 221 | return feedMenu( |
| 222 | 'For you', |
| 223 | isDefaultCustom |
| 224 | ? `${webappUrl}feeds/${defaultFeedId}/edit` |
| 225 | : `${webappUrl}feeds/${user?.id}/edit?dview=${FeedSettingsMenu.Tags}`, |
| 226 | ); |
| 227 | }; |
| 228 | |
| 229 | if (user) { |
| 230 | const isDefaultCustom = isCustomDefaultFeed && path === '/'; |
| 231 | items.push({ |
| 232 | key: forYouKey, |
| 233 | label: isForYouMenu ? forYou?.label : 'For you', |
| 234 | ariaLabel: isForYouMenu ? forYou?.ariaLabel : undefined, |
| 235 | href: forYouHref, |
| 236 | active: path === '/' || path === '/my-feed', |
| 237 | replace: true, |
| 238 | menu: forYouMenu(isDefaultCustom), |
| 239 | }); |
| 240 | } |
| 241 |
nothing calls this directly
no test coverage detected