@@ -16,6 +16,8 @@ import { SymbolView } from "../../components/ui/AppSymbol";
1616import { scopedThreadKey } from "../../lib/scopedEntities" ;
1717import { environmentServerConfigsAtom } from "../../state/server" ;
1818import { environmentThreadShells } from "../../state/threads" ;
19+ import { sortSettledThreads } from "@t3tools/client-runtime/state/thread-sort" ;
20+ import { useOlderSettledShelf , useOlderSettledShelfGrowth } from "../../state/olderSettledShelf" ;
1921import {
2022 pendingThreadOrderAtom ,
2123 threadDropBusyAtom ,
@@ -28,7 +30,12 @@ import {
2830 threadDragAction ,
2931 type ThreadMoveDestination ,
3032} from "./threadOrder" ;
31- import { getThreadListV2OrderedSection , threadListInboxReturns } from "./threadListV2" ;
33+ import {
34+ getThreadListV2OrderedSection ,
35+ THREAD_LIST_V2_SETTLED_INITIAL_COUNT ,
36+ THREAD_LIST_V2_SETTLED_PAGE_COUNT ,
37+ threadListInboxReturns ,
38+ } from "./threadListV2" ;
3239import { useThreadListV2ShelfPreferences } from "./use-thread-list-v2-shelf-preferences" ;
3340
3441const ROW_HEIGHT = 56 ;
@@ -40,6 +47,8 @@ type Row = {
4047 key : string ;
4148 section : Section ;
4249 thread ?: EnvironmentThreadShell ;
50+ /** The Settled section's "Show more" row. */
51+ more ?: true ;
4352 offset : number ;
4453 height : number ;
4554} ;
@@ -158,6 +167,15 @@ export function ThreadArrangementSheet(props: { onClose: () => void }) {
158167 const { workingShelfEnabled } = useThreadListV2ShelfPreferences ( ) ;
159168 const [ now , setNow ] = useState ( ( ) => new Date ( ) . toISOString ( ) ) ;
160169 const [ expanded , setExpanded ] = useState ( { snoozed : false , settled : false } ) ;
170+ const [ settledVisibleCount , setSettledVisibleCount ] = useState (
171+ THREAD_LIST_V2_SETTLED_INITIAL_COUNT ,
172+ ) ;
173+ // Older settled threads load in pages, as in the thread list.
174+ const olderSettledShelf = useOlderSettledShelf ( {
175+ scopes : [ ...configs . keys ( ) ] . map ( ( environmentId ) => ( { environmentId, projectIds : null } ) ) ,
176+ expanded : expanded . settled ,
177+ visibleCount : settledVisibleCount ,
178+ } ) ;
161179 useEffect ( ( ) => {
162180 const wakeAt = Math . min (
163181 ...threads . flatMap ( ( thread ) => {
@@ -201,9 +219,13 @@ export function ThreadArrangementSheet(props: { onClose: () => void }) {
201219 ? sortInboxThreadsByReturn ( active , threadListInboxReturns . returnedAt )
202220 : active ,
203221 snoozed : parked . filter ( ( thread ) => effectiveSnoozed ( thread , { now } ) ) ,
204- settled : parked . filter ( ( thread ) => ! effectiveSnoozed ( thread , { now } ) ) ,
222+ settled : sortSettledThreads ( parked . filter ( ( thread ) => ! effectiveSnoozed ( thread , { now } ) ) ) ,
205223 } ;
206224 } , [ threads , configs , now , queuedThreadKeys , pendingOrder , workingShelfEnabled ] ) ;
225+ const listedSettled = sections . settled . filter ( olderSettledShelf . isListed ) ;
226+ useOlderSettledShelfGrowth ( olderSettledShelf , listedSettled ) ;
227+ const visibleSettled = listedSettled . slice ( 0 , settledVisibleCount ) ;
228+ const settledCount = sections . settled . length + olderSettledShelf . unloadedCount ( threads ) ;
207229 const planners = useMemo ( ( ) => {
208230 const planner = ( section : "pinned" | "active" ) =>
209231 createThreadMovePlanner ( {
@@ -232,13 +254,17 @@ export function ThreadArrangementSheet(props: { onClose: () => void }) {
232254 result . push ( { key : section , section, offset, height : HEADER_HEIGHT } ) ;
233255 offset += HEADER_HEIGHT ;
234256 if ( ( section === "snoozed" || section === "settled" ) && ! expanded [ section ] ) continue ;
235- for ( const thread of sections [ section ] ) {
257+ for ( const thread of section === "settled" ? visibleSettled : sections [ section ] ) {
236258 result . push ( { key : keyOf ( thread ) , section, thread, offset, height : ROW_HEIGHT } ) ;
237259 offset += ROW_HEIGHT ;
238260 }
261+ if ( section === "settled" && settledCount > visibleSettled . length ) {
262+ result . push ( { key : "settled-more" , section, more : true , offset, height : ROW_HEIGHT } ) ;
263+ offset += ROW_HEIGHT ;
264+ }
239265 }
240266 return result ;
241- } , [ sections , expanded ] ) ;
267+ } , [ sections , expanded , visibleSettled , settledCount ] ) ;
242268 const list = useRef < FlatList < Row > > ( null ) ;
243269 const geometry = useRef ( { height : 0 , offset : 0 } ) ;
244270 const drag = useRef < Drag | null > ( null ) ;
@@ -507,6 +533,25 @@ export function ThreadArrangementSheet(props: { onClose: () => void }) {
507533 } }
508534 />
509535 </ >
536+ ) : item . more ? (
537+ < Pressable
538+ disabled = { olderSettledShelf . loading }
539+ className = "flex-1 justify-center self-stretch"
540+ onPress = { ( ) => {
541+ olderSettledShelf . retry ( ) ;
542+ setSettledVisibleCount (
543+ ( count ) => count + THREAD_LIST_V2_SETTLED_PAGE_COUNT ,
544+ ) ;
545+ } }
546+ >
547+ < Text className = "text-sm text-foreground-muted" >
548+ { olderSettledShelf . loading
549+ ? "Loading"
550+ : olderSettledShelf . failed
551+ ? "Could not load older threads. Retry"
552+ : `Show more (${ settledCount - visibleSettled . length } settled hidden)` }
553+ </ Text >
554+ </ Pressable >
510555 ) : (
511556 < Pressable
512557 disabled = { item . section === "pinned" || item . section === "active" }
@@ -519,7 +564,10 @@ export function ThreadArrangementSheet(props: { onClose: () => void }) {
519564 >
520565 < Text className = "text-sm font-t3-semibold text-foreground-muted" >
521566 { item . section [ 0 ] ! . toUpperCase ( ) + item . section . slice ( 1 ) } (
522- { sections [ item . section ] . length } )
567+ { item . section === "settled"
568+ ? settledCount
569+ : sections [ item . section ] . length }
570+ )
523571 </ Text >
524572 </ Pressable >
525573 ) }
0 commit comments