@@ -2,7 +2,6 @@ import { useActiveNewTask } from "../../state/active-new-task";
22import { AppActivityIndicator } from "../../components/ui/AppActivityIndicator" ;
33import { useAndroidControlSizing } from "../../components/ui/useAndroidControlSizing" ;
44import type { ThreadMoveDestination } from "../threads/threadOrder" ;
5- import { computeThreadMoveAvailability } from "../threads/threadOrder" ;
65import type { LegendListRef } from "@legendapp/list/react-native" ;
76import { AnimatedLegendList } from "@legendapp/list/reanimated" ;
87import { THREAD_SIDEBAR_ROW_LAYOUT } from "../threads/threadListAnimations" ;
@@ -54,6 +53,7 @@ import { useNativeWorkspaceColumnsSupported } from "../../native/NativeWorkspace
5453import { useThreadSearch } from "../../state/queries" ;
5554import { requestThreadMessageJump } from "../threads/threadMessageJump" ;
5655import { useThreadListSearchMatches } from "../threads/useThreadListSearchMatches" ;
56+ import { useThreadListV2 } from "../threads/useThreadListV2" ;
5757import { useThreadJumpShortcuts } from "../keyboard/threadKeyboardShortcuts" ;
5858import { usePendingThreadOrder } from "../../state/thread-order" ;
5959import { threadListEnvironmentsAtom } from "../../state/server" ;
@@ -71,11 +71,7 @@ import { useThreadRowProviderInstanceResolver } from "../threads/thread-provider
7171import { useOpenThreadPullRequests } from "../threads/use-open-thread-pull-requests" ;
7272import type { ThreadPrPresentation } from "../../state/thread-pr-presentation" ;
7373import {
74- buildThreadListV2Items ,
75- getThreadListV2OrderedSection ,
76- buildThreadListV2ListItems ,
7774 threadListV2ListItemsAreEqual ,
78- threadListInboxReturns ,
7975 THREAD_LIST_V2_SETTLED_INITIAL_COUNT ,
8076 THREAD_LIST_V2_SETTLED_PAGE_COUNT ,
8177 type ThreadListV2ListItem ,
@@ -300,7 +296,6 @@ export function HomeScreen(props: HomeScreenProps) {
300296 : [ ] ;
301297 const threadSearch = useThreadSearch ( searchEnvironmentIds , props . searchQuery ) ;
302298 const threadSearchMatchByKey = useThreadListSearchMatches ( props . threads , threadSearch ) ;
303- const matchedThreadKeys = new Set ( threadSearchMatchByKey . keys ( ) ) ;
304299 const handleSwipeableWillOpen = ( methods : SwipeableMethods ) => {
305300 if ( openSwipeableRef . current !== methods ) {
306301 openSwipeableRef . current ?. close ( ) ;
@@ -397,14 +392,6 @@ export function HomeScreen(props: HomeScreenProps) {
397392 ) ,
398393 ) ,
399394 ) ;
400- const v2ScopedProjectKeys =
401- v2ScopedProjectGroup === null
402- ? null
403- : new Set (
404- v2ScopedProjectGroup . projectRefs . map ( ( projectRef ) =>
405- scopedProjectKey ( projectRef . environmentId , projectRef . projectId ) ,
406- ) ,
407- ) ;
408395 const handleSettleThread = props . onSettleThread ;
409396 const handleSnoozeThread = props . onSnoozeThread ;
410397 const handleUnsnoozeThread = props . onUnsnoozeThread ;
@@ -462,54 +449,32 @@ export function HomeScreen(props: HomeScreenProps) {
462449 } = listEnvironments ;
463450 const resolveProviderInstance = useThreadRowProviderInstanceResolver ( providersByEnvironmentId ) ;
464451 const pendingOrder = usePendingThreadOrder ( nowMinute , snoozeWakeTick ) ;
465- // Up/down menu availability for every card, computed once per section per
466- // rebuild (see computeThreadMoveAvailability): per-thread planner calls made
467- // list construction quadratic, and this list rebuilds on every minute tick.
468- const threadMoveAvailability = ( ( ) => {
469- const sectionAvailability = ( section : "pinned" | "active" ) =>
470- computeThreadMoveAvailability ( {
471- allThreads : props . threads ,
472- section,
473- pendingOrder,
474- reorderableEnvironmentIds :
475- section === "pinned" ? pinReorderEnvironmentIds : activeReorderEnvironmentIds ,
476- ordered : getThreadListV2OrderedSection ( {
477- threads : props . threads ,
478- section,
479- pendingOrder,
480- now,
481- settlementEnvironmentIds,
482- snoozeEnvironmentIds,
483- queuedThreadKeys,
484- } ) ,
485- } ) ;
486- return new Map ( [
487- ...sectionAvailability ( "pinned" ) ,
488- ...( workingShelfEnabled ? [ ] : sectionAvailability ( "active" ) ) ,
489- ] ) ;
490- } ) ( ) ;
491- const threadListV2Layout = ( ( ) => {
492- threadListInboxReturns . observe ( workingShelfEnabled ? props . threads : null ) ;
493- return buildThreadListV2Items ( {
494- pendingOrder,
495- threads : props . threads . filter ( ( thread ) => thread . archivedAt === null ) ,
496- environmentId : props . selectedEnvironmentId ,
497- projectRefs : v2ScopedProjectGroup === null ? null : v2ScopedProjectGroup . projectRefs ,
498- searchQuery : props . searchQuery ,
499- matchedThreadKeys,
500- settlementEnvironmentIds,
501- snoozeEnvironmentIds,
502- queuedThreadKeys,
503- settledLimit : settledVisibleCount ,
504- now,
505- workingShelfEnabled,
506- workingShelfExpanded,
507- inboxReturnAt : threadListInboxReturns . returnedAt ,
508- snoozedShelfExpanded,
509- settledShelfExpanded,
510- selectedThreadKey,
511- } ) ;
512- } ) ( ) ;
452+ const {
453+ layout : threadListV2Layout ,
454+ items : threadListV2Items ,
455+ contentOnlyThreadKeys,
456+ } = useThreadListV2 ( {
457+ threads : props . threads ,
458+ pendingTasks : props . pendingTasks ,
459+ environmentId : props . selectedEnvironmentId ,
460+ projectRefs : v2ScopedProjectGroup === null ? null : v2ScopedProjectGroup . projectRefs ,
461+ searchQuery : props . searchQuery ,
462+ searchMatches : threadSearchMatchByKey ,
463+ settlementEnvironmentIds,
464+ snoozeEnvironmentIds,
465+ pinReorderEnvironmentIds,
466+ activeReorderEnvironmentIds,
467+ queuedThreadKeys,
468+ settledLimit : settledVisibleCount ,
469+ now,
470+ pendingOrder,
471+ shelfPreferencesLoaded,
472+ workingShelfEnabled,
473+ workingShelfExpanded,
474+ snoozedShelfExpanded,
475+ settledShelfExpanded,
476+ selectedThreadKey,
477+ } ) ;
513478 const nextSnoozeWakeAt = threadListV2Layout . nextSnoozeWakeAt ;
514479 useEffect ( ( ) => {
515480 if ( nextSnoozeWakeAt === null ) return ;
@@ -525,47 +490,20 @@ export function HomeScreen(props: HomeScreenProps) {
525490 // unchanged: after a clamped fire (wake beyond the 32-bit setTimeout
526491 // range) the boundary string is identical and the chain would die.
527492 } , [ nextSnoozeWakeAt , snoozeWakeTick ] ) ;
528- const v2SearchQuery = props . searchQuery . trim ( ) . toLocaleLowerCase ( ) ;
529- const v2PendingTasks = props . pendingTasks . filter (
530- ( pendingTask ) =>
531- ( props . selectedEnvironmentId === null ||
532- pendingTask . environmentId === props . selectedEnvironmentId ) &&
533- ( v2ScopedProjectKeys === null ||
534- v2ScopedProjectKeys . has (
535- scopedProjectKey ( pendingTask . environmentId , pendingTask . projectId ) ,
536- ) ) &&
537- ( v2SearchQuery . length === 0 || pendingTask . title . toLocaleLowerCase ( ) . includes ( v2SearchQuery ) ) ,
538- ) ;
539- const threadListV2Items = buildThreadListV2ListItems ( {
540- items : threadListV2Layout . items ,
541- pendingTasks : v2PendingTasks ,
542- workingCount : threadListV2Layout . workingCount ,
543- workingShelfExpanded,
544- workingShelfHeaderIndex : threadListV2Layout . workingShelfHeaderIndex ,
545- snoozedCount : threadListV2Layout . snoozedCount ,
546- snoozedShelfExpanded,
547- snoozedShelfHeaderIndex : threadListV2Layout . snoozedShelfHeaderIndex ,
548- settledCount : threadListV2Layout . settledCount ,
549- settledShelfExpanded,
550- settledShelfHeaderIndex : threadListV2Layout . settledShelfHeaderIndex ,
551- snoozeLabelNow : `${ nowMinute } :00.000Z` ,
552- snoozeEnvironmentIds,
553- queuedThreadKeys,
554- moveAvailability : threadMoveAvailability ,
555- shelfPreferencesLoading : ! shelfPreferencesLoaded ,
556- } ) ;
557-
493+ // Called as `props.onSelectThread(...)`, the compiler would cache this handler on the whole
494+ // props object, which is new on every render of Home's parent.
495+ const { onSelectThread } = props ;
558496 // A row listed for a message match opens the thread at that message, by
559497 // tap or by shortcut.
560498 const selectThread = ( thread : EnvironmentThreadShell ) => {
561499 const key = threadSearchMatchKey ( { environmentId : thread . environmentId , threadId : thread . id } ) ;
562- const messageId = threadListV2Layout . contentOnlyThreadKeys . has ( key )
500+ const messageId = contentOnlyThreadKeys . has ( key )
563501 ? threadSearchMatchByKey . get ( key ) ?. messageId
564502 : undefined ;
565503 if ( messageId ) {
566504 requestThreadMessageJump ( scopedThreadKey ( thread . environmentId , thread . id ) , messageId ) ;
567505 }
568- props . onSelectThread ( thread ) ;
506+ onSelectThread ( thread ) ;
569507 } ;
570508 useThreadJumpShortcuts ( threadListV2Items , selectThread ) ;
571509 useEffect ( ( ) => {
@@ -670,7 +608,7 @@ export function HomeScreen(props: HomeScreenProps) {
670608 environmentMachine = { machineByEnvironmentId . get ( thread . environmentId ) }
671609 searchMatch = {
672610 // Only rows listed for their messages show one and open at it.
673- threadListV2Layout . contentOnlyThreadKeys . has (
611+ contentOnlyThreadKeys . has (
674612 threadSearchMatchKey ( { environmentId : thread . environmentId , threadId : thread . id } ) ,
675613 )
676614 ? threadSearchMatchByKey . get (
0 commit comments