(tab: ClusterTab)
| 170 | // What a tab does when chosen; the link's own navigation covers the |
| 171 | // remaining case (a mouse click on another root). |
| 172 | const activate = (tab: ClusterTab): boolean => { |
| 173 | logTab(tab); |
| 174 | |
| 175 | if (!user && tab.requiresLogin) { |
| 176 | showLogin({ trigger: tab.trigger ?? AuthTriggers.MainButton }); |
| 177 | return true; |
| 178 | } |
| 179 | |
| 180 | if (tab.root !== active) { |
| 181 | haptic(); |
| 182 | } |
| 183 | |
| 184 | // The lit tab, as on X and Instagram: from a leaf it returns to the |
| 185 | // root; on the root it scrolls to the top; at the top it refreshes. |
| 186 | if (tab.root === active) { |
| 187 | if (!isRootView(tab.root, router.pathname)) { |
| 188 | moveShell(router, ShellMove.Pop, () => router.push(tab.href)); |
| 189 | return true; |
| 190 | } |
| 191 | // Home's segments (Happening now, Following, custom feeds) are views |
| 192 | // of Home, but the tab itself means the main feed: from another |
| 193 | // segment it switches back there, the way the segments switch, rather |
| 194 | // than refreshing the segment the reader is on. |
| 195 | if ( |
| 196 | tab.root === ShellRoot.Home && |
| 197 | withoutLayoutVariantPrefix(router.pathname ?? '') !== tab.href |
| 198 | ) { |
| 199 | router.replace(tab.href); |
| 200 | return true; |
| 201 | } |
| 202 | revealShell(); |
| 203 | if (window.scrollY > 0) { |
| 204 | window.scrollTo({ top: 0, behavior: 'smooth' }); |
| 205 | } else { |
| 206 | refreshShell(queryClient); |
| 207 | } |
| 208 | return true; |
| 209 | } |
| 210 | |
| 211 | return false; |
| 212 | }; |
| 213 | |
| 214 | const onTabClick = (tab: ClusterTab) => (event: React.MouseEvent) => { |
| 215 | if (activate(tab)) { |
no test coverage detected