Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

adaptive-navigation.ts

35 lines1.3 KB

1export type AdaptiveNavigationAction = "push" | "replace" | "set-params";
2​
3const BASE_THREAD_ROUTE_PATTERN = /^\/threads\/[^/]+\/[^/]+\/?$/;
4​
5export function isBaseThreadRoute(pathname: string): boolean {
6 return BASE_THREAD_ROUTE_PATTERN.test(pathname);
7}
8​
9/**
10 * A persistent sidebar selects a peer destination in place. A compact list
11 * drills into a new destination so the native back stack remains available.
12 * From Home the selection pushes (never replaces) so Home stays beneath the
13 * thread — collapsing back to a compact width keeps a sane back stack.
14 */
15export function resolveThreadSelectionNavigationAction(input: {
16 readonly usesSplitView: boolean;
17 readonly pathname: string;
18}): AdaptiveNavigationAction {
19 if (!input.usesSplitView || input.pathname === "/") {
20 return "push";
21 }
22​
23 return isBaseThreadRoute(input.pathname) ? "set-params" : "replace";
25​
26/**
27 * On regular-width layouts, the file browser and preview occupy one workspace
28 * destination. Replacing the browser route keeps a single back step to chat.
29 * Compact layouts retain the browser as the previous stack screen.
30 */
31export function resolveFileSelectionNavigationAction(input: {
32 readonly hasPersistentFileInspector: boolean;
33}): AdaptiveNavigationAction {
34 return input.hasPersistentFileInspector ? "replace" : "push";