Skip to content

Commit 301531f

Browse files
committed
fix(search): address review findings on thread search qualifiers
- quoted tokens are always text; queries without qualifiers pass through unchanged - one token classifier for parse, toggle, and clear; quoted commas stay one value - drop the in: alias; project: matches title, folder name, and grouped label - palettes filter by qualifiers without rebuilding items on every keystroke - qualifiers apply only to root thread search, not submenus or > actions - archived results are read-only on mobile and open the archive screen everywhere - one-predicate server change; MCP thread search schema unchanged
1 parent f84a524 commit 301531f

21 files changed

Lines changed: 798 additions & 575 deletions

‎apps/mobile/src/features/home/HomeScreen.tsx‎

Lines changed: 66 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ import {
5252
import { useThreadRowProviderInstanceResolver } from "../threads/thread-provider-instance";
5353
import {
5454
buildThreadListV2Items,
55-
createMobileThreadSearchContext,
55+
getMobileThreadSearchEnvironmentNames,
56+
useMobileThreadSearchContext,
5657
getThreadListV2OrderedSection,
5758
buildThreadListV2ListItems,
5859
threadListV2ListItemsAreEqual,
5960
threadListInboxReturns,
6061
THREAD_LIST_V2_SETTLED_INITIAL_COUNT,
6162
THREAD_LIST_V2_SETTLED_PAGE_COUNT,
6263
type ThreadListV2ListItem,
63-
sortThreadsByActivity,
6464
} from "../threads/threadListV2";
6565
import { useThreadListV2ShelfPreferences } from "../threads/use-thread-list-v2-shelf-preferences";
6666
import type { HomeListFilterMenuEnvironment } from "./home-list-filter-menu";
@@ -260,10 +260,8 @@ export function HomeScreen(props: HomeScreenProps) {
260260
const searchableThreads = useMemo(
261261
() =>
262262
parsedSearch.filters.archived
263-
? sortThreadsByActivity(
264-
archivedSnapshots.snapshots.flatMap(({ environmentId, snapshot }) =>
265-
snapshot.threads.map((thread) => presentThreadShell(environmentId, thread)),
266-
),
263+
? archivedSnapshots.snapshots.flatMap(({ environmentId, snapshot }) =>
264+
snapshot.threads.map((thread) => presentThreadShell(environmentId, thread)),
267265
)
268266
: props.threads,
269267
[archivedSnapshots.snapshots, parsedSearch.filters.archived, props.threads],
@@ -531,22 +529,26 @@ export function HomeScreen(props: HomeScreenProps) {
531529
} = listEnvironments;
532530
const resolveProviderInstance = useThreadRowProviderInstanceResolver(providersByEnvironmentId);
533531
const pendingOrder = usePendingThreadOrder(nowMinute, snoozeWakeTick);
534-
const threadSearchContext = useMemo(
532+
const environmentNames = useMemo(
535533
() =>
536-
createMobileThreadSearchContext({
537-
projects: projectByKey,
538-
providers: providersByEnvironmentId,
539-
environmentNames: (thread) =>
540-
[
541-
props.environments.find(
542-
(environment) => environment.environmentId === thread.environmentId,
543-
)?.label,
544-
props.savedConnectionsById[thread.environmentId]?.environmentLabel,
545-
thread.environmentId,
546-
].filter((name): name is string => name !== undefined),
547-
}),
548-
[projectByKey, props.environments, props.savedConnectionsById, providersByEnvironmentId],
534+
new Map(
535+
props.environments.map((environment) => [
536+
environment.environmentId,
537+
getMobileThreadSearchEnvironmentNames({
538+
environmentId: environment.environmentId,
539+
workspaceLabel: environment.label,
540+
savedConnectionLabel:
541+
props.savedConnectionsById[environment.environmentId]?.environmentLabel,
542+
}),
543+
]),
544+
),
545+
[props.environments, props.savedConnectionsById],
549546
);
547+
const threadSearchContext = useMobileThreadSearchContext({
548+
projects: projectByKey,
549+
providers: providersByEnvironmentId,
550+
environmentNames,
551+
});
550552
// Up/down menu availability for every card, computed once per section per
551553
// rebuild (see computeThreadMoveAvailability): per-thread planner calls made
552554
// list construction quadratic, and this list rebuilds on every minute tick.
@@ -590,15 +592,11 @@ export function HomeScreen(props: HomeScreenProps) {
590592
// Archive searches use the snapshot instead of the live shells.
591593
return buildThreadListV2Items({
592594
pendingOrder,
593-
threads: searchableThreads.filter(
594-
(thread) => parsedSearch.filters.archived || thread.archivedAt === null,
595-
),
595+
threads: searchableThreads,
596596
environmentId: props.selectedEnvironmentId,
597597
projectRefs: v2ScopedProjectGroup === null ? null : v2ScopedProjectGroup.projectRefs,
598-
searchQuery: parsedSearch.text,
599-
searchFilters: parsedSearch.filters,
598+
parsedSearch,
600599
searchFilterContext: threadSearchContext,
601-
searchNow: new Date(),
602600
matchedThreadKeys,
603601
settlementEnvironmentIds,
604602
snoozeEnvironmentIds,
@@ -653,18 +651,26 @@ export function HomeScreen(props: HomeScreenProps) {
653651
const v2SearchQuery = parsedSearch.text.trim().toLocaleLowerCase();
654652
const v2PendingTasks = useMemo(
655653
() =>
656-
props.pendingTasks.filter(
657-
(pendingTask) =>
658-
(props.selectedEnvironmentId === null ||
659-
pendingTask.environmentId === props.selectedEnvironmentId) &&
660-
(v2ScopedProjectKeys === null ||
661-
v2ScopedProjectKeys.has(
662-
scopedProjectKey(pendingTask.environmentId, pendingTask.projectId),
663-
)) &&
664-
(v2SearchQuery.length === 0 ||
665-
pendingTask.title.toLocaleLowerCase().includes(v2SearchQuery)),
666-
),
667-
[props.pendingTasks, props.selectedEnvironmentId, v2ScopedProjectKeys, v2SearchQuery],
654+
parsedSearch.hasFilters
655+
? []
656+
: props.pendingTasks.filter(
657+
(pendingTask) =>
658+
(props.selectedEnvironmentId === null ||
659+
pendingTask.environmentId === props.selectedEnvironmentId) &&
660+
(v2ScopedProjectKeys === null ||
661+
v2ScopedProjectKeys.has(
662+
scopedProjectKey(pendingTask.environmentId, pendingTask.projectId),
663+
)) &&
664+
(v2SearchQuery.length === 0 ||
665+
pendingTask.title.toLocaleLowerCase().includes(v2SearchQuery)),
666+
),
667+
[
668+
parsedSearch.hasFilters,
669+
props.pendingTasks,
670+
props.selectedEnvironmentId,
671+
v2ScopedProjectKeys,
672+
v2SearchQuery,
673+
],
668674
);
669675
const threadListV2Items = useMemo(
670676
() =>
@@ -770,6 +776,7 @@ export function HomeScreen(props: HomeScreenProps) {
770776
hasQueuedMessages={item.hasQueuedMessages}
771777
snoozed={item.item.snoozed}
772778
pinned={item.item.pinned}
779+
readOnly={item.item.readOnly}
773780
snoozePresetMinute={item.snoozePresetMinute ?? ""}
774781
snoozeWakeLabelText={item.snoozeWakeLabelText}
775782
timeLabel={item.timeLabel}
@@ -900,8 +907,11 @@ export function HomeScreen(props: HomeScreenProps) {
900907
// that matches nothing needs the in-list "No results" state, not the
901908
// full-page "No threads yet". Settled threads are unarchived live shells,
902909
// so the archived-at check already covers the settled shelf.
903-
const hasAnyThreads =
904-
props.threads.some((thread) => thread.archivedAt === null) || props.pendingTasks.length > 0;
910+
const hasAnyThreads = parsedSearch.filters.archived
911+
? searchableThreads.length > 0 ||
912+
archivedSnapshots.isLoading ||
913+
archivedSnapshots.error !== null
914+
: props.threads.some((thread) => thread.archivedAt === null) || props.pendingTasks.length > 0;
905915
const selectedEnvironmentLabel =
906916
props.selectedEnvironmentId === null
907917
? null
@@ -967,10 +977,23 @@ export function HomeScreen(props: HomeScreenProps) {
967977
// Use the v2 project scope for its empty state. Snoozed threads need no
968978
// special empty state: their shelf header is a list row even while collapsed.
969979
const v2ListEmpty =
970-
hasSearchQuery && threadSearch.isPending ? undefined : hasSearchQuery ? (
980+
hasSearchQuery &&
981+
(threadSearch.isPending || (parsedSearch.filters.archived && archivedSnapshots.isLoading)) ? (
971982
<EmptyState
972-
title="No results"
973-
detail={`No threads matching "${props.searchQuery}".`}
983+
title="Searching…"
984+
detail="Searching thread messages…"
985+
variant={Platform.OS === "android" ? "plain" : undefined}
986+
/>
987+
) : hasSearchQuery ? (
988+
<EmptyState
989+
title={
990+
parsedSearch.filters.archived && archivedSnapshots.error ? "Search failed" : "No results"
991+
}
992+
detail={
993+
parsedSearch.filters.archived && archivedSnapshots.error
994+
? archivedSnapshots.error
995+
: `No threads matching "${props.searchQuery}".`
996+
}
974997
variant={Platform.OS === "android" ? "plain" : undefined}
975998
/>
976999
) : v2ScopedProjectGroup !== null ? (

0 commit comments

Comments
 (0)