Skip to content
Merged
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
63 changes: 60 additions & 3 deletions apps/mobile/src/features/threads/NewTaskRouteScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ import {
} from "@react-navigation/native";
import { SymbolView } from "../../components/AppSymbol";
import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell";
import { useEffect, useRef } from "react";
import { ActivityIndicator, Alert, Platform, Pressable, ScrollView, View } from "react-native";
import { useEffect, useRef, useState } from "react";
import {
ActivityIndicator,
Alert,
Platform,
Pressable,
ScrollView,
TextInput,
View,
} from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { cn } from "../../lib/cn";

Expand All @@ -22,6 +30,7 @@ import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
import { useIncomingShare } from "../sharing/IncomingShareProvider";
import { useNewTaskFlow } from "./new-task-flow-provider";
import {
filterProjectScopes,
getProjectScopeAccessibilityLabel,
getProjectScopeSelectionTarget,
} from "./new-task-project-selection";
Expand Down Expand Up @@ -87,6 +96,7 @@ function deriveProjectEmptyState(catalogState: WorkspaceState): {

export function NewTaskRouteScreen({ route }: StaticScreenProps<NewTaskRouteParams | undefined>) {
const projects = useProjects();
const [searchText, setSearchText] = useState("");
const { projectScopes, selectedEnvironmentId, setProject } = useNewTaskFlow();
const { state: catalogState } = useWorkspaceState();
const navigation = useNavigation();
Expand All @@ -107,6 +117,7 @@ export function NewTaskRouteScreen({ route }: StaticScreenProps<NewTaskRoutePara
: null;
const screenTitle = incomingShare ? "Start a task" : "Choose project";
const projectEmptyState = deriveProjectEmptyState(catalogState);
const visibleScopes = filterProjectScopes(projectScopes, searchText);
const resumedDestinationKeyRef = useRef<string | null>(null);
const reservedDestinationProject = incomingShare?.destination
? (projects.find(
Expand Down Expand Up @@ -230,9 +241,46 @@ export function NewTaskRouteScreen({ route }: StaticScreenProps<NewTaskRoutePara
</>
)}

<View className="px-5 pb-2 pt-3">
<View className="min-h-12 flex-row items-center gap-2.5 rounded-2xl border border-input-border bg-input px-3.5">
<SymbolView
name="magnifyingglass"
size={17}
tintColorClassName="accent-foreground-muted"
type="monochrome"
/>
<TextInput
accessibilityLabel="Search projects"
autoCapitalize="none"
autoCorrect={false}
className="flex-1 py-2.5 text-base font-sans text-foreground"
onChangeText={setSearchText}
placeholder="Search projects"
placeholderTextColorClassName="accent-placeholder"
value={searchText}
/>
{searchText.length > 0 ? (
<Pressable
accessibilityLabel="Clear search"
hitSlop={10}
onPress={() => setSearchText("")}
>
<SymbolView
name="xmark.circle.fill"
size={17}
tintColorClassName="accent-foreground-muted"
type="monochrome"
/>
</Pressable>
) : null}
</View>
</View>

<ScrollView
contentInsetAdjustmentBehavior="automatic"
showsVerticalScrollIndicator={false}
keyboardShouldPersistTaps="handled"
keyboardDismissMode="on-drag"
className="flex-1"
contentContainerStyle={{
gap: 12,
Expand Down Expand Up @@ -274,9 +322,18 @@ export function NewTaskRouteScreen({ route }: StaticScreenProps<NewTaskRoutePara
</Pressable>
)}
</View>
) : visibleScopes.length === 0 ? (
<View collapsable={false} className="items-center gap-2 rounded-[24px] bg-card px-6 py-8">
<Text className="text-center text-lg font-t3-bold text-foreground">
No matching projects
</Text>
<Text className="text-center text-sm leading-normal text-foreground-muted">
Try a different project name or workspace path.
</Text>
</View>
) : (
<View collapsable={false} className="overflow-hidden rounded-[24px] bg-card">
{projectScopes.map((scope, scopeIndex) => {
{visibleScopes.map((scope, scopeIndex) => {
const hasMultipleProjects = scope.projects.length > 1;
const selectionTarget = getProjectScopeSelectionTarget(scope, selectedEnvironmentId);
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,43 @@ import { describe, expect, it } from "vite-plus/test";
import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell";
import type { HomeProjectScope } from "../home/homeThreadList";
import {
filterProjectScopes,
getProjectScopeAccessibilityLabel,
getProjectScopeSelectionTarget,
resolveDraftProjectSelection,
resolveEnvironmentProjectMatch,
} from "./new-task-project-selection";

describe("filterProjectScopes", () => {
const local = makeProject("code", "mac", { title: "Desktop checkout" });
const remote = makeProject("remote-code", "server", {
workspaceRoot: "/srv/remote-workspace",
});
const code = makeScope([local, remote]);
const docs = { ...makeScope([makeProject("docs")]), key: "docs", title: "Documentation" };
const scopes = [code, docs];

it("keeps all scopes for an empty or whitespace query", () => {
expect(filterProjectScopes(scopes, "")).toBe(scopes);
expect(filterProjectScopes(scopes, " ")).toBe(scopes);
});

it("finds logical names, project titles and workspace paths without case sensitivity", () => {
expect(filterProjectScopes(scopes, " T3 CODE ")).toEqual([code]);
expect(filterProjectScopes(scopes, "DESKTOP")).toEqual([code]);
expect(filterProjectScopes(scopes, "REMOTE-WORKSPACE")).toEqual([code]);
expect(filterProjectScopes(scopes, "documentation")).toEqual([docs]);
expect(filterProjectScopes(scopes, "missing-project")).toEqual([]);
});

it("keeps every workspace and the preferred environment when one workspace matches", () => {
const matches = filterProjectScopes(scopes, "REMOTE-WORKSPACE");
expect(matches[0]).toBe(code);
expect(getProjectScopeSelectionTarget(matches[0]!, EnvironmentId.make("mac"))).toBe(local);
expect(code.projects).toEqual([local, remote]);
});
});

function makeProject(
id: string,
environmentId = "environment",
Expand Down
17 changes: 17 additions & 0 deletions apps/mobile/src/features/threads/new-task-project-selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ export function getProjectScopeAccessibilityLabel(
: `${scope.title}, ${selectionTarget.workspaceRoot}`;
}

export function filterProjectScopes(
scopes: ReadonlyArray<HomeProjectScope>,
searchText: string,
): ReadonlyArray<HomeProjectScope> {
const query = searchText.trim().toLowerCase();
if (!query) return scopes;
return scopes.filter(
(scope) =>
scope.title.toLowerCase().includes(query) ||
scope.projects.some(
(project) =>
project.title.toLowerCase().includes(query) ||
project.workspaceRoot.toLowerCase().includes(query),
),
);
}

function getOnlySelectableProject(
projectScopes: ReadonlyArray<HomeProjectScope>,
): EnvironmentProject | null {
Expand Down
Loading