@@ -3,14 +3,15 @@ import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/model
33import {
44 isListedSettledThread ,
55 settledShelfFrontier ,
6+ sortOlderSettledScopes ,
67 unloadedOlderSettledCount ,
78 wantedOlderSettledPages ,
89 type OlderSettled ,
910 type OlderSettledScope ,
1011} from "@t3tools/client-runtime/state/threads" ;
1112import type { EnvironmentId , ProjectId } from "@t3tools/contracts" ;
1213import { Atom } from "effect/reactivity" ;
13- import { useEffect , useState } from "react" ;
14+ import { useEffect , useMemo , useState } from "react" ;
1415
1516import { appAtomRegistry } from "./atom-registry" ;
1617import { olderSettledThreads , threadFamilies } from "./threads" ;
@@ -30,10 +31,11 @@ export function useOlderSettledShelf(input: {
3031 /** Rows the shelf shows; pages are read until it lists that many. */
3132 readonly visibleCount : number ;
3233} ) {
33- const scopeKey = JSON . stringify ( input . scopes ) ;
34+ const scopes = useMemo ( ( ) => sortOlderSettledScopes ( input . scopes ) , [ input . scopes ] ) ;
35+ const scopeKey = JSON . stringify ( scopes ) ;
3436 const [ requested , setRequested ] = useState ( { scopeKey, pages : NO_PAGES } ) ;
3537 const pages = requested . scopeKey === scopeKey && input . expanded ? requested . pages : NO_PAGES ;
36- const shelfScopes = input . scopes . map ( ( scope ) => ( {
38+ const shelfScopes = scopes . map ( ( scope ) => ( {
3739 scope,
3840 pages : pages . get ( scope . environmentId ) ?? 0 ,
3941 } ) ) ;
@@ -70,7 +72,7 @@ export function useOlderSettledShelf(input: {
7072 isListed : ( thread : EnvironmentThreadShell ) => isListedSettledThread ( thread . source , frontier ) ,
7173 /** Older settled threads in scope that are not local; add it to the local Settled rows. */
7274 unloadedCount : ( threads : ReadonlyArray < EnvironmentThreadShell > ) =>
73- unloadedOlderSettledCount ( { olderSettled : olderOf , scopes : input . scopes , threads } ) ,
75+ unloadedOlderSettledCount ( { olderSettled : olderOf , scopes, threads } ) ,
7476 loading : loaded . some ( ( { scope } ) => pagesOf ( scope . environmentId ) ?. status === "pending" ) ,
7577 failed : loaded . some ( ( { scope } ) => pagesOf ( scope . environmentId ) ?. status === "failed" ) ,
7678 retry : ( ) => {
0 commit comments