@@ -7,6 +7,10 @@ import {
77 type EnvironmentProject ,
88 type EnvironmentThreadShell ,
99} from "@t3tools/client-runtime/state/shell" ;
10+ import {
11+ threadSearchMatchKey ,
12+ type EnvironmentThreadSearchMatch ,
13+ } from "@t3tools/client-runtime/state/thread-search" ;
1014import type {
1115 EnvironmentId ,
1216 SidebarProjectGroupingMode ,
@@ -22,11 +26,12 @@ import { useThemeColor } from "../../lib/useThemeColor";
2226
2327import { AppText as Text } from "../../components/AppText" ;
2428import { EmptyState } from "../../components/EmptyState" ;
25- import type { WorkspaceState } from "../../state/workspaceModel" ;
29+ import type { WorkspaceEnvironment , WorkspaceState } from "../../state/workspaceModel" ;
2630import type { SavedRemoteConnection } from "../../lib/connection" ;
2731import { scopedProjectKey } from "../../lib/scopedEntities" ;
2832import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../../native/native-glass" ;
2933import { mobilePreferencesAtom , updateMobilePreferencesAtom } from "../../state/preferences" ;
34+ import { useThreadSearch } from "../../state/queries" ;
3035import { useThreadListV2Enabled } from "../threads/use-thread-list-v2-enabled" ;
3136import { environmentServerConfigsAtom } from "../../state/server" ;
3237import type { PendingNewTask } from "../../state/use-pending-new-tasks" ;
@@ -72,7 +77,9 @@ interface HomeScreenProps {
7277 readonly pendingTasks : ReadonlyArray < PendingNewTask > ;
7378 readonly catalogState : WorkspaceState ;
7479 readonly savedConnectionsById : Readonly < Record < string , SavedRemoteConnection > > ;
75- readonly environments : ReadonlyArray < HomeListFilterMenuEnvironment > ;
80+ readonly environments : ReadonlyArray <
81+ HomeListFilterMenuEnvironment & Pick < WorkspaceEnvironment , "connectionState" >
82+ > ;
7683 readonly searchQuery : string ;
7784 readonly selectedEnvironmentId : EnvironmentId | null ;
7885 readonly selectedProjectKey : string | null ;
@@ -189,6 +196,35 @@ export function HomeScreen(props: HomeScreenProps) {
189196 const listRef = useRef < LegendListRef | null > ( null ) ;
190197 const insets = useSafeAreaInsets ( ) ;
191198 const accentColor = useThemeColor ( "--color-icon-muted" ) ;
199+ const searchEnvironmentIds = useMemo (
200+ ( ) =>
201+ props . selectedEnvironmentId === null
202+ ? props . environments
203+ . filter ( ( environment ) => environment . connectionState === "connected" )
204+ . map ( ( environment ) => environment . environmentId )
205+ : props . environments . some (
206+ ( environment ) =>
207+ environment . environmentId === props . selectedEnvironmentId &&
208+ environment . connectionState === "connected" ,
209+ )
210+ ? [ props . selectedEnvironmentId ]
211+ : [ ] ,
212+ [ props . environments , props . selectedEnvironmentId ] ,
213+ ) ;
214+ const threadSearch = useThreadSearch ( searchEnvironmentIds , props . searchQuery ) ;
215+ const threadSearchMatchByKey = useMemo ( ( ) => {
216+ const matches = new Map < string , EnvironmentThreadSearchMatch > ( ) ;
217+ for ( const match of threadSearch . matches ) {
218+ if ( match . source === "user" || match . source === "assistant" ) {
219+ matches . set ( threadSearchMatchKey ( match ) , match ) ;
220+ }
221+ }
222+ return matches ;
223+ } , [ threadSearch . matches ] ) ;
224+ const matchedThreadKeys = useMemo (
225+ ( ) => new Set ( threadSearch . matches . map ( threadSearchMatchKey ) ) ,
226+ [ threadSearch . matches ] ,
227+ ) ;
192228 const effectiveGroupDisplayStates = useMemo ( ( ) => {
193229 const next = new Map ( groupDisplayStates ) ;
194230 if ( ! AsyncResult . isSuccess ( preferencesResult ) ) {
@@ -318,6 +354,7 @@ export function HomeScreen(props: HomeScreenProps) {
318354 pendingTasks : scopedPendingTasks ,
319355 environmentId : props . selectedEnvironmentId ,
320356 searchQuery : props . searchQuery ,
357+ matchedThreadKeys,
321358 projectSortOrder : props . projectSortOrder ,
322359 threadSortOrder : props . threadSortOrder ,
323360 projectGroupingMode : props . projectGroupingMode ,
@@ -328,6 +365,7 @@ export function HomeScreen(props: HomeScreenProps) {
328365 props . searchQuery ,
329366 props . selectedEnvironmentId ,
330367 props . threadSortOrder ,
368+ matchedThreadKeys ,
331369 scopedPendingTasks ,
332370 scopedProjects ,
333371 scopedThreads ,
@@ -516,6 +554,7 @@ export function HomeScreen(props: HomeScreenProps) {
516554 environmentId : props . selectedEnvironmentId ,
517555 projectRefs : v2ScopedProjectGroup === null ? null : v2ScopedProjectGroup . projectRefs ,
518556 searchQuery : props . searchQuery ,
557+ matchedThreadKeys,
519558 changeRequestStateByKey,
520559 settlementEnvironmentIds,
521560 snoozeEnvironmentIds,
@@ -533,6 +572,7 @@ export function HomeScreen(props: HomeScreenProps) {
533572 props . searchQuery ,
534573 props . selectedEnvironmentId ,
535574 props . threads ,
575+ matchedThreadKeys ,
536576 threadListV2Enabled ,
537577 v2ScopedProjectGroup ,
538578 ] ) ;
@@ -629,6 +669,13 @@ export function HomeScreen(props: HomeScreenProps) {
629669 ? ( props . savedConnectionsById [ thread . environmentId ] ?. environmentLabel ?? null )
630670 : null
631671 }
672+ searchMatch = { threadSearchMatchByKey . get (
673+ threadSearchMatchKey ( {
674+ environmentId : thread . environmentId ,
675+ threadId : thread . id ,
676+ } ) ,
677+ ) }
678+ searchQuery = { props . searchQuery }
632679 onSelectThread = { props . onSelectThread }
633680 onDeleteThread = { handleDeleteThread }
634681 onArchiveThread = { props . onArchiveThread }
@@ -660,7 +707,9 @@ export function HomeScreen(props: HomeScreenProps) {
660707 props . savedConnectionsById ,
661708 serverConfigs ,
662709 settlementEnvironmentIds ,
710+ threadSearchMatchByKey ,
663711 v2ProjectTitleByProjectKey ,
712+ props . searchQuery ,
664713 ] ,
665714 ) ;
666715 const v2KeyExtractor = useCallback ( ( item : ThreadListV2ListItem ) => item . key , [ ] ) ;
@@ -675,19 +724,28 @@ export function HomeScreen(props: HomeScreenProps) {
675724 projectTitleByProjectKey : v2ProjectTitleByProjectKey ,
676725 serverConfigs,
677726 savedConnectionsById : props . savedConnectionsById ,
727+ searchQuery : props . searchQuery ,
728+ threadSearchMatchByKey,
678729 } ) ,
679730 [
680731 projectByKey ,
681732 projectCwdByKey ,
733+ props . searchQuery ,
682734 props . savedConnectionsById ,
683735 serverConfigs ,
736+ threadSearchMatchByKey ,
684737 v2ProjectTitleByProjectKey ,
685738 ] ,
686739 ) ;
687740
688741 const extraData = useMemo (
689- ( ) => ( { savedConnectionsById : props . savedConnectionsById , projectCwdByKey } ) ,
690- [ props . savedConnectionsById , projectCwdByKey ] ,
742+ ( ) => ( {
743+ projectCwdByKey,
744+ savedConnectionsById : props . savedConnectionsById ,
745+ searchQuery : props . searchQuery ,
746+ threadSearchMatchByKey,
747+ } ) ,
748+ [ projectCwdByKey , props . savedConnectionsById , props . searchQuery , threadSearchMatchByKey ] ,
691749 ) ;
692750
693751 const renderItem = useCallback (
@@ -740,6 +798,13 @@ export function HomeScreen(props: HomeScreenProps) {
740798 null
741799 }
742800 isLast = { item . isLast }
801+ searchMatch = { threadSearchMatchByKey . get (
802+ threadSearchMatchKey ( {
803+ environmentId : thread . environmentId ,
804+ threadId : thread . id ,
805+ } ) ,
806+ ) }
807+ searchQuery = { props . searchQuery }
743808 onArchiveThread = { props . onArchiveThread }
744809 onDeleteThread = { props . onDeleteThread }
745810 onSelectThread = { props . onSelectThread }
@@ -770,7 +835,9 @@ export function HomeScreen(props: HomeScreenProps) {
770835 props . onNewThreadInProject ,
771836 props . onSelectPendingTask ,
772837 props . onSelectThread ,
838+ props . searchQuery ,
773839 props . savedConnectionsById ,
840+ threadSearchMatchByKey ,
774841 updateGroupDisplay ,
775842 ] ,
776843 ) ;
@@ -863,7 +930,7 @@ export function HomeScreen(props: HomeScreenProps) {
863930 const v2ListHeader = listHeader ;
864931
865932 const listEmpty = ! hasResults ? (
866- hasSearchQuery ? (
933+ hasSearchQuery && threadSearch . isPending ? null : hasSearchQuery ? (
867934 < EmptyState title = "No results" detail = { `No threads matching "${ props . searchQuery } ".` } />
868935 ) : selectedProjectScope !== null ? (
869936 < EmptyState
@@ -886,31 +953,34 @@ export function HomeScreen(props: HomeScreenProps) {
886953 // threads yet" over an inbox that is merely all-snoozed reads as data
887954 // loss.
888955 const v2SnoozedCount = threadListV2Layout . snoozedCount ;
889- const v2ListEmpty = hasSearchQuery ? (
890- v2SnoozedCount > 0 ? (
891- // The snoozed threads already passed this search filter: "No
892- // results" would claim nothing matched when matches are merely
893- // parked.
956+ const v2ListEmpty =
957+ hasSearchQuery && threadSearch . isPending && v2SnoozedCount === 0 ? null : hasSearchQuery ? (
958+ v2SnoozedCount > 0 ? (
959+ // The snoozed threads already passed this search filter: "No
960+ // results" would claim nothing matched when matches are merely
961+ // parked.
962+ < EmptyState
963+ title = {
964+ v2SnoozedCount === 1 ? "1 matching thread snoozed" : `All matching threads snoozed`
965+ }
966+ detail = { `Threads matching "${ props . searchQuery } " are snoozed and return when their wake time passes.` }
967+ />
968+ ) : (
969+ < EmptyState title = "No results" detail = { `No threads matching "${ props . searchQuery } ".` } />
970+ )
971+ ) : v2SnoozedCount > 0 ? (
972+ < EmptyState
973+ title = { v2SnoozedCount === 1 ? "1 thread snoozed" : `${ v2SnoozedCount } threads snoozed` }
974+ detail = "Snoozed threads return when their wake time passes."
975+ />
976+ ) : v2ScopedProjectGroup !== null ? (
894977 < EmptyState
895- title = { v2SnoozedCount === 1 ? "1 matching thread snoozed" : `All matching threads snoozed `}
896- detail = { `Threads matching " ${ props . searchQuery } " are snoozed and return when their wake time passes.` }
978+ title = { `No threads in ${ v2ScopedProjectGroup . title } `}
979+ detail = "Choose another project or create a new task."
897980 />
898981 ) : (
899- < EmptyState title = "No results" detail = { `No threads matching "${ props . searchQuery } ".` } />
900- )
901- ) : v2SnoozedCount > 0 ? (
902- < EmptyState
903- title = { v2SnoozedCount === 1 ? "1 thread snoozed" : `${ v2SnoozedCount } threads snoozed` }
904- detail = "Snoozed threads return when their wake time passes."
905- />
906- ) : v2ScopedProjectGroup !== null ? (
907- < EmptyState
908- title = { `No threads in ${ v2ScopedProjectGroup . title } ` }
909- detail = "Choose another project or create a new task."
910- />
911- ) : (
912- listEmpty
913- ) ;
982+ listEmpty
983+ ) ;
914984
915985 if ( threadListV2Enabled ) {
916986 return (
0 commit comments