@@ -12,10 +12,6 @@ import {
1212 exists as allEventsExists ,
1313 find as allEventsFind ,
1414} from '../../lib/all-events.ts' ;
15- import {
16- DEFAULT_FILTER ,
17- filterButtonText ,
18- } from '../../lib/inline-menu-filter.ts' ;
1915import { backMainButtons } from '../../lib/inline-menu.ts' ;
2016import type { MyContext } from '../../lib/types.ts' ;
2117
@@ -31,12 +27,12 @@ export const menu = new MenuTemplate<MyContext>(async ctx => {
3127 text += '\n\n' ;
3228
3329 try {
34- const filteredEvents = await findEvents ( ctx ) ;
35-
36- const filter = ctx . session . eventfilter ?? DEFAULT_FILTER ;
37- text += filter === DEFAULT_FILTER
38- ? `Ich habe ${ total } Veranstaltungen. Nutze den Filter um die Auswahl einzugrenzen.`
39- : `Mit deinem Filter konnte ich ${ filteredEvents . length } passende Veranstaltungen finden.` ;
30+ if ( ctx . session . eventfilter === undefined ) {
31+ text += `Ich habe ${ total } Veranstaltungen. Nutze den Filter um die Auswahl einzugrenzen.` ;
32+ } else {
33+ const filteredEvents = await findEvents ( ctx ) ;
34+ text += `Mit deinem Filter konnte ich ${ filteredEvents . length } passende Veranstaltungen finden.` ;
35+ }
4036 } catch ( error ) {
4137 const errorText = error instanceof Error ? error . message : String ( error ) ;
4238 text += 'Filter Error: ' ;
@@ -47,7 +43,7 @@ export const menu = new MenuTemplate<MyContext>(async ctx => {
4743} ) ;
4844
4945async function findEvents ( ctx : MyContext ) : Promise < readonly string [ ] > {
50- const filter = ctx . session . eventfilter ?? DEFAULT_FILTER ;
46+ const filter = ctx . session . eventfilter ?? '.+' ;
5147 const ignore = Object . keys ( ctx . userconfig . mine . events ) ;
5248 return allEventsFind ( filter , ignore ) ;
5349}
@@ -66,7 +62,11 @@ const question = new StatelessQuestion<MyContext>(
6662bot . use ( question . middleware ( ) ) ;
6763
6864menu . interact ( 'filter' , {
69- text : filterButtonText ( ctx => ctx . session . eventfilter ) ,
65+ text ( ctx ) {
66+ return ctx . session . eventfilter
67+ ? `🔎 Filter: ${ ctx . session . eventfilter } `
68+ : '🔎 Filter' ;
69+ } ,
7070 async do ( ctx , path ) {
7171 await question . replyWithHTML (
7272 ctx ,
@@ -81,7 +81,7 @@ menu.interact('filter', {
8181menu . interact ( 'filter-clear' , {
8282 text : 'Filter aufheben' ,
8383 joinLastRow : true ,
84- hide : ctx => ( ctx . session . eventfilter ?? DEFAULT_FILTER ) === DEFAULT_FILTER ,
84+ hide : ctx => ctx . session . eventfilter === undefined ,
8585 do ( ctx ) {
8686 delete ctx . session . eventfilter ;
8787 return true ;
0 commit comments