@@ -5,6 +5,7 @@ import { LegendList, type LegendListRef } from "@legendapp/list/react-native";
55import {
66 type EnvironmentProject ,
77 type EnvironmentThreadShell ,
8+ presentThreadShell ,
89} from "@t3tools/client-runtime/state/shell" ;
910import {
1011 threadSearchMatchKey ,
@@ -33,6 +34,8 @@ import type { SavedRemoteConnection } from "../../lib/connection";
3334import { scopedProjectKey } from "../../lib/scopedEntities" ;
3435import { NATIVE_LIQUID_GLASS_SUPPORTED } from "../../native/native-glass" ;
3536import { useThreadSearch } from "../../state/queries" ;
37+ import { useArchivedThreadSnapshots } from "../archive/useArchivedThreadSnapshots" ;
38+ import { parseThreadSearchQuery } from "@t3tools/client-runtime/state/threadSearchQuery" ;
3639import { useThreadJumpShortcuts } from "../keyboard/threadKeyboardShortcuts" ;
3740import { usePendingThreadOrder } from "../../state/thread-order" ;
3841import { threadListEnvironmentsAtom } from "../../state/server" ;
@@ -49,13 +52,15 @@ import {
4952import { useThreadRowProviderInstanceResolver } from "../threads/thread-provider-instance" ;
5053import {
5154 buildThreadListV2Items ,
55+ createMobileThreadSearchContext ,
5256 getThreadListV2OrderedSection ,
5357 buildThreadListV2ListItems ,
5458 threadListV2ListItemsAreEqual ,
5559 threadListInboxReturns ,
5660 THREAD_LIST_V2_SETTLED_INITIAL_COUNT ,
5761 THREAD_LIST_V2_SETTLED_PAGE_COUNT ,
5862 type ThreadListV2ListItem ,
63+ sortThreadsByActivity ,
5964} from "../threads/threadListV2" ;
6065import { useThreadListV2ShelfPreferences } from "../threads/use-thread-list-v2-shelf-preferences" ;
6166import type { HomeListFilterMenuEnvironment } from "./home-list-filter-menu" ;
@@ -222,6 +227,10 @@ function HomeTopContentSpacer() {
222227/* ─── Main screen ────────────────────────────────────────────────────── */
223228
224229export function HomeScreen ( props : HomeScreenProps ) {
230+ const parsedSearch = useMemo (
231+ ( ) => parseThreadSearchQuery ( props . searchQuery , { now : new Date ( ) } ) ,
232+ [ props . searchQuery ] ,
233+ ) ;
225234 const queuedThreadKeys = useQueuedThreadKeys ( ) ;
226235 const openSwipeableRef = useRef < SwipeableMethods | null > ( null ) ;
227236 const insets = useSafeAreaInsets ( ) ;
@@ -245,7 +254,25 @@ export function HomeScreen(props: HomeScreenProps) {
245254 : [ ] ,
246255 [ props . environments , props . selectedEnvironmentId ] ,
247256 ) ;
248- const threadSearch = useThreadSearch ( searchEnvironmentIds , props . searchQuery ) ;
257+ const archivedSnapshots = useArchivedThreadSnapshots (
258+ parsedSearch . filters . archived ? searchEnvironmentIds : [ ] ,
259+ ) ;
260+ const searchableThreads = useMemo (
261+ ( ) =>
262+ parsedSearch . filters . archived
263+ ? sortThreadsByActivity (
264+ archivedSnapshots . snapshots . flatMap ( ( { environmentId, snapshot } ) =>
265+ snapshot . threads . map ( ( thread ) => presentThreadShell ( environmentId , thread ) ) ,
266+ ) ,
267+ )
268+ : props . threads ,
269+ [ archivedSnapshots . snapshots , parsedSearch . filters . archived , props . threads ] ,
270+ ) ;
271+ const threadSearch = useThreadSearch (
272+ searchEnvironmentIds ,
273+ parsedSearch . text ,
274+ parsedSearch . filters . archived ,
275+ ) ;
249276 const threadSearchMatchByKey = useMemo ( ( ) => {
250277 const matches = new Map < string , EnvironmentThreadSearchMatch > ( ) ;
251278 for ( const match of threadSearch . matches ) {
@@ -504,6 +531,22 @@ export function HomeScreen(props: HomeScreenProps) {
504531 } = listEnvironments ;
505532 const resolveProviderInstance = useThreadRowProviderInstanceResolver ( providersByEnvironmentId ) ;
506533 const pendingOrder = usePendingThreadOrder ( nowMinute , snoozeWakeTick ) ;
534+ const threadSearchContext = useMemo (
535+ ( ) =>
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 ] ,
549+ ) ;
507550 // Up/down menu availability for every card, computed once per section per
508551 // rebuild (see computeThreadMoveAvailability): per-thread planner calls made
509552 // list construction quadratic, and this list rebuilds on every minute tick.
@@ -544,14 +587,18 @@ export function HomeScreen(props: HomeScreenProps) {
544587 ] ) ;
545588 const threadListV2Layout = useMemo ( ( ) => {
546589 threadListInboxReturns . observe ( workingShelfEnabled ? props . threads : null ) ;
547- // Settled threads are live shells; archived threads keep their original
548- // "hidden from lists" meaning.
590+ // Archive searches use the snapshot instead of the live shells.
549591 return buildThreadListV2Items ( {
550592 pendingOrder,
551- threads : props . threads . filter ( ( thread ) => thread . archivedAt === null ) ,
593+ threads : searchableThreads . filter (
594+ ( thread ) => parsedSearch . filters . archived || thread . archivedAt === null ,
595+ ) ,
552596 environmentId : props . selectedEnvironmentId ,
553597 projectRefs : v2ScopedProjectGroup === null ? null : v2ScopedProjectGroup . projectRefs ,
554- searchQuery : props . searchQuery ,
598+ searchQuery : parsedSearch . text ,
599+ searchFilters : parsedSearch . filters ,
600+ searchFilterContext : threadSearchContext ,
601+ searchNow : new Date ( ) ,
555602 matchedThreadKeys,
556603 settlementEnvironmentIds,
557604 snoozeEnvironmentIds,
@@ -577,11 +624,13 @@ export function HomeScreen(props: HomeScreenProps) {
577624 settledVisibleCount ,
578625 settlementEnvironmentIds ,
579626 snoozeEnvironmentIds ,
580- props . searchQuery ,
627+ parsedSearch ,
581628 props . selectedEnvironmentId ,
582629 props . threads ,
630+ searchableThreads ,
583631 matchedThreadKeys ,
584632 v2ScopedProjectGroup ,
633+ threadSearchContext ,
585634 ] ) ;
586635 // Re-partition the moment the earliest snooze expires (clamped to the
587636 // signed-32-bit setTimeout range; far-future wakes re-arm at the clamp).
@@ -601,7 +650,7 @@ export function HomeScreen(props: HomeScreenProps) {
601650 // they are spliced in below the active block and stay visible and deletable
602651 // while their environment is offline. Same environment scope and search
603652 // filter as the list itself.
604- const v2SearchQuery = props . searchQuery . trim ( ) . toLocaleLowerCase ( ) ;
653+ const v2SearchQuery = parsedSearch . text . trim ( ) . toLocaleLowerCase ( ) ;
605654 const v2PendingTasks = useMemo (
606655 ( ) =>
607656 props . pendingTasks . filter (
@@ -745,7 +794,7 @@ export function HomeScreen(props: HomeScreenProps) {
745794 threadId : thread . id ,
746795 } ) ,
747796 ) }
748- searchQuery = { props . searchQuery }
797+ searchQuery = { parsedSearch . text }
749798 onSelectThread = { props . onSelectThread }
750799 onDeleteThread = { handleDeleteThread }
751800 onArchiveThread = { props . onArchiveThread }
@@ -830,7 +879,7 @@ export function HomeScreen(props: HomeScreenProps) {
830879 projectTitleByProjectKey : v2ProjectTitleByProjectKey ,
831880 listEnvironments,
832881 savedConnectionsById : props . savedConnectionsById ,
833- searchQuery : props . searchQuery ,
882+ searchQuery : parsedSearch . text ,
834883 threadSearchMatchByKey,
835884 // Rows read it for their reorder menu items.
836885 workingShelfEnabled,
0 commit comments