@@ -219,6 +219,7 @@ import {
219219 sidebarMarkerId ,
220220 sidebarThreadKeyAtY ,
221221 countWaitingThreads ,
222+ isWaitingOnUser ,
222223 threadsWaitingOnAnswer ,
223224 orderInboxThreads ,
224225 resolveNextWaitingThread ,
@@ -868,6 +869,10 @@ function SidebarSectionHeader(props: {
868869 ) ;
869870}
870871
872+ const COLLAPSED_PROJECT_GROUPS_KEY = "t3code:sidebar:collapsed-project-groups" ;
873+ const CollapsedProjectGroups = Schema . Array ( Schema . String ) ;
874+ const EMPTY_COLLAPSED_PROJECT_GROUPS : ReadonlyArray < string > = [ ] ;
875+
871876const WAITING_COUNT_LABELS : Record < WaitingThreadKind , string > = {
872877 blocked : "need an answer" ,
873878 failed : "failed" ,
@@ -882,18 +887,36 @@ function SidebarProjectGroupHeader(props: {
882887 project : ProjectFaviconProject | null ;
883888 name : string ;
884889 count : number ;
890+ collapsed : boolean ;
891+ /** Threads of this project that wait on the user; shown while collapsed. */
892+ waitingCount : number ;
893+ onToggle : ( ) => void ;
885894} ) {
886895 return (
887- < div
896+ < button
897+ type = "button"
888898 data-testid = "sidebar-project-group-header"
889- className = "mx-0.5 flex h-6 items-center gap-1.5 px-2 pt-1 text-2xs font-medium text-muted-foreground"
899+ aria-expanded = { ! props . collapsed }
900+ onClick = { props . onToggle }
901+ className = "mx-0.5 flex h-6 w-[calc(100%-0.25rem)] cursor-pointer items-center gap-1.5 rounded-sm px-2 pt-1 text-left text-2xs font-medium text-muted-foreground hover:text-sidebar-foreground focus-visible:ring-2 focus-visible:ring-ring focus-visible:outline-none focus-visible:ring-inset"
890902 >
891903 { props . project ? (
892904 < ProjectFavicon project = { props . project } className = "size-3 shrink-0" />
893905 ) : null }
894906 < span className = "min-w-0 truncate" > { props . name } </ span >
895907 < span className = "shrink-0 tabular-nums opacity-60" > { props . count } </ span >
896- </ div >
908+ { props . collapsed ? (
909+ < span className = "ml-auto flex shrink-0 items-center gap-1.5" >
910+ { props . waitingCount > 0 ? (
911+ < span
912+ className = "size-1.5 rounded-full bg-primary"
913+ aria-label = { `${ props . waitingCount } waiting on you` }
914+ />
915+ ) : null }
916+ < span className = "opacity-60" > hidden</ span >
917+ </ span >
918+ ) : null }
919+ </ button >
897920 ) ;
898921}
899922
@@ -3126,6 +3149,21 @@ export default function Sidebar() {
31263149 ( ) => setSettledVisibleCount ( ( count ) => count + SETTLED_TAIL_PAGE_COUNT ) ,
31273150 [ ] ,
31283151 ) ;
3152+ // Project blocks the user folded away in the by-project order.
3153+ const [ collapsedProjectKeys , setCollapsedProjectKeys ] = useLocalStorage (
3154+ COLLAPSED_PROJECT_GROUPS_KEY ,
3155+ EMPTY_COLLAPSED_PROJECT_GROUPS ,
3156+ CollapsedProjectGroups ,
3157+ ) ;
3158+ const toggleProjectGroup = useCallback (
3159+ ( projectKey : string ) =>
3160+ setCollapsedProjectKeys ( ( keys ) =>
3161+ keys . includes ( projectKey )
3162+ ? keys . filter ( ( key ) => key !== projectKey )
3163+ : [ ...keys , projectKey ] ,
3164+ ) ,
3165+ [ setCollapsedProjectKeys ] ,
3166+ ) ;
31293167 const [ settledShelfExpanded , setSettledShelfExpanded ] = useLocalStorage (
31303168 SETTLED_SHELF_EXPANDED_KEY ,
31313169 false ,
@@ -5774,13 +5812,20 @@ export default function Sidebar() {
57745812 ] ;
57755813 const groupByProject = inboxOrder === "project" && from === null ;
57765814 const activeCountByProject = new Map < string , number > ( ) ;
5815+ const waitingCountByProject = new Map < string , number > ( ) ;
57775816 if ( groupByProject ) {
57785817 for ( const thread of activeThreads ) {
57795818 const projectKey = sidebarProjectPriorityKey ( thread ) ;
57805819 activeCountByProject . set (
57815820 projectKey ,
57825821 ( activeCountByProject . get ( projectKey ) ?? 0 ) + 1 ,
57835822 ) ;
5823+ if ( isWaitingOnUser ( thread ) ) {
5824+ waitingCountByProject . set (
5825+ projectKey ,
5826+ ( waitingCountByProject . get ( projectKey ) ?? 0 ) + 1 ,
5827+ ) ;
5828+ }
57845829 }
57855830 }
57865831 let lastGroupProjectKey : string | null = null ;
@@ -5798,9 +5843,18 @@ export default function Sidebar() {
57985843 project = { projectByKey . get ( projectKey ) ?? null }
57995844 name = { projectDisplayNameByKey . get ( projectKey ) ?? "No project" }
58005845 count = { activeCountByProject . get ( projectKey ) ?? 0 }
5846+ collapsed = { collapsedProjectKeys . includes ( projectKey ) }
5847+ waitingCount = { waitingCountByProject . get ( projectKey ) ?? 0 }
5848+ onToggle = { ( ) => toggleProjectGroup ( projectKey ) }
58015849 /> ,
58025850 ) ;
58035851 }
5852+ // A folded block still shows the thread that is open.
5853+ if (
5854+ collapsedProjectKeys . includes ( projectKey ) &&
5855+ item . key !== routeThreadKey
5856+ )
5857+ continue ;
58045858 }
58055859 items . push ( renderThreadRow ( thread , item . section ) ) ;
58065860 continue ;
0 commit comments