Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions apps/mobile/src/features/files/ThreadFilesRouteScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { copyTextWithHaptic } from "../../lib/copyTextWithHaptic";
import { isPdfFile } from "../../lib/filePreview";
import { tryOpenExternalUrl } from "../../lib/openExternalUrl";
import { useUniwindTheme } from "../../lib/useUniwindTheme";
import { firstRouteParam } from "../../lib/routeParams";
import type { MediaVideoPreviewSource } from "../../lib/videoPreviewSource";
import { useMediaActions } from "../../state/mediaActions";
import { type MediaActionsSource } from "../../lib/mediaActionsSource";
Expand Down Expand Up @@ -175,11 +176,6 @@ function FileHeader(props: {

type FileViewMode = "preview" | "source";

function firstRouteParam(value: string | string[] | undefined): string | null {
const first = Array.isArray(value) ? value[0] : value;
return first === undefined || first.trim().length === 0 ? null : first;
}

function normalizeRoutePath(value: string | string[] | undefined): string | null {
const path = Array.isArray(value) ? value.join("/") : value;
if (path === undefined || path.trim().length === 0) {
Expand Down
9 changes: 9 additions & 0 deletions apps/mobile/src/features/shortcuts/appShortcuts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,22 @@ describe("activeThreadRef", () => {
{ environmentId: " ", threadId: "thread-2" },
{ environmentId: "env-1", threadId: " " },
{ environmentId: 42, threadId: "thread-2" },
{ environmentId: null, threadId: "thread-2" },
{ environmentId: { nested: true }, threadId: "thread-2" },
{ environmentId: [], threadId: [] },
];
for (const params of malformed) {
expect(activeThreadRef(navState({ name: "Thread", params }))).toBe(null);
}
});

it("uses the trimmed first value of each param", () => {
const params = { environmentId: [" env-1 ", "env-2"], threadId: "thread-2 " };
expect(activeThreadRef(navState({ name: "Thread", params }))).toEqual({
environmentId: "env-1",
threadId: "thread-2",
});
});
});

describe("launcher shortcut ids", () => {
Expand Down
9 changes: 1 addition & 8 deletions apps/mobile/src/features/shortcuts/appShortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { NavigationState } from "@react-navigation/native";
import { EnvironmentId, ThreadId, type ScopedThreadRef } from "@t3tools/contracts";

import type { RecentThreadShortcut } from "../../persistence/imperative";
import { firstRouteParam } from "../../lib/routeParams";

const MAX_RECENT_THREAD_SHORTCUTS = 3;

Expand All @@ -17,14 +18,6 @@ function threadShortcutHref(thread: RecentThreadShortcut): string {
return `/threads/${encodeURIComponent(thread.environmentId)}/${encodeURIComponent(thread.threadId)}`;
}

function firstRouteParam(value: string | string[] | undefined): string | null {
if (Array.isArray(value)) {
return value[0] ?? null;
}

return value ?? null;
}

/** Never throw: malformed deep-link or restored ids can fail schema constructors during root-stack render. */
export function activeThreadRef(state: NavigationState): ScopedThreadRef | null {
const route = state.routes[state.index];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { useEnvironmentQuery } from "../../state/query";
import { appAtomRegistry } from "../../state/atom-registry";
import { useAtomCommand } from "../../state/use-atom-command";
import { uuidv4 } from "../../lib/uuid";
import { firstRouteParam } from "../../lib/routeParams";
import { useServerConfigs } from "../../state/entities";
import { useConnectionsReady } from "../../state/workspace";
import {
Expand Down Expand Up @@ -200,11 +201,6 @@ type TerminalToolbarAction =
readonly modifier: PendingModifier;
};

function firstRouteParam(value: string | string[] | undefined): string | null {
const first = Array.isArray(value) ? value[0] : value;
return first === undefined || first.trim().length === 0 ? null : first;
}

function inferHostPlatform(environmentLabel: string | null): HostPlatform {
const value = environmentLabel?.toLowerCase() ?? "";
if (
Expand Down
6 changes: 1 addition & 5 deletions apps/mobile/src/features/threads/ThreadRouteScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { vcsEnvironment } from "../../state/vcs";
import { EmptyState } from "../../components/ui/EmptyState";
import { LoadingScreen } from "../../components/LoadingScreen";
import { scopedThreadKey } from "../../lib/scopedEntities";
import { firstRouteParam } from "../../lib/routeParams";
import { scopeThreadRef } from "@t3tools/client-runtime/environment";
import { useThreadShell } from "../../state/entities";
import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../../native/native-glass";
Expand Down Expand Up @@ -125,11 +126,6 @@ import { useStartSideChat } from "./useStartSideChat";
import type { ThreadInspectorMode, ThreadInspectorTarget } from "./thread-inspector-navigation";
import { useSelectWorkspaceDetail } from "../layout/workspace/useSelectWorkspaceDetail";

function firstRouteParam(value: string | string[] | undefined): string | null {
const first = Array.isArray(value) ? value[0] : value;
return first === undefined || first.trim().length === 0 ? null : first;
}

// The inspector pane's bar belongs to ThreadInspectorHeader; the fallback must not draw its own.
const InspectorHeaderShownContext = createContext(false);

Expand Down
5 changes: 5 additions & 0 deletions apps/mobile/src/lib/routeParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** Blank counts as missing; a present value is returned untrimmed. */
export function firstRouteParam(value: string | string[] | undefined): string | null {
const first = Array.isArray(value) ? value[0] : value;
return first === undefined || first.trim().length === 0 ? null : first;
}
6 changes: 1 addition & 5 deletions apps/mobile/src/state/use-thread-selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
import * as Option from "effect/Option";

import { scopedThreadKey } from "../lib/scopedEntities";
import { firstRouteParam } from "../lib/routeParams";
import { useProject, useQuietThreadShell } from "./entities";
import { useEnvironmentThread } from "./threads";
import {
Expand All @@ -39,11 +40,6 @@ type ThreadSelectionRouteParams = {
readonly threadId?: string | string[];
};

function firstRouteParam(value: string | string[] | undefined): string | null {
const first = Array.isArray(value) ? value[0] : value;
return first === undefined || first.trim().length === 0 ? null : first;
}

function latestUserMessageAt(
projection: OrchestrationV2ThreadProjection,
): OrchestrationV2ThreadShell["latestUserMessageAt"] {
Expand Down
Loading