@@ -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 ,
@@ -27,6 +31,7 @@ import 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" ;
@@ -189,6 +194,27 @@ export function HomeScreen(props: HomeScreenProps) {
189194 const listRef = useRef < LegendListRef | null > ( null ) ;
190195 const insets = useSafeAreaInsets ( ) ;
191196 const accentColor = useThemeColor ( "--color-icon-muted" ) ;
197+ const searchEnvironmentIds = useMemo (
198+ ( ) =>
199+ props . selectedEnvironmentId === null
200+ ? props . environments . map ( ( environment ) => environment . environmentId )
201+ : [ props . selectedEnvironmentId ] ,
202+ [ props . environments , props . selectedEnvironmentId ] ,
203+ ) ;
204+ const threadSearch = useThreadSearch ( searchEnvironmentIds , props . searchQuery ) ;
205+ const threadSearchMatchByKey = useMemo ( ( ) => {
206+ const matches = new Map < string , EnvironmentThreadSearchMatch > ( ) ;
207+ for ( const match of threadSearch . matches ) {
208+ if ( match . source === "user" || match . source === "assistant" ) {
209+ matches . set ( threadSearchMatchKey ( match ) , match ) ;
210+ }
211+ }
212+ return matches ;
213+ } , [ threadSearch . matches ] ) ;
214+ const matchedThreadKeys = useMemo (
215+ ( ) => new Set ( threadSearch . matches . map ( threadSearchMatchKey ) ) ,
216+ [ threadSearch . matches ] ,
217+ ) ;
192218 const effectiveGroupDisplayStates = useMemo ( ( ) => {
193219 const next = new Map ( groupDisplayStates ) ;
194220 if ( ! AsyncResult . isSuccess ( preferencesResult ) ) {
@@ -318,6 +344,7 @@ export function HomeScreen(props: HomeScreenProps) {
318344 pendingTasks : scopedPendingTasks ,
319345 environmentId : props . selectedEnvironmentId ,
320346 searchQuery : props . searchQuery ,
347+ matchedThreadKeys,
321348 projectSortOrder : props . projectSortOrder ,
322349 threadSortOrder : props . threadSortOrder ,
323350 projectGroupingMode : props . projectGroupingMode ,
@@ -328,6 +355,7 @@ export function HomeScreen(props: HomeScreenProps) {
328355 props . searchQuery ,
329356 props . selectedEnvironmentId ,
330357 props . threadSortOrder ,
358+ matchedThreadKeys ,
331359 scopedPendingTasks ,
332360 scopedProjects ,
333361 scopedThreads ,
@@ -516,6 +544,7 @@ export function HomeScreen(props: HomeScreenProps) {
516544 environmentId : props . selectedEnvironmentId ,
517545 projectRefs : v2ScopedProjectGroup === null ? null : v2ScopedProjectGroup . projectRefs ,
518546 searchQuery : props . searchQuery ,
547+ matchedThreadKeys,
519548 changeRequestStateByKey,
520549 settlementEnvironmentIds,
521550 snoozeEnvironmentIds,
@@ -533,6 +562,7 @@ export function HomeScreen(props: HomeScreenProps) {
533562 props . searchQuery ,
534563 props . selectedEnvironmentId ,
535564 props . threads ,
565+ matchedThreadKeys ,
536566 threadListV2Enabled ,
537567 v2ScopedProjectGroup ,
538568 ] ) ;
@@ -629,6 +659,13 @@ export function HomeScreen(props: HomeScreenProps) {
629659 ? ( props . savedConnectionsById [ thread . environmentId ] ?. environmentLabel ?? null )
630660 : null
631661 }
662+ searchMatch = { threadSearchMatchByKey . get (
663+ threadSearchMatchKey ( {
664+ environmentId : thread . environmentId ,
665+ threadId : thread . id ,
666+ } ) ,
667+ ) }
668+ searchQuery = { props . searchQuery }
632669 onSelectThread = { props . onSelectThread }
633670 onDeleteThread = { handleDeleteThread }
634671 onArchiveThread = { props . onArchiveThread }
@@ -660,7 +697,9 @@ export function HomeScreen(props: HomeScreenProps) {
660697 props . savedConnectionsById ,
661698 serverConfigs ,
662699 settlementEnvironmentIds ,
700+ threadSearchMatchByKey ,
663701 v2ProjectTitleByProjectKey ,
702+ props . searchQuery ,
664703 ] ,
665704 ) ;
666705 const v2KeyExtractor = useCallback ( ( item : ThreadListV2ListItem ) => item . key , [ ] ) ;
@@ -675,12 +714,14 @@ export function HomeScreen(props: HomeScreenProps) {
675714 projectTitleByProjectKey : v2ProjectTitleByProjectKey ,
676715 serverConfigs,
677716 savedConnectionsById : props . savedConnectionsById ,
717+ threadSearchMatchByKey,
678718 } ) ,
679719 [
680720 projectByKey ,
681721 projectCwdByKey ,
682722 props . savedConnectionsById ,
683723 serverConfigs ,
724+ threadSearchMatchByKey ,
684725 v2ProjectTitleByProjectKey ,
685726 ] ,
686727 ) ;
@@ -740,6 +781,13 @@ export function HomeScreen(props: HomeScreenProps) {
740781 null
741782 }
742783 isLast = { item . isLast }
784+ searchMatch = { threadSearchMatchByKey . get (
785+ threadSearchMatchKey ( {
786+ environmentId : thread . environmentId ,
787+ threadId : thread . id ,
788+ } ) ,
789+ ) }
790+ searchQuery = { props . searchQuery }
743791 onArchiveThread = { props . onArchiveThread }
744792 onDeleteThread = { props . onDeleteThread }
745793 onSelectThread = { props . onSelectThread }
@@ -770,7 +818,9 @@ export function HomeScreen(props: HomeScreenProps) {
770818 props . onNewThreadInProject ,
771819 props . onSelectPendingTask ,
772820 props . onSelectThread ,
821+ props . searchQuery ,
773822 props . savedConnectionsById ,
823+ threadSearchMatchByKey ,
774824 updateGroupDisplay ,
775825 ] ,
776826 ) ;
0 commit comments