@@ -21,6 +21,68 @@ import {
2121
2222type SidebarSessionGroupMenuAction = "rename-group" | "new-group" | "delete-group" ;
2323
24+ function renderSidebarMenuTrigger ( position : { x : number ; y : number } , label : string ) {
25+ return html `
26+ < button
27+ slot ="trigger "
28+ type ="button "
29+ tabindex ="-1 "
30+ aria-hidden ="true "
31+ aria-label =${ label }
32+ style ="position: fixed; left: ${ position . x } px; top: ${ position . y } px; width: 1px; height: 1px; opacity: 0; pointer-events: none;"
33+ > </ button >
34+ ` ;
35+ }
36+
37+ function renderSidebarMenuRadioItem ( params : {
38+ value : string ;
39+ checked : boolean ;
40+ label : string ;
41+ creator ?: SessionCreatorOption ;
42+ } ) {
43+ return html `
44+ < wa-dropdown-item
45+ class ="sidebar-session-sort-menu__item "
46+ value =${ params . value }
47+ role ="menuitemradio"
48+ aria-checked=${ String ( params . checked ) }
49+ ${ ref ( ( element ) => syncDropdownItemRadio ( element , params . checked ) ) }
50+ >
51+ < span slot ="details " class ="session-menu__check " aria-hidden ="true "
52+ > ${ params . checked ? icons . check : nothing } </ span
53+ >
54+ ${ params . creator ? renderSessionOwnerChip ( params . creator , "row" , "created" ) : nothing }
55+ < span class ="session-menu__text "> ${ params . label } </ span >
56+ </ wa-dropdown-item >
57+ ` ;
58+ }
59+
60+ function renderSidebarCreatorFilter (
61+ creators : readonly SessionCreatorOption [ ] ,
62+ creatorFilterId : string | null ,
63+ ) {
64+ if ( creators . length < 2 ) {
65+ return nothing ;
66+ }
67+ return html `
68+ < div class ="session-menu__separator " role ="separator "> </ div >
69+ < div class ="sidebar-session-sort-menu__title "> ${ t ( "sessionsView.people" ) } </ div >
70+ ${ renderSidebarMenuRadioItem ( {
71+ value : "creator:" ,
72+ checked : creatorFilterId === null ,
73+ label : t ( "sessionsView.allCreators" ) ,
74+ } ) }
75+ ${ creators . map ( ( creator ) =>
76+ renderSidebarMenuRadioItem ( {
77+ value : `creator:${ creator . id } ` ,
78+ checked : creatorFilterId === creator . id ,
79+ label : creator . label ?? creator . id ,
80+ creator,
81+ } ) ,
82+ ) }
83+ ` ;
84+ }
85+
2486export function renderSidebarSessionGroupMenu ( params : {
2587 menu : SidebarSessionGroupMenuState | null ;
2688 trigger : HTMLElement | null ;
@@ -58,14 +120,7 @@ export function renderSidebarSessionGroupMenu(params: {
58120 @wa-after-hide=${ ( event : Event ) =>
59121 params . onClose ( consumeDropdownKeyboardDismissal ( event ) ) }
60122 >
61- < button
62- slot ="trigger "
63- type ="button "
64- tabindex ="-1 "
65- aria-hidden ="true "
66- aria-label =${ t ( "sessionsView.groupMenu" , { group : menu . group } ) }
67- style ="position: fixed; left: ${ menu . x } px; top: ${ menu . y } px; width: 1px; height: 1px; opacity: 0; pointer-events: none;"
68- > </ button >
123+ ${ renderSidebarMenuTrigger ( menu , t ( "sessionsView.groupMenu" , { group : menu . group } ) ) }
69124 < wa-dropdown-item
70125 class ="session-menu__item "
71126 value ="rename-group "
@@ -149,72 +204,16 @@ export function renderSidebarCatalogViewMenu(params: {
149204 @wa-after-hide=${ ( event : Event ) =>
150205 params . onClose ( consumeDropdownKeyboardDismissal ( event ) ) }
151206 >
152- < button
153- slot ="trigger "
154- type ="button "
155- tabindex ="-1 "
156- aria-hidden ="true "
157- aria-label =${ t ( "chat.sidebar.catalogViewOptions" ) }
158- style ="position: fixed; left: ${ position . x } px; top: ${ position . y } px; width: 1px; height: 1px; opacity: 0; pointer-events: none;"
159- > </ button >
207+ ${ renderSidebarMenuTrigger ( position , t ( "chat.sidebar.catalogViewOptions" ) ) }
160208 < div class ="sidebar-session-sort-menu__title "> ${ t ( "sessionsView.groupBy" ) } </ div >
161- ${ groupingOptions . map (
162- ( option ) => html `
163- < wa-dropdown-item
164- class ="sidebar-session-sort-menu__item "
165- value =${ `grouping:${ option . grouping } ` }
166- role ="menuitemradio"
167- aria-checked=${ String ( params . grouping === option . grouping ) }
168- ${ ref ( ( element ) =>
169- syncDropdownItemRadio ( element , params . grouping === option . grouping ) ,
170- ) }
171- >
172- < span slot ="details " class ="session-menu__check " aria-hidden ="true "
173- > ${ params . grouping === option . grouping ? icons . check : nothing } </ span
174- >
175- < span class ="session-menu__text "> ${ option . label } </ span >
176- </ wa-dropdown-item >
177- ` ,
209+ ${ groupingOptions . map ( ( option ) =>
210+ renderSidebarMenuRadioItem ( {
211+ value : `grouping:${ option . grouping } ` ,
212+ checked : params . grouping === option . grouping ,
213+ label : option . label ,
214+ } ) ,
178215 ) }
179- ${ params . creators . length >= 2
180- ? html `
181- < div class ="session-menu__separator " role ="separator "> </ div >
182- < div class ="sidebar-session-sort-menu__title "> ${ t ( "sessionsView.people" ) } </ div >
183- < wa-dropdown-item
184- class ="sidebar-session-sort-menu__item "
185- value ="creator: "
186- role ="menuitemradio "
187- aria-checked =${ String ( params . creatorFilterId === null ) }
188- ${ ref ( ( element ) =>
189- syncDropdownItemRadio ( element , params . creatorFilterId === null ) ,
190- ) }
191- >
192- < span slot ="details " class ="session-menu__check " aria-hidden ="true "
193- > ${ params . creatorFilterId === null ? icons . check : nothing } </ span
194- >
195- < span class ="session-menu__text "> ${ t ( "sessionsView.allCreators" ) } </ span >
196- </ wa-dropdown-item >
197- ${ params . creators . map (
198- ( creator ) => html `
199- < wa-dropdown-item
200- class ="sidebar-session-sort-menu__item "
201- value =${ `creator:${ creator . id } ` }
202- role ="menuitemradio"
203- aria-checked=${ String ( params . creatorFilterId === creator . id ) }
204- ${ ref ( ( element ) =>
205- syncDropdownItemRadio ( element , params . creatorFilterId === creator . id ) ,
206- ) }
207- >
208- < span slot ="details " class ="session-menu__check " aria-hidden ="true "
209- > ${ params . creatorFilterId === creator . id ? icons . check : nothing } </ span
210- >
211- ${ renderSessionOwnerChip ( creator , "row" , "created" ) }
212- < span class ="session-menu__text "> ${ creator . label ?? creator . id } </ span >
213- </ wa-dropdown-item >
214- ` ,
215- ) }
216- `
217- : nothing }
216+ ${ renderSidebarCreatorFilter ( params . creators , params . creatorFilterId ) }
218217 < div class ="session-menu__separator " role ="separator "> </ div >
219218 < wa-dropdown-item class ="sidebar-session-sort-menu__item " value ="hide-catalog ">
220219 < span class ="session-menu__text "> ${ t ( "chat.sidebar.hideFromSidebar" ) } </ span >
@@ -281,116 +280,39 @@ export function renderSidebarSessionSortMenu(params: {
281280 @wa-after-hide=${ ( event : Event ) =>
282281 params . onClose ( consumeDropdownKeyboardDismissal ( event ) ) }
283282 >
284- < button
285- slot ="trigger "
286- type ="button "
287- tabindex ="-1 "
288- aria-hidden ="true "
289- aria-label =${ t ( "chat.sidebar.sortSessions" ) }
290- style ="position: fixed; left: ${ position . x } px; top: ${ position . y } px; width: 1px; height: 1px; opacity: 0; pointer-events: none;"
291- > </ button >
283+ ${ renderSidebarMenuTrigger ( position , t ( "chat.sidebar.sortSessions" ) ) }
292284 < div class ="sidebar-session-sort-menu__title "> ${ t ( "sessionsView.groupBy" ) } </ div >
293- ${ groupingOptions . map (
294- ( option ) => html `
295- < wa-dropdown-item
296- class ="sidebar-session-sort-menu__item "
297- value =${ `grouping:${ option . grouping } ` }
298- role ="menuitemradio"
299- aria-checked=${ String ( params . grouping === option . grouping ) }
300- ${ ref ( ( element ) =>
301- syncDropdownItemRadio ( element , params . grouping === option . grouping ) ,
302- ) }
303- >
304- < span slot ="details " class ="session-menu__check " aria-hidden ="true "
305- > ${ params . grouping === option . grouping ? icons . check : nothing } </ span
306- >
307- < span class ="session-menu__text "> ${ option . label } </ span >
308- </ wa-dropdown-item >
309- ` ,
285+ ${ groupingOptions . map ( ( option ) =>
286+ renderSidebarMenuRadioItem ( {
287+ value : `grouping:${ option . grouping } ` ,
288+ checked : params . grouping === option . grouping ,
289+ label : option . label ,
290+ } ) ,
310291 ) }
311292 < div class ="session-menu__separator " role ="separator "> </ div >
312293 < div class ="sidebar-session-sort-menu__title "> ${ t ( "chat.sidebar.sortBy" ) } </ div >
313- ${ SIDEBAR_SESSION_SORT_OPTIONS . map (
314- ( option ) => html `
315- < wa-dropdown-item
316- class ="sidebar-session-sort-menu__item "
317- value =${ `sort:${ option . mode } ` }
318- role ="menuitemradio"
319- aria-checked=${ String ( params . sortMode === option . mode ) }
320- ${ ref ( ( element ) => syncDropdownItemRadio ( element , params . sortMode === option . mode ) ) }
321- >
322- < span slot ="details " class ="session-menu__check " aria-hidden ="true "
323- > ${ params . sortMode === option . mode ? icons . check : nothing } </ span
324- >
325- < span class ="session-menu__text "> ${ t ( option . labelKey ) } </ span >
326- </ wa-dropdown-item >
327- ` ,
294+ ${ SIDEBAR_SESSION_SORT_OPTIONS . map ( ( option ) =>
295+ renderSidebarMenuRadioItem ( {
296+ value : `sort:${ option . mode } ` ,
297+ checked : params . sortMode === option . mode ,
298+ label : t ( option . labelKey ) ,
299+ } ) ,
328300 ) }
329301 < div class ="session-menu__separator " role ="separator "> </ div >
330302 < div class ="sidebar-session-sort-menu__title "> ${ t ( "sessionsView.status" ) } </ div >
331- ${ SIDEBAR_SESSION_STATUS_OPTIONS . map (
332- ( statusFilter ) => html `
333- < wa-dropdown-item
334- class ="sidebar-session-sort-menu__item "
335- value =${ `status:${ statusFilter } ` }
336- role ="menuitemradio"
337- aria-checked=${ String ( params . statusFilter === statusFilter ) }
338- ${ ref ( ( element ) =>
339- syncDropdownItemRadio ( element , params . statusFilter === statusFilter ) ,
340- ) }
341- >
342- < span slot ="details " class ="session-menu__check " aria-hidden ="true "
343- > ${ params . statusFilter === statusFilter ? icons . check : nothing } </ span
344- >
345- < span class ="session-menu__text "
346- > ${ statusFilter === "active"
347- ? t ( "common.active" )
348- : statusFilter === "archived"
349- ? t ( "sessionsView.archived" )
350- : t ( "sessionsView.all" ) } </ span
351- >
352- </ wa-dropdown-item >
353- ` ,
303+ ${ SIDEBAR_SESSION_STATUS_OPTIONS . map ( ( statusFilter ) =>
304+ renderSidebarMenuRadioItem ( {
305+ value : `status:${ statusFilter } ` ,
306+ checked : params . statusFilter === statusFilter ,
307+ label :
308+ statusFilter === "active"
309+ ? t ( "common.active" )
310+ : statusFilter === "archived"
311+ ? t ( "sessionsView.archived" )
312+ : t ( "sessionsView.all" ) ,
313+ } ) ,
354314 ) }
355- ${ params . creators . length >= 2
356- ? html `
357- < div class ="session-menu__separator " role ="separator "> </ div >
358- < div class ="sidebar-session-sort-menu__title "> ${ t ( "sessionsView.people" ) } </ div >
359- < wa-dropdown-item
360- class ="sidebar-session-sort-menu__item "
361- value ="creator: "
362- role ="menuitemradio "
363- aria-checked =${ String ( params . creatorFilterId === null ) }
364- ${ ref ( ( element ) =>
365- syncDropdownItemRadio ( element , params . creatorFilterId === null ) ,
366- ) }
367- >
368- < span slot ="details " class ="session-menu__check " aria-hidden ="true "
369- > ${ params . creatorFilterId === null ? icons . check : nothing } </ span
370- >
371- < span class ="session-menu__text "> ${ t ( "sessionsView.allCreators" ) } </ span >
372- </ wa-dropdown-item >
373- ${ params . creators . map (
374- ( creator ) => html `
375- < wa-dropdown-item
376- class ="sidebar-session-sort-menu__item "
377- value =${ `creator:${ creator . id } ` }
378- role ="menuitemradio"
379- aria-checked=${ String ( params . creatorFilterId === creator . id ) }
380- ${ ref ( ( element ) =>
381- syncDropdownItemRadio ( element , params . creatorFilterId === creator . id ) ,
382- ) }
383- >
384- < span slot ="details " class ="session-menu__check " aria-hidden ="true "
385- > ${ params . creatorFilterId === creator . id ? icons . check : nothing } </ span
386- >
387- ${ renderSessionOwnerChip ( creator , "row" , "created" ) }
388- < span class ="session-menu__text "> ${ creator . label ?? creator . id } </ span >
389- </ wa-dropdown-item >
390- ` ,
391- ) }
392- `
393- : nothing }
315+ ${ renderSidebarCreatorFilter ( params . creators , params . creatorFilterId ) }
394316 < div class ="session-menu__separator " role ="separator "> </ div >
395317 < wa-dropdown-item
396318 class ="sidebar-session-sort-menu__item "
0 commit comments