@@ -30,12 +30,16 @@ import type {
3030 GetOverviewBranch ,
3131 GetOverviewBranches ,
3232 GetOverviewResponse ,
33+ OverviewFilters ,
34+ OverviewRecentThreshold ,
35+ OverviewStaleThreshold ,
3336 State ,
3437} from './protocol' ;
3538import {
3639 CollapseSectionCommand ,
3740 DidChangeIntegrationsConnections ,
3841 DidChangeOrgSettings ,
42+ DidChangeOverviewFilter ,
3943 DidChangePreviewEnabled ,
4044 DidChangeRepositories ,
4145 DidChangeRepositoryWip ,
@@ -45,6 +49,8 @@ import {
4549 DismissWalkthroughSection ,
4650 GetLaunchpadSummary ,
4751 GetOverview ,
52+ GetOverviewFilterState ,
53+ SetOverviewFilter ,
4854} from './protocol' ;
4955import type { HomeWebviewShowingArgs } from './registration' ;
5056
@@ -87,6 +93,16 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
8793 } ;
8894 }
8995
96+ private _overviewBranchFilter : OverviewFilters = {
97+ recent : {
98+ threshold : 'OneWeek' ,
99+ } ,
100+ stale : {
101+ threshold : 'OneYear' ,
102+ show : false ,
103+ } ,
104+ } ;
105+
90106 onShowing (
91107 loading : boolean ,
92108 _options ?: WebviewShowOptions ,
@@ -133,6 +149,11 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
133149 ] ;
134150 }
135151
152+ private setOverviewFilter ( value : OverviewFilters ) {
153+ this . _overviewBranchFilter = value ;
154+ void this . host . notify ( DidChangeOverviewFilter , { filter : this . _overviewBranchFilter } ) ;
155+ }
156+
136157 async onMessageReceived ( e : IpcMessage ) {
137158 switch ( true ) {
138159 case CollapseSectionCommand . is ( e ) :
@@ -141,12 +162,18 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
141162 case DismissWalkthroughSection . is ( e ) :
142163 this . dismissWalkthrough ( ) ;
143164 break ;
165+ case SetOverviewFilter . is ( e ) :
166+ this . setOverviewFilter ( e . params ) ;
167+ break ;
144168 case GetLaunchpadSummary . is ( e ) :
145169 void this . host . respond ( GetLaunchpadSummary , e , await getLaunchpadSummary ( this . container ) ) ;
146170 break ;
147171 case GetOverview . is ( e ) :
148172 void this . host . respond ( GetOverview , e , await this . getBranchOverview ( ) ) ;
149173 break ;
174+ case GetOverviewFilterState . is ( e ) :
175+ void this . host . respond ( GetOverviewFilterState , e , this . _overviewBranchFilter ) ;
176+ break ;
150177 }
151178 }
152179
@@ -202,7 +229,6 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
202229 }
203230
204231 private getWalkthroughDismissed ( ) {
205- console . log ( { test : this . container . storage . get ( 'home:walkthrough:dismissed' ) } ) ;
206232 return Boolean ( this . container . storage . get ( 'home:walkthrough:dismissed' ) ) ;
207233 }
208234
@@ -276,7 +302,7 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
276302 branchesAndWorktrees ?. branches ,
277303 branchesAndWorktrees ?. worktrees ,
278304 this . container ,
279- // TODO: add filters
305+ this . _overviewBranchFilter ,
280306 ) ;
281307 if ( overviewBranches == null ) return undefined ;
282308
@@ -427,26 +453,18 @@ export class HomeWebviewProvider implements WebviewProvider<State, State, HomeWe
427453 }
428454}
429455
430- const branchOverviewDefaults = Object . freeze ( {
431- recent : { threshold : 1000 * 60 * 60 * 24 * 14 } ,
432- stale : { threshold : 1000 * 60 * 60 * 24 * 365 } ,
433- } ) ;
434-
435- interface BranchOverviewOptions {
436- recent ?: {
437- threshold : number ;
438- } ;
439- stale ?: {
440- show ?: boolean ;
441- threshold ?: number ;
442- } ;
443- }
456+ const thresholdValues : Record < OverviewStaleThreshold | OverviewRecentThreshold , number > = {
457+ OneDay : 1000 * 60 * 60 * 24 * 1 ,
458+ OneWeek : 1000 * 60 * 60 * 24 * 7 ,
459+ OneMonth : 1000 * 60 * 60 * 24 * 30 ,
460+ OneYear : 1000 * 60 * 60 * 24 * 365 ,
461+ } ;
444462
445463async function getOverviewBranches (
446464 branches : GitBranch [ ] ,
447465 worktrees : GitWorktree [ ] ,
448466 container : Container ,
449- options ?: BranchOverviewOptions ,
467+ options : OverviewFilters ,
450468) : Promise < GetOverviewBranches | undefined > {
451469 if ( branches . length === 0 ) return undefined ;
452470
@@ -469,7 +487,7 @@ async function getOverviewBranches(
469487 const contributorPromises = new Map < string , Promise < BranchContributorOverview | undefined > > ( ) ;
470488
471489 const now = Date . now ( ) ;
472- const recentThreshold = now - ( options ? .recent ? .threshold ?? branchOverviewDefaults . recent . threshold ) ;
490+ const recentThreshold = now - thresholdValues [ options . recent . threshold ] ;
473491
474492 for ( const branch of branches ) {
475493 const wt = worktreesByBranch . get ( branch . id ) ;
@@ -520,7 +538,7 @@ async function getOverviewBranches(
520538 }
521539
522540 if ( options ?. stale ?. show === true ) {
523- const staleThreshold = now - ( options ? .stale ? .threshold ?? branchOverviewDefaults . stale . threshold ) ;
541+ const staleThreshold = now - thresholdValues [ options . stale . threshold ] ;
524542 sortBranches ( branches , {
525543 missingUpstream : true ,
526544 orderBy : 'date:asc' ,
0 commit comments